diff --git a/src/test/java/org/jabref/gui/autocompleter/SuggestionProvidersTest.java b/src/test/java/org/jabref/gui/autocompleter/SuggestionProvidersTest.java new file mode 100644 index 00000000000..65a587d0290 --- /dev/null +++ b/src/test/java/org/jabref/gui/autocompleter/SuggestionProvidersTest.java @@ -0,0 +1,48 @@ +package org.jabref.gui.autocompleter; + +import org.jabref.logic.journals.JournalAbbreviationRepository; +import org.jabref.model.database.BibDatabase; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.Field; +import org.jabref.model.entry.field.FieldFactory; +import org.jabref.model.entry.field.SpecialField; +import org.jabref.model.entry.field.StandardField; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; + +class SuggestionProvidersTest { + + @Test + void getForFieldTest() { + BibDatabase database = new BibDatabase(); + JournalAbbreviationRepository abbreviationRepository = mock(JournalAbbreviationRepository.class); + BibEntry entry = new BibEntry(); + Field personEntryField = StandardField.AUTHOR; + Field singleEntryField = StandardField.XREF; + Field multipleEntryField = StandardField.XDATA; + Field journalEntryField = StandardField.JOURNAL; + Field publisherEntryField = StandardField.PUBLISHER; + Field specialEntryField = SpecialField.PRINTED; + AutoCompletePreferences autoCompletePreferences = new AutoCompletePreferences(true, AutoCompleteFirstNameMode.BOTH, AutoCompletePreferences.NameFormat.BOTH, FieldFactory.parseFieldList(personEntryField.getName() + ";" + singleEntryField.getName() + ";" + multipleEntryField.getName() + ";" + journalEntryField.getName() + ";" + publisherEntryField.getName() + ";" + specialEntryField.getName()), null); + SuggestionProviders sp = new SuggestionProviders(database, abbreviationRepository, autoCompletePreferences); + SuggestionProviders empty = new SuggestionProviders(); + + entry.setField(personEntryField, "Goethe"); + entry.setField(singleEntryField, "Single"); + entry.setField(multipleEntryField, "Multiple"); + entry.setField(journalEntryField, "Journal"); + entry.setField(publisherEntryField, "Publisher"); + entry.setField(specialEntryField, "2000"); + + assertEquals(org.jabref.gui.autocompleter.EmptySuggestionProvider.class, empty.getForField(personEntryField).getClass()); + assertEquals(org.jabref.gui.autocompleter.PersonNameSuggestionProvider.class, sp.getForField(personEntryField).getClass()); + assertEquals(org.jabref.gui.autocompleter.BibEntrySuggestionProvider.class, sp.getForField(singleEntryField).getClass()); + assertEquals(org.jabref.gui.autocompleter.BibEntrySuggestionProvider.class, sp.getForField(multipleEntryField).getClass()); + assertEquals(org.jabref.gui.autocompleter.JournalsSuggestionProvider.class, sp.getForField(journalEntryField).getClass()); + assertEquals(org.jabref.gui.autocompleter.JournalsSuggestionProvider.class, sp.getForField(publisherEntryField).getClass()); + assertEquals(org.jabref.gui.autocompleter.WordSuggestionProvider.class, sp.getForField(specialEntryField).getClass()); + } +} diff --git a/src/test/java/org/jabref/logic/citationkeypattern/CitationKeyGeneratorTest.java b/src/test/java/org/jabref/logic/citationkeypattern/CitationKeyGeneratorTest.java index 82498577af2..b7efe6a1e8e 100644 --- a/src/test/java/org/jabref/logic/citationkeypattern/CitationKeyGeneratorTest.java +++ b/src/test/java/org/jabref/logic/citationkeypattern/CitationKeyGeneratorTest.java @@ -739,7 +739,6 @@ void testPagePrefixNull() { @Test void testLastPage() { - assertEquals("27", CitationKeyGenerator.lastPage("7--27")); assertEquals("27", CitationKeyGenerator.lastPage("--27")); assertEquals("", CitationKeyGenerator.lastPage("")); @@ -747,6 +746,8 @@ void testLastPage() { assertEquals("97", CitationKeyGenerator.lastPage("7,41,73--97")); assertEquals("97", CitationKeyGenerator.lastPage("7,41,97--73")); assertEquals("43", CitationKeyGenerator.lastPage("43+")); + assertEquals("0", CitationKeyGenerator.lastPage("00--0")); + assertEquals("1", CitationKeyGenerator.lastPage("1--1")); } @SuppressWarnings("ConstantConditions") diff --git a/src/test/java/org/jabref/logic/formatter/casechanger/UpperCaseFormatterTest.java b/src/test/java/org/jabref/logic/formatter/casechanger/UpperCaseFormatterTest.java index 2c669a6a5d2..791a08a5c49 100644 --- a/src/test/java/org/jabref/logic/formatter/casechanger/UpperCaseFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/casechanger/UpperCaseFormatterTest.java @@ -1,7 +1,10 @@ package org.jabref.logic.formatter.casechanger; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import java.util.stream.Stream; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,24 +13,23 @@ */ public class UpperCaseFormatterTest { - private UpperCaseFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new UpperCaseFormatter(); - } + private UpperCaseFormatter formatter = new UpperCaseFormatter(); - @Test - public void test() { - assertEquals("LOWER", formatter.format("LOWER")); - assertEquals("UPPER", formatter.format("upper")); - assertEquals("UPPER", formatter.format("UPPER")); - assertEquals("UPPER {lower}", formatter.format("upper {lower}")); - assertEquals("UPPER {l}OWER", formatter.format("upper {l}ower")); + @ParameterizedTest + @MethodSource("upperCaseTests") + public void upperCasetest(String expectedFormat, String inputFormat) { + assertEquals(expectedFormat, formatter.format(inputFormat)); } - @Test - public void formatExample() { - assertEquals("KDE {Amarok}", formatter.format(formatter.getExampleInput())); + private static Stream upperCaseTests() { + return Stream.of( + Arguments.of("LOWER", "LOWER"), + Arguments.of("UPPER", "upper"), + Arguments.of("UPPER", "UPPER"), + Arguments.of("UPPER {lower}", "upper {lower}"), + Arguments.of("UPPER {l}OWER", "upper {l}ower"), + Arguments.of("1", "1"), + Arguments.of("!", "!") + ); } } diff --git a/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java b/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java index c2ee7af10b3..35b92e744d7 100644 --- a/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java @@ -9,12 +9,22 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class HTMLCharacterCheckerTest { private final HTMLCharacterChecker checker = new HTMLCharacterChecker(); private final BibEntry entry = new BibEntry(); + @Test + void fieldNullValueCheck() { + Exception exception = assertThrows( + NullPointerException.class, + () -> entry.setField(StandardField.AUTHOR, null), + "field value must not be null" + ); + } + @Test void titleAcceptsNonHTMLEncodedCharacters() { entry.setField(StandardField.TITLE, "Not a single {HTML} character"); diff --git a/src/test/java/org/jabref/model/entry/EntryLinkListTest.java b/src/test/java/org/jabref/model/entry/EntryLinkListTest.java index 03b45ef2ae0..6cc596f8096 100644 --- a/src/test/java/org/jabref/model/entry/EntryLinkListTest.java +++ b/src/test/java/org/jabref/model/entry/EntryLinkListTest.java @@ -10,6 +10,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; public class EntryLinkListTest { @@ -21,6 +22,7 @@ public class EntryLinkListTest { private ParsedEntryLink link; private BibEntry source; private BibEntry target; + private BibEntry entry; @BeforeEach public void before() { @@ -59,6 +61,13 @@ public void givenFieldValueAndDatabaseWhenParsingThenExpectLink() { assertEquals(expected, link); } + @Test + public void givenBibEntryWhenParsingThenExpectLink() { + entry = create("entry"); + ParsedEntryLink expected = new ParsedEntryLink(entry); + assertFalse(expected.getLinkedEntry().isEmpty()); + } + @Test public void givenNullFieldValueAndDatabaseWhenParsingThenExpectLinksIsEmpty() { links = EntryLinkList.parse(null, database); diff --git a/src/test/java/org/jabref/model/util/FileHelperTest.java b/src/test/java/org/jabref/model/util/FileHelperTest.java index 27096d3b4ff..6d047662b12 100644 --- a/src/test/java/org/jabref/model/util/FileHelperTest.java +++ b/src/test/java/org/jabref/model/util/FileHelperTest.java @@ -1,5 +1,6 @@ package org.jabref.model.util; +import java.nio.file.Path; import java.util.Optional; import org.junit.jupiter.api.Test; @@ -18,4 +19,10 @@ public void fileExtensionFromUrl() { final String filePath = "https://link.springer.com/content/pdf/10.1007%2Fs40955-018-0121-9.pdf"; assertEquals(Optional.of("pdf"), FileHelper.getFileExtension(filePath)); } + + @Test + public void testFileNameEmpty() { + Path path = Path.of("/"); + assertEquals(Optional.of(path), FileHelper.find("", path)); + } }