Skip to content

Commit eade1cf

Browse files
committed
fix merge conflicts and external link creator tests
1 parent 2d65f10 commit eade1cf

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

jablib/src/main/java/org/jabref/logic/util/ExternalLinkCreator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public Optional<String> getShortScienceSearchURL(BibEntry entry) {
3737
if (!baseUrl.contains("{title}")) {
3838
try {
3939
URIBuilder uriBuilder = new URIBuilder(DEFAULT_SHORTSCIENCE_SEARCH_URL);
40-
uriBuilder.addParameter("q", title);
40+
uriBuilder.addParameter("q", title.trim());
4141
author.ifPresent(a -> uriBuilder.addParameter("author", a));
4242
return uriBuilder.toString();
4343
} catch (URISyntaxException ex) {
@@ -68,7 +68,7 @@ public Optional<String> getGoogleScholarSearchURL(BibEntry entry) {
6868
if (!baseUrl.contains("{title}")) {
6969
try {
7070
URIBuilder uriBuilder = new URIBuilder(DEFAULT_GOOGLE_SCHOLAR_SEARCH_URL);
71-
uriBuilder.addParameter("q", title);
71+
uriBuilder.addParameter("q", title.trim());
7272
author.ifPresent(a -> uriBuilder.addParameter("author", a));
7373
return uriBuilder.toString();
7474
} catch (URISyntaxException ex) {

jablib/src/test/java/org/jabref/logic/util/ExternalLinkCreatorTest.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public StubImporterPreferences() {
3535
true, // persistCustomKeys
3636
List.of(), // catalogs
3737
null, // defaultPlainCitationParser
38+
5, // citationsRelationsStoreTTL
3839
Collections.emptyMap() // searchEngineUrlTemplates
3940
);
4041
}
@@ -62,9 +63,12 @@ static Stream<Arguments> specialCharactersProvider() {
6263
@ParameterizedTest
6364
@MethodSource("specialCharactersProvider")
6465
void getShortScienceSearchURLEncodesSpecialCharacters(String title) {
66+
ImporterPreferences stubPreferences = new StubImporterPreferences();
67+
ExternalLinkCreator linkCreator = new ExternalLinkCreator(stubPreferences);
68+
6569
BibEntry entry = new BibEntry();
6670
entry.setField(StandardField.TITLE, title);
67-
Optional<String> url = getShortScienceSearchURL(entry);
71+
Optional<String> url = linkCreator.getShortScienceSearchURL(entry);
6872
assertTrue(url.isPresent());
6973
assertTrue(urlIsValid(url.get()));
7074
}
@@ -77,8 +81,11 @@ void getShortScienceSearchURLEncodesSpecialCharacters(String title) {
7781
"'JabRef bibliography management', 'https://www.shortscience.org/internalsearch?q=JabRef%20bibliography%20management'"
7882
})
7983
void getShortScienceSearchURLEncodesCharacters(String title, String expectedUrl) {
84+
ImporterPreferences stubPreferences = new StubImporterPreferences();
85+
ExternalLinkCreator linkCreator = new ExternalLinkCreator(stubPreferences);
86+
8087
BibEntry entry = new BibEntry().withField(StandardField.TITLE, title);
81-
Optional<String> url = getShortScienceSearchURL(entry);
88+
Optional<String> url = linkCreator.getShortScienceSearchURL(entry);
8289
assertEquals(Optional.of(expectedUrl), url);
8390
}
8491

@@ -91,15 +98,17 @@ void getShortScienceSearchURLReturnsEmptyOnMissingTitle() {
9198
assertEquals(Optional.empty(), linkCreator.getShortScienceSearchURL(entry));
9299
}
93100

94-
@Test
95-
void getShortScienceSearchURLLinksToSearchResults() {
101+
@ParameterizedTest
102+
@CsvSource({
103+
"JabRef bibliography management, https://www.shortscience.org/internalsearch?q=JabRef%20bibliography%20management",
104+
"Machine learning, https://www.shortscience.org/internalsearch?q=Machine%20learning",
105+
})
106+
void getShortScienceSearchURLLinksToSearchResults(String title, String expectedUrl) {
96107
ImporterPreferences stubPreferences = new StubImporterPreferences();
97108
ExternalLinkCreator linkCreator = new ExternalLinkCreator(stubPreferences);
98109

99-
// Take an arbitrary article name
100-
BibEntry entry = new BibEntry().withField(StandardField.TITLE, "JabRef bibliography management");
110+
BibEntry entry = new BibEntry().withField(StandardField.TITLE, title);
101111
Optional<String> url = linkCreator.getShortScienceSearchURL(entry);
102-
// Expected behaviour is to link to the search results page, /internalsearch
103-
assertEquals(Optional.of("https://www.shortscience.org/internalsearch?q=JabRef%20bibliography%20management"), url);
112+
assertEquals(Optional.of(expectedUrl), url);
104113
}
105114
}

0 commit comments

Comments
 (0)