Skip to content

Commit e77d5e0

Browse files
committed
use builder of BibEntry with citation key
1 parent cf113a2 commit e77d5e0

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

jabsrv/src/test/java/org/jabref/http/server/cayw/CAYWResourceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected Application configure() {
2727
resourceConfig.register(new AbstractBinder() {
2828
@Override protected void configure() {
2929
SrvStateManager mockSrv = Mockito.mock(SrvStateManager.class);
30-
BibEntry bibEntry = new BibEntry("Author2023test");
30+
BibEntry bibEntry = new BibEntry().withCitationKey("Author2023test");
3131
Mockito.when(mockSrv.getSelectedEntries()).thenReturn(FXCollections.observableArrayList(bibEntry));
3232
bind(mockSrv).to(SrvStateManager.class);
3333
}

jabsrv/src/test/java/org/jabref/http/server/cayw/format/CAYWFormattersTest.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.List;
44
import java.util.Optional;
5+
import java.util.stream.Collectors;
6+
import java.util.stream.Stream;
57

68
import org.jabref.http.server.cayw.CAYWQueryParams;
79
import org.jabref.http.server.cayw.gui.CAYWEntry;
@@ -15,13 +17,16 @@
1517

1618
class CAYWFormattersTest {
1719

18-
private static CAYWEntry caywEntry(String key) {
19-
BibEntry bibEntry = new BibEntry();
20-
bibEntry.setCitationKey(key);
21-
return new CAYWEntry(bibEntry, "", "", "");
20+
private List<CAYWEntry> caywEntries(String... keys) {
21+
if (keys == null) {
22+
return List.of();
23+
}
24+
return Stream.of(keys)
25+
.map(key -> new CAYWEntry(new BibEntry().withCitationKey(key), key, key, ""))
26+
.collect(Collectors.toList());
2227
}
2328

24-
private static CAYWQueryParams queryParams(String command) {
29+
private CAYWQueryParams queryParams(String command) {
2530
CAYWQueryParams mock = Mockito.mock(CAYWQueryParams.class);
2631
Mockito.when(mock.getCommand()).thenReturn(Optional.ofNullable(command));
2732
return mock;
@@ -30,15 +35,15 @@ private static CAYWQueryParams queryParams(String command) {
3035
@Test
3136
void biblatex_noCommand() {
3237
BibLatexFormatter formatter = new BibLatexFormatter("autocite");
33-
String actual = formatter.format(queryParams(null), List.of(caywEntry("key1"), caywEntry("key2")));
38+
String actual = formatter.format(queryParams(null), caywEntries("key1", "key2"));
3439
assertEquals("\\autocite{key1,key2}", actual);
3540
assertEquals(MediaType.TEXT_PLAIN_TYPE, formatter.getMediaType());
3641
}
3742

3843
@Test
3944
void biblatex_explicitCommand() {
4045
BibLatexFormatter formatter = new BibLatexFormatter("autocite");
41-
String actual = formatter.format(queryParams("cite"), List.of(caywEntry("key1")));
46+
String actual = formatter.format(queryParams("cite"), caywEntries("key1"));
4247
assertEquals("\\cite{key1}", actual);
4348
assertEquals(MediaType.TEXT_PLAIN_TYPE, formatter.getMediaType());
4449
}
@@ -47,26 +52,23 @@ void biblatex_explicitCommand() {
4752
void biblatex_missingKey() {
4853
// If you decide to DROP empties, change formatter + this expectation.
4954
BibLatexFormatter formatter = new BibLatexFormatter("autocite");
50-
CAYWEntry entry1 = caywEntry("key1");
51-
CAYWEntry entry2 = caywEntry("");
52-
CAYWEntry entry3 = caywEntry("key3");
53-
String actual = formatter.format(queryParams(null), List.of(entry1, entry2, entry3));
55+
String actual = formatter.format(queryParams(null), caywEntries("key1", "", "key3"));
5456
assertEquals("\\autocite{key1,key3}", actual); // current implementation
5557
assertEquals(MediaType.TEXT_PLAIN_TYPE, formatter.getMediaType());
5658
}
5759

5860
@Test
5961
void natbib_citep() {
6062
NatbibFormatter formatter = new NatbibFormatter("citep");
61-
String actual = formatter.format(queryParams(null), List.of(caywEntry("key1"), caywEntry("key2")));
63+
String actual = formatter.format(queryParams(null), caywEntries("key1", "key2"));
6264
assertEquals("\\citep{key1,key2}", actual);
6365
assertEquals(MediaType.TEXT_PLAIN_TYPE, formatter.getMediaType());
6466
}
6567

6668
@Test
6769
void mmd() {
6870
MMDFormatter formatter = new MMDFormatter();
69-
String actual = formatter.format(queryParams(null), List.of(caywEntry("key1"), caywEntry("key2")));
71+
String actual = formatter.format(queryParams(null), caywEntries("key1", "key2"));
7072
// Whatever your MMD formatter currently emits; adjust expected accordingly.
7173
assertEquals("[#key1][][#key2][]", actual);
7274
assertEquals(MediaType.TEXT_PLAIN_TYPE, formatter.getMediaType());
@@ -75,14 +77,14 @@ void mmd() {
7577
@Test
7678
void pandoc() {
7779
PandocFormatter formatter = new PandocFormatter();
78-
String actual = formatter.format(queryParams(null), List.of(caywEntry("key1"), caywEntry("key2")));
80+
String actual = formatter.format(queryParams(null), caywEntries("key1", "key2"));
7981
assertEquals("[@key1; @key2]", actual);
8082
}
8183

8284
@Test
8385
void typst() {
8486
TypstFormatter formatter = new TypstFormatter();
85-
String actual = formatter.format(queryParams(null), List.of(caywEntry("key1"), caywEntry("key2")));
87+
String actual = formatter.format(queryParams(null), caywEntries("key1", "key2"));
8688
assertEquals("@key1 @key2", actual);
8789
}
8890
}

0 commit comments

Comments
 (0)