Skip to content

Commit 186712c

Browse files
committed
feat: fix tests
1 parent 4ef9146 commit 186712c

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

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

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
11
package org.jabref.logic.util;
22

33
import java.net.MalformedURLException;
4+
import java.util.Collections;
45
import java.util.Optional;
56

7+
import org.jabref.logic.importer.ImporterPreferences;
68
import org.jabref.model.entry.BibEntry;
79
import org.jabref.model.entry.field.StandardField;
810

911
import org.junit.jupiter.api.Test;
1012

11-
import static org.jabref.logic.util.ExternalLinkCreator.getShortScienceSearchURL;
1213
import static org.junit.jupiter.api.Assertions.assertEquals;
1314
import static org.junit.jupiter.api.Assertions.assertTrue;
1415

1516
class ExternalLinkCreatorTest {
1617

18+
// Create stub for ImporterPreferences to test
19+
private static class StubImporterPreferences extends ImporterPreferences {
20+
public StubImporterPreferences() {
21+
super(
22+
true, // importerEnabled
23+
true, // generateNewKeyOnImport
24+
null, // importWorkingDirectory
25+
true, // warnAboutDuplicatesOnImport
26+
Collections.emptySet(), // customImporters
27+
Collections.emptySet(), // apiKeys
28+
Collections.emptyMap(), // defaultApiKeys
29+
true, // persistCustomKeys
30+
Collections.emptyList(), // catalogs
31+
null, // defaultPlainCitationParser
32+
Collections.emptyMap() // searchEngineUrlTemplates
33+
);
34+
}
35+
}
36+
1737
/**
1838
* Validates URL conformance to RFC2396. Does not perform complex checks such as opening connections.
1939
*/
@@ -29,25 +49,34 @@ private boolean urlIsValid(String url) {
2949

3050
@Test
3151
void getShortScienceSearchURLEncodesSpecialCharacters() {
52+
ImporterPreferences stubPreferences = new StubImporterPreferences();
53+
ExternalLinkCreator linkCreator = new ExternalLinkCreator(stubPreferences);
54+
3255
BibEntry entry = new BibEntry();
3356
String rfc3986ReservedCharacters = "!*'();:@&=+$,/?#[]";
3457
entry.setField(StandardField.TITLE, rfc3986ReservedCharacters);
35-
Optional<String> url = getShortScienceSearchURL(entry);
58+
Optional<String> url = linkCreator.getShortScienceSearchURL(entry);
3659
assertTrue(url.isPresent());
3760
assertTrue(urlIsValid(url.get()));
3861
}
3962

4063
@Test
4164
void getShortScienceSearchURLReturnsEmptyOnMissingTitle() {
65+
ImporterPreferences stubPreferences = new StubImporterPreferences();
66+
ExternalLinkCreator linkCreator = new ExternalLinkCreator(stubPreferences);
67+
4268
BibEntry entry = new BibEntry();
43-
assertEquals(Optional.empty(), getShortScienceSearchURL(entry));
69+
assertEquals(Optional.empty(), linkCreator.getShortScienceSearchURL(entry));
4470
}
4571

4672
@Test
4773
void getShortScienceSearchURLLinksToSearchResults() {
74+
ImporterPreferences stubPreferences = new StubImporterPreferences();
75+
ExternalLinkCreator linkCreator = new ExternalLinkCreator(stubPreferences);
76+
4877
// Take an arbitrary article name
4978
BibEntry entry = new BibEntry().withField(StandardField.TITLE, "JabRef bibliography management");
50-
Optional<String> url = getShortScienceSearchURL(entry);
79+
Optional<String> url = linkCreator.getShortScienceSearchURL(entry);
5180
// Expected behaviour is to link to the search results page, /internalsearch
5281
assertEquals(Optional.of("https://www.shortscience.org/internalsearch?q=JabRef%20bibliography%20management"), url);
5382
}

0 commit comments

Comments
 (0)