From 3084c57147f1b31f02e6bf2045551bcef1aad3a5 Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 15 Mar 2021 15:12:59 +0100 Subject: [PATCH 01/29] Branch Coverage Tests FieldChange.java 18% -> 94% Abbreviation.java 63% -> 88% SuggestionProviders.java 0% -> 100% --- .../SuggestionProvidersTest.java | 52 ++++++++++++++++ .../logic/journals/AbbreviationTest.java | 15 ++++- .../org/jabref/model/FieldChangeTest.java | 61 +++++++++++++++++++ 3 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/jabref/gui/autocompleter/SuggestionProvidersTest.java create mode 100644 src/test/java/org/jabref/model/FieldChangeTest.java 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..198cb35f829 --- /dev/null +++ b/src/test/java/org/jabref/gui/autocompleter/SuggestionProvidersTest.java @@ -0,0 +1,52 @@ +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 java.util.ArrayList; +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.*; +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"); + database.insertEntry(entry); + + assertSame("org.jabref.gui.autocompleter.EmptrySuggestionProvider", empty.getForField(personEntryField).getClass().getName()); + assertSame("org.jabref.gui.autocompleter.PersonNameSuggestionProvider", sp.getForField(personEntryField).getClass().getName()); + assertSame("org.jabref.gui.autocompleter.BibEntrySuggestionProvider", sp.getForField(singleEntryField).getClass().getName()); + assertSame("org.jabref.gui.autocompleter.BibEntrySuggestionProvider", sp.getForField(multipleEntryField).getClass().getName()); + assertSame("org.jabref.gui.autocompleter.JournalsSuggestionProvider", sp.getForField(journalEntryField).getClass().getName()); + assertSame("org.jabref.gui.autocompleter.JournalsSuggestionProvider", sp.getForField(publisherEntryField).getClass().getName()); + assertSame("org.jabref.gui.autocompleter.WordSuggestionProvider", sp.getForField(specialEntryField).getClass().getName()); + } +} diff --git a/src/test/java/org/jabref/logic/journals/AbbreviationTest.java b/src/test/java/org/jabref/logic/journals/AbbreviationTest.java index 3931d712c47..8f502abef9c 100644 --- a/src/test/java/org/jabref/logic/journals/AbbreviationTest.java +++ b/src/test/java/org/jabref/logic/journals/AbbreviationTest.java @@ -2,7 +2,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; class AbbreviationTest { @@ -101,4 +101,17 @@ void testDefaultAndShortestUniqueAbbreviationsAreSame() { Abbreviation abbreviation = new Abbreviation("Long Name", "L N"); assertEquals(abbreviation.getAbbreviation(), abbreviation.getShortestUniqueAbbreviation()); } + + @Test + void testToString() { + Abbreviation abbreviation = new Abbreviation("Long Name", "L N", "LN"); + assertEquals(abbreviation.toString(), "Abbreviation{name=Long Name, abbreviation=L N, medlineAbbreviation=L N, shortestUniqueAbbreviation=LN}"); + } + + @Test + void testEquals() { + Abbreviation abbreviation = new Abbreviation("Long Name", "L N", "LN"); + assertTrue(abbreviation.equals(abbreviation)); + assertFalse(abbreviation.equals("String")); + } } diff --git a/src/test/java/org/jabref/model/FieldChangeTest.java b/src/test/java/org/jabref/model/FieldChangeTest.java new file mode 100644 index 00000000000..746a98b2bb9 --- /dev/null +++ b/src/test/java/org/jabref/model/FieldChangeTest.java @@ -0,0 +1,61 @@ +package org.jabref.model; + +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.Field; +import org.jabref.model.entry.field.StandardField; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class FieldChangeTest { + + private FieldChange Fieldchange; + + @Test + void testHashCode() { + FieldChange fcNull = new FieldChange(null, null, null, null); + assertEquals(923521,fcNull.hashCode()); + } + + @Test + void testEquals() { + BibEntry entry = new BibEntry(); + BibEntry entryOther = new BibEntry(); + final Field field = StandardField.DOI; + final Field fieldOther = StandardField.DOI; + entry.setField(StandardField.DOI, "foo"); + final String oldValue = "foo"; + final String newValue = "bar"; + final String oldValueOther = "fooX"; + final String newValueOther = "barX"; + + FieldChange fc = new FieldChange(entry, field, oldValue, newValue); + FieldChange fcOther = new FieldChange(entryOther, fieldOther, oldValueOther, newValueOther); + FieldChange fcBlankAll = new FieldChange(null, null, null, null); + FieldChange fcBlankField = new FieldChange(entry, null, oldValue, newValue); + FieldChange fcBlankOldValue = new FieldChange(entry, field, null, newValue); + FieldChange fcBlankNewValue = new FieldChange(entry, field, oldValue, null); + + assertFalse(fc.equals("foo")); + assertTrue(fc.equals(fc)); + assertFalse(fcBlankAll.equals(fc)); + assertFalse(fc.equals(fcOther)); + assertFalse(fcBlankField.equals(fc)); + assertFalse(fcBlankOldValue.equals(fc)); + assertFalse(fcBlankNewValue.equals(fc)); + assertTrue(fcBlankAll.equals(fcBlankAll)); + } + + @Test + void testToString() { + BibEntry entry = new BibEntry(); + Field field = StandardField.DOI; + entry.setCitationKey("CitationKey"); + final String oldValue = "Old"; + final String newValue = "New"; + + FieldChange fc = new FieldChange(entry, field, oldValue, newValue); + assertEquals("FieldChange [entry=CitationKey, field=DOI, oldValue=Old, newValue=New]", fc.toString()); + } +} From 0004bc540c5c2337629c017dbcbcd0d9e77e868d Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 15 Mar 2021 15:13:42 +0100 Subject: [PATCH 02/29] Boundary Tests FileHelper.java -> Boundary testing of an empty file CitationKeyGenerator.java -> Boundary testing of testlagepage parser for 0-00 & 1-1 HTMLCharacterChecker.java -> Null Value Boundary test --- .../citationkeypattern/CitationKeyGeneratorTest.java | 3 +++ .../logic/integrity/HTMLCharacterCheckerTest.java | 11 +++++++++++ .../java/org/jabref/model/util/FileHelperTest.java | 9 ++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/jabref/logic/citationkeypattern/CitationKeyGeneratorTest.java b/src/test/java/org/jabref/logic/citationkeypattern/CitationKeyGeneratorTest.java index 82498577af2..1ae6fde62de 100644 --- a/src/test/java/org/jabref/logic/citationkeypattern/CitationKeyGeneratorTest.java +++ b/src/test/java/org/jabref/logic/citationkeypattern/CitationKeyGeneratorTest.java @@ -747,6 +747,9 @@ 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/integrity/HTMLCharacterCheckerTest.java b/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java index c2ee7af10b3..db827d75ea0 100644 --- a/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java @@ -7,14 +7,25 @@ import org.jabref.model.entry.field.StandardField; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; 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/util/FileHelperTest.java b/src/test/java/org/jabref/model/util/FileHelperTest.java index 27096d3b4ff..5352ff0c5fc 100644 --- a/src/test/java/org/jabref/model/util/FileHelperTest.java +++ b/src/test/java/org/jabref/model/util/FileHelperTest.java @@ -1,10 +1,11 @@ package org.jabref.model.util; +import java.nio.file.Path; import java.util.Optional; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; class FileHelperTest { @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)); + } } From 4e4f8fe16fe21abfb9c2debd946839caf7f0155a Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 15 Mar 2021 15:13:56 +0100 Subject: [PATCH 03/29] Partition Tests ParsedEntryLink.java -> Partition testing of ParsingEntryLink UpperCaseFormatter.java -> Partition testing for special characters CitationStyleCacheTest.java -> Partition testing of cache storage --- .../citationstyle/CitationStyleCacheTest.java | 39 +++++++++++++++++++ .../casechanger/UpperCaseFormatterTest.java | 3 ++ .../jabref/model/entry/EntryLinkListTest.java | 10 ++++- 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/test/java/org/jabref/logic/citationstyle/CitationStyleCacheTest.java diff --git a/src/test/java/org/jabref/logic/citationstyle/CitationStyleCacheTest.java b/src/test/java/org/jabref/logic/citationstyle/CitationStyleCacheTest.java new file mode 100644 index 00000000000..70e7c26cc56 --- /dev/null +++ b/src/test/java/org/jabref/logic/citationstyle/CitationStyleCacheTest.java @@ -0,0 +1,39 @@ +package org.jabref.logic.citationstyle; + +import org.jabref.model.database.BibDatabase; +import org.jabref.model.database.BibDatabaseContext; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.texparser.Citation; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +class CitationStyleCacheTest { + + private BibEntry bibEntry; + private List entries; + private BibDatabase database; + private BibDatabaseContext databaseContext; + private CitationStyleCache csCache; + + @BeforeAll + static void beforeAll() { + } + + @Test + void getCitationForTest() { + BibEntry bibEntry = new BibEntry(); + bibEntry.setCitationKey("test"); + List entries = new ArrayList<>(); + entries.add(0,bibEntry); + BibDatabase database = new BibDatabase(entries); + BibDatabaseContext databaseContext = new BibDatabaseContext(database); + CitationStyleCache csCache = new CitationStyleCache(databaseContext); + + assertNotNull(csCache.getCitationFor(bibEntry)); + } +} 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..5f2a74947e4 100644 --- a/src/test/java/org/jabref/logic/formatter/casechanger/UpperCaseFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/casechanger/UpperCaseFormatterTest.java @@ -24,6 +24,9 @@ public void test() { assertEquals("UPPER", formatter.format("UPPER")); assertEquals("UPPER {lower}", formatter.format("upper {lower}")); assertEquals("UPPER {l}OWER", formatter.format("upper {l}ower")); + assertEquals("1", formatter.format("1")); + assertEquals("!", formatter.format("!")); + } @Test diff --git a/src/test/java/org/jabref/model/entry/EntryLinkListTest.java b/src/test/java/org/jabref/model/entry/EntryLinkListTest.java index 03b45ef2ae0..1ca8fd6dc4b 100644 --- a/src/test/java/org/jabref/model/entry/EntryLinkListTest.java +++ b/src/test/java/org/jabref/model/entry/EntryLinkListTest.java @@ -9,8 +9,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; public class EntryLinkListTest { @@ -21,6 +20,7 @@ public class EntryLinkListTest { private ParsedEntryLink link; private BibEntry source; private BibEntry target; + private BibEntry entry; @BeforeEach public void before() { @@ -29,6 +29,7 @@ public void before() { link = links.get(0); source = create("source"); target = create("target"); + entry = create("entry"); } private BibEntry create(String citeKey) { @@ -58,6 +59,11 @@ public void givenFieldValueAndDatabaseWhenParsingThenExpectLink() { ParsedEntryLink expected = new ParsedEntryLink(KEY, database); assertEquals(expected, link); } + @Test + public void givenBibEntryWhenParsingThenExpectLink() { + ParsedEntryLink expected = new ParsedEntryLink(entry); + assertFalse(expected.getLinkedEntry().isEmpty()); + } @Test public void givenNullFieldValueAndDatabaseWhenParsingThenExpectLinksIsEmpty() { From 8f68850cbdb049def52b796dc73b7df47c23a551 Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 15 Mar 2021 15:15:42 +0100 Subject: [PATCH 04/29] Update SuggestionProvidersTest.java SPTest typo fix --- .../org/jabref/gui/autocompleter/SuggestionProvidersTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/jabref/gui/autocompleter/SuggestionProvidersTest.java b/src/test/java/org/jabref/gui/autocompleter/SuggestionProvidersTest.java index 198cb35f829..1310a1da248 100644 --- a/src/test/java/org/jabref/gui/autocompleter/SuggestionProvidersTest.java +++ b/src/test/java/org/jabref/gui/autocompleter/SuggestionProvidersTest.java @@ -41,7 +41,7 @@ void getForFieldTest() { entry.setField(specialEntryField, "2000"); database.insertEntry(entry); - assertSame("org.jabref.gui.autocompleter.EmptrySuggestionProvider", empty.getForField(personEntryField).getClass().getName()); + assertSame("org.jabref.gui.autocompleter.EmptySuggestionProvider", empty.getForField(personEntryField).getClass().getName()); assertSame("org.jabref.gui.autocompleter.PersonNameSuggestionProvider", sp.getForField(personEntryField).getClass().getName()); assertSame("org.jabref.gui.autocompleter.BibEntrySuggestionProvider", sp.getForField(singleEntryField).getClass().getName()); assertSame("org.jabref.gui.autocompleter.BibEntrySuggestionProvider", sp.getForField(multipleEntryField).getClass().getName()); From 4ea42edc2acdd8e3ddd09924a642646b4eadb428 Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Wed, 17 Mar 2021 11:59:02 +0100 Subject: [PATCH 05/29] CodeStyle Fixes Checkstyle passed --- .../autocompleter/SuggestionProvidersTest.java | 11 ++++------- .../citationstyle/CitationStyleCacheTest.java | 17 ++++++----------- .../integrity/HTMLCharacterCheckerTest.java | 1 - .../jabref/logic/journals/AbbreviationTest.java | 4 +++- .../java/org/jabref/model/FieldChangeTest.java | 8 +++++--- .../jabref/model/entry/EntryLinkListTest.java | 5 ++++- .../org/jabref/model/util/FileHelperTest.java | 2 +- 7 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/test/java/org/jabref/gui/autocompleter/SuggestionProvidersTest.java b/src/test/java/org/jabref/gui/autocompleter/SuggestionProvidersTest.java index 1310a1da248..54a4f470ff4 100644 --- a/src/test/java/org/jabref/gui/autocompleter/SuggestionProvidersTest.java +++ b/src/test/java/org/jabref/gui/autocompleter/SuggestionProvidersTest.java @@ -7,12 +7,10 @@ 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 java.util.ArrayList; -import java.util.Set; +import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.mockito.Mockito.mock; class SuggestionProvidersTest { @@ -28,9 +26,8 @@ void getForFieldTest() { 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); + 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"); diff --git a/src/test/java/org/jabref/logic/citationstyle/CitationStyleCacheTest.java b/src/test/java/org/jabref/logic/citationstyle/CitationStyleCacheTest.java index 70e7c26cc56..51e67f8d382 100644 --- a/src/test/java/org/jabref/logic/citationstyle/CitationStyleCacheTest.java +++ b/src/test/java/org/jabref/logic/citationstyle/CitationStyleCacheTest.java @@ -1,16 +1,15 @@ package org.jabref.logic.citationstyle; +import java.util.ArrayList; +import java.util.List; + import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; -import org.jabref.model.texparser.Citation; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import java.util.ArrayList; -import java.util.List; +import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertNotNull; class CitationStyleCacheTest { @@ -20,16 +19,12 @@ class CitationStyleCacheTest { private BibDatabaseContext databaseContext; private CitationStyleCache csCache; - @BeforeAll - static void beforeAll() { - } - @Test void getCitationForTest() { BibEntry bibEntry = new BibEntry(); bibEntry.setCitationKey("test"); List entries = new ArrayList<>(); - entries.add(0,bibEntry); + entries.add(0, bibEntry); BibDatabase database = new BibDatabase(entries); BibDatabaseContext databaseContext = new BibDatabaseContext(database); CitationStyleCache csCache = new CitationStyleCache(databaseContext); diff --git a/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java b/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java index db827d75ea0..35b92e744d7 100644 --- a/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java @@ -7,7 +7,6 @@ import org.jabref.model.entry.field.StandardField; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.function.Executable; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; diff --git a/src/test/java/org/jabref/logic/journals/AbbreviationTest.java b/src/test/java/org/jabref/logic/journals/AbbreviationTest.java index 8f502abef9c..19958130029 100644 --- a/src/test/java/org/jabref/logic/journals/AbbreviationTest.java +++ b/src/test/java/org/jabref/logic/journals/AbbreviationTest.java @@ -2,7 +2,9 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; class AbbreviationTest { diff --git a/src/test/java/org/jabref/model/FieldChangeTest.java b/src/test/java/org/jabref/model/FieldChangeTest.java index 746a98b2bb9..07dbb2a9287 100644 --- a/src/test/java/org/jabref/model/FieldChangeTest.java +++ b/src/test/java/org/jabref/model/FieldChangeTest.java @@ -3,10 +3,12 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.StandardField; -import org.junit.jupiter.api.BeforeAll; + import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; class FieldChangeTest { @@ -15,7 +17,7 @@ class FieldChangeTest { @Test void testHashCode() { FieldChange fcNull = new FieldChange(null, null, null, null); - assertEquals(923521,fcNull.hashCode()); + assertEquals(923521, fcNull.hashCode()); } @Test diff --git a/src/test/java/org/jabref/model/entry/EntryLinkListTest.java b/src/test/java/org/jabref/model/entry/EntryLinkListTest.java index 1ca8fd6dc4b..c360719d452 100644 --- a/src/test/java/org/jabref/model/entry/EntryLinkListTest.java +++ b/src/test/java/org/jabref/model/entry/EntryLinkListTest.java @@ -9,7 +9,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +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 { @@ -59,6 +61,7 @@ public void givenFieldValueAndDatabaseWhenParsingThenExpectLink() { ParsedEntryLink expected = new ParsedEntryLink(KEY, database); assertEquals(expected, link); } + @Test public void givenBibEntryWhenParsingThenExpectLink() { ParsedEntryLink expected = new ParsedEntryLink(entry); diff --git a/src/test/java/org/jabref/model/util/FileHelperTest.java b/src/test/java/org/jabref/model/util/FileHelperTest.java index 5352ff0c5fc..6d047662b12 100644 --- a/src/test/java/org/jabref/model/util/FileHelperTest.java +++ b/src/test/java/org/jabref/model/util/FileHelperTest.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; class FileHelperTest { @Test From 8e297b72396c2f49f92510f2a21b718c5746eece Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Fri, 26 Mar 2021 14:43:58 +0100 Subject: [PATCH 06/29] Update AbbreviationTest.java Adjustments for @ellieMayVelasquez feedback https://github.com/JabRef/jabref/pull/7543#pullrequestreview-617043711 --- src/test/java/org/jabref/logic/journals/AbbreviationTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/jabref/logic/journals/AbbreviationTest.java b/src/test/java/org/jabref/logic/journals/AbbreviationTest.java index 19958130029..92043e5f124 100644 --- a/src/test/java/org/jabref/logic/journals/AbbreviationTest.java +++ b/src/test/java/org/jabref/logic/journals/AbbreviationTest.java @@ -113,7 +113,8 @@ void testToString() { @Test void testEquals() { Abbreviation abbreviation = new Abbreviation("Long Name", "L N", "LN"); - assertTrue(abbreviation.equals(abbreviation)); + Abbreviation otherAbbreviation = new Abbreviation("Long Name", "L N", "LN"); + assertTrue(abbreviation.equals(otherAbbreviation)); assertFalse(abbreviation.equals("String")); } } From 969a29d4572ad7ab9c0ef9a9144209fc8434e6e1 Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 29 Mar 2021 14:19:04 +0200 Subject: [PATCH 07/29] Refactor LayoutEntryTest Assertion Roulette --- .../jabref/logic/layout/LayoutEntryTest.java | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/test/java/org/jabref/logic/layout/LayoutEntryTest.java b/src/test/java/org/jabref/logic/layout/LayoutEntryTest.java index 53a4ff0bf34..a49a5989179 100644 --- a/src/test/java/org/jabref/logic/layout/LayoutEntryTest.java +++ b/src/test/java/org/jabref/logic/layout/LayoutEntryTest.java @@ -70,29 +70,29 @@ public String layout(String layoutFile, BibEntry entry) throws IOException { @Test public void testParseMethodCalls() { - assertEquals(1, LayoutEntry.parseMethodsCalls("bla").size()); - assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla").get(0)).get(0)); - - assertEquals(1, LayoutEntry.parseMethodsCalls("bla,").size()); - assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla,").get(0)).get(0)); - - assertEquals(1, LayoutEntry.parseMethodsCalls("_bla.bla.blub,").size()); - assertEquals("_bla.bla.blub", (LayoutEntry.parseMethodsCalls("_bla.bla.blub,").get(0)).get(0)); - - assertEquals(2, LayoutEntry.parseMethodsCalls("bla,foo").size()); - assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla,foo").get(0)).get(0)); - assertEquals("foo", (LayoutEntry.parseMethodsCalls("bla,foo").get(1)).get(0)); - - assertEquals(2, LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").size()); - assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(0)).get(0)); - assertEquals("foo", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(1)).get(0)); - assertEquals("test", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(0)).get(1)); - assertEquals("fark", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(1)).get(1)); - - assertEquals(2, LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").size()); - assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(0)).get(0)); - assertEquals("foo", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(1)).get(0)); - assertEquals("test", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(0)).get(1)); - assertEquals("fark", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(1)).get(1)); + assertEquals(1, LayoutEntry.parseMethodsCalls("bla").size(), "Parsing of layout entry method calls failed."); + assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla").get(0)).get(0), "Parsing of layout entry method calls failed. Input did not match expected output."); + + assertEquals(1, LayoutEntry.parseMethodsCalls("bla,").size(), "Parsing of layout entry method calls failed. Check for comma behaviour."); + assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla,").get(0)).get(0), "Parsing of layout entry method calls failed. Input did not match expected output."); + + assertEquals(1, LayoutEntry.parseMethodsCalls("_bla.bla.blub,").size(), "Parsing of layout entry method calls failed. Check for special characters."); + assertEquals("_bla.bla.blub", (LayoutEntry.parseMethodsCalls("_bla.bla.blub,").get(0)).get(0),"Parsing of layout entry method calls failed. Input did not match expected output. Check for comma behaviour."); + + assertEquals(2, LayoutEntry.parseMethodsCalls("bla,foo").size(), "Parsing of layout entry method calls failed. Not all arguments were parsed correctly."); + assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla,foo").get(0)).get(0), "Parsing of layout entry method calls failed. Input did not match expected output. Method calls not separated as expected."); + assertEquals("foo", (LayoutEntry.parseMethodsCalls("bla,foo").get(1)).get(0),"Parsing of layout entry method calls failed. Input did not match expected output. Method calls not separated as expected."); + + assertEquals(2, LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").size(),"Parsing of layout entry method calls failed. Check for escaped characters behaviour."); + assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(0)).get(0),"Parsing of layout entry method calls failed. Input did not match expected output. Check for multiple method calls with escaped characters."); + assertEquals("foo", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(1)).get(0),"Parsing of layout entry method calls failed. Input did not match expected output. Check for multiple method calls with escaped characters."); + assertEquals("test", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(0)).get(1),"Parsing of layout entry method calls failed. Input did not match expected output. Check for multiple method calls with escaped characters."); + assertEquals("fark", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(1)).get(1),"Parsing of layout entry method calls failed. Input did not match expected output. Check for multiple method calls with escaped characters."); + + assertEquals(2, LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").size(),"Parsing of layout method calls failed. Check for arguments in parentheses."); + assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(0)).get(0),"Parsing of layout method calls failed. Input did not match expected output. Check for arguments in parentheses."); + assertEquals("foo", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(1)).get(0),"Parsing of layout method calls failed. Input did not match expected output. Check for arguments in parentheses"); + assertEquals("test", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(0)).get(1),"Parsing of layout method calls failed. Input did not match expected output. Check for arguments in parentheses"); + assertEquals("fark", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(1)).get(1),"Parsing of layout method calls failed. Input did not match expected output. Check for arguments in parentheses"); } } From 79153d32fb9b3fb33698016068998fd04555f6bc Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 29 Mar 2021 16:24:54 +0200 Subject: [PATCH 08/29] Refactor OpenDatabaseTest Added Resource Optimism --- .../logic/importer/OpenDatabaseTest.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/jabref/logic/importer/OpenDatabaseTest.java b/src/test/java/org/jabref/logic/importer/OpenDatabaseTest.java index 22e2cba90bf..c71dab89235 100644 --- a/src/test/java/org/jabref/logic/importer/OpenDatabaseTest.java +++ b/src/test/java/org/jabref/logic/importer/OpenDatabaseTest.java @@ -1,7 +1,6 @@ package org.jabref.logic.importer; import java.io.IOException; -import java.net.URISyntaxException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Path; @@ -19,6 +18,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Answers; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -28,19 +28,24 @@ class OpenDatabaseTest { private final Charset defaultEncoding = StandardCharsets.UTF_8; private ImportFormatPreferences importFormatPreferences; private TimestampPreferences timestampPreferences; - private final Path bibNoHeader; - private final Path bibWrongHeader; - private final Path bibHeader; - private final Path bibHeaderAndSignature; - private final Path bibEncodingWithoutNewline; + private Path bibNoHeader = null; + private Path bibWrongHeader = null; + private Path bibHeader = null; + private Path bibHeaderAndSignature = null; + private Path bibEncodingWithoutNewline = null; private final FileUpdateMonitor fileMonitor = new DummyFileUpdateMonitor(); - OpenDatabaseTest() throws URISyntaxException { + OpenDatabaseTest() { + try{ bibNoHeader = Path.of(OpenDatabaseTest.class.getResource("headerless.bib").toURI()); bibWrongHeader = Path.of(OpenDatabaseTest.class.getResource("wrong-header.bib").toURI()); bibHeader = Path.of(OpenDatabaseTest.class.getResource("encoding-header.bib").toURI()); bibHeaderAndSignature = Path.of(OpenDatabaseTest.class.getResource("jabref-header.bib").toURI()); bibEncodingWithoutNewline = Path.of(OpenDatabaseTest.class.getResource("encodingWithoutNewline.bib").toURI()); + } catch (Exception e){ + //Ignore Tests if utility files could not be located + assumeTrue(false); + } } @BeforeEach From bb6f44e72fc31876f6d46d4a21b49555277c50b8 Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 29 Mar 2021 16:30:38 +0200 Subject: [PATCH 09/29] Refactor GroupTreeViewModel Added assertion messages to fix assertion roulette. --- .../org/jabref/gui/groups/GroupTreeViewModelTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java b/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java index f90c5fdf360..d1a8b026d6f 100644 --- a/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java +++ b/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java @@ -40,12 +40,12 @@ void setUp() throws Exception { @Test void rootGroupIsAllEntriesByDefault() throws Exception { AllEntriesGroup allEntriesGroup = new AllEntriesGroup("All entries"); - assertEquals(new GroupNodeViewModel(databaseContext, stateManager, taskExecutor, allEntriesGroup, new CustomLocalDragboard(), mock(PreferencesService.class)), groupTree.rootGroupProperty().getValue()); + assertEquals(new GroupNodeViewModel(databaseContext, stateManager, taskExecutor, allEntriesGroup, new CustomLocalDragboard(), mock(PreferencesService.class)), groupTree.rootGroupProperty().getValue()"New group view model is not set to all entries by default."); } @Test void rootGroupIsSelectedByDefault() { - assertEquals(groupTree.rootGroupProperty().get().getGroupNode(), stateManager.getSelectedGroup(databaseContext).get(0)); + assertEquals(groupTree.rootGroupProperty().get().getGroupNode(), stateManager.getSelectedGroup(databaseContext).get(0),"Root group not selected by default."); } @Test @@ -58,7 +58,7 @@ void explicitGroupsAreRemovedFromEntriesOnDelete() { model.addEntriesToGroup(databaseContext.getEntries()); groupTree.removeGroupsAndSubGroupsFromEntries(model); - assertEquals(Optional.empty(), entry.getField(StandardField.GROUPS)); + assertEquals(Optional.empty(), entry.getField(StandardField.GROUPS),"Explicit group was not removed from BibEntry."); } @Test @@ -72,6 +72,6 @@ void keywordGroupsAreNotRemovedFromEntriesOnDelete() { model.addEntriesToGroup(databaseContext.getEntries()); groupTree.removeGroupsAndSubGroupsFromEntries(model); - assertEquals(groupName, entry.getField(StandardField.KEYWORDS).get()); + assertEquals(groupName, entry.getField(StandardField.KEYWORDS).get(),"Keyword group was not removed from Bibentry."); } } From 075a82def2ee3c48c8e8e602ca025116d2d53cc5 Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 29 Mar 2021 17:12:53 +0200 Subject: [PATCH 10/29] Update GroupTreeViewModelTest.java --- src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java b/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java index d1a8b026d6f..1733f3e1760 100644 --- a/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java +++ b/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java @@ -40,7 +40,7 @@ void setUp() throws Exception { @Test void rootGroupIsAllEntriesByDefault() throws Exception { AllEntriesGroup allEntriesGroup = new AllEntriesGroup("All entries"); - assertEquals(new GroupNodeViewModel(databaseContext, stateManager, taskExecutor, allEntriesGroup, new CustomLocalDragboard(), mock(PreferencesService.class)), groupTree.rootGroupProperty().getValue()"New group view model is not set to all entries by default."); + assertEquals(new GroupNodeViewModel(databaseContext, stateManager, taskExecutor, allEntriesGroup, new CustomLocalDragboard(), mock(PreferencesService.class)), groupTree.rootGroupProperty().getValue(),"New group view model is not set to all entries by default."); } @Test From 9f9ce0322ea9b4c8091b052db2011eea775d592c Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 29 Mar 2021 17:13:53 +0200 Subject: [PATCH 11/29] Refactor MergeReviewIntoCommentActionMigrationTest General Fixture, removed test code duplication --- ...eReviewIntoCommentActionMigrationTest.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/test/java/org/jabref/migrations/MergeReviewIntoCommentActionMigrationTest.java b/src/test/java/org/jabref/migrations/MergeReviewIntoCommentActionMigrationTest.java index 2668527fd37..e72d79235df 100644 --- a/src/test/java/org/jabref/migrations/MergeReviewIntoCommentActionMigrationTest.java +++ b/src/test/java/org/jabref/migrations/MergeReviewIntoCommentActionMigrationTest.java @@ -7,6 +7,7 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -15,15 +16,25 @@ class MergeReviewIntoCommentActionMigrationTest { private MergeReviewIntoCommentMigration action; + private BibEntry entry; + private BibEntry expectedEntry; @BeforeEach public void setUp() { action = new MergeReviewIntoCommentMigration(); + entry = createMinimalBibEntry(); + expectedEntry = createMinimalBibEntry(); + } + + @AfterEach + public void tearDown(){ + action = null; + entry = null; + expectedEntry = null; } @Test public void noFields() { - BibEntry entry = createMinimalBibEntry(); ParserResult actualParserResult = new ParserResult(Collections.singletonList(entry)); action.performMigration(actualParserResult); @@ -33,11 +44,9 @@ public void noFields() { @Test public void reviewField() { - BibEntry actualEntry = createMinimalBibEntry(); - actualEntry.setField(StandardField.REVIEW, "My Review"); - ParserResult actualParserResult = new ParserResult(Collections.singletonList(actualEntry)); + entry.setField(StandardField.REVIEW, "My Review"); + ParserResult actualParserResult = new ParserResult(Collections.singletonList(entry)); - BibEntry expectedEntry = createMinimalBibEntry(); expectedEntry.setField(StandardField.COMMENT, "My Review"); action.performMigration(actualParserResult); @@ -47,7 +56,6 @@ public void reviewField() { @Test public void commentField() { - BibEntry entry = createMinimalBibEntry(); entry.setField(StandardField.COMMENT, "My Comment"); ParserResult actualParserResult = new ParserResult(Collections.singletonList(entry)); @@ -60,11 +68,9 @@ public void commentField() { public void multiLineReviewField() { String commentString = "My Review\n\nSecond Paragraph\n\nThird Paragraph"; - BibEntry actualEntry = createMinimalBibEntry(); - actualEntry.setField(StandardField.REVIEW, commentString); - ParserResult actualParserResult = new ParserResult(Collections.singletonList(actualEntry)); + entry.setField(StandardField.REVIEW, commentString); + ParserResult actualParserResult = new ParserResult(Collections.singletonList(entry)); - BibEntry expectedEntry = createMinimalBibEntry(); expectedEntry.setField(StandardField.COMMENT, commentString); action.performMigration(actualParserResult); @@ -75,13 +81,11 @@ public void multiLineReviewField() { @Test @Disabled("Re-enable if the MergeReviewIntoCommentMigration.mergeCommentFieldIfPresent() does not block and wait for user input.") public void reviewAndCommentField() { - BibEntry actualEntry = createMinimalBibEntry(); - actualEntry.setField(StandardField.REVIEW, "My Review"); - actualEntry.setField(StandardField.COMMENT, "My Comment"); + entry.setField(StandardField.REVIEW, "My Review"); + entry.setField(StandardField.COMMENT, "My Comment"); - ParserResult actualParserResult = new ParserResult(Collections.singletonList(actualEntry)); + ParserResult actualParserResult = new ParserResult(Collections.singletonList(entry)); - BibEntry expectedEntry = createMinimalBibEntry(); expectedEntry.setField(StandardField.COMMENT, "My Comment\n" + Localization.lang("Review") + ":\nMy Review"); action.performMigration(actualParserResult); From a0bf585347547ab6e66b0e79a6919893e07e3499 Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 29 Mar 2021 17:42:34 +0200 Subject: [PATCH 12/29] Update MergeReviewIntoCommentActionMigrationTest.java checkstyle fix --- .../migrations/MergeReviewIntoCommentActionMigrationTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/org/jabref/migrations/MergeReviewIntoCommentActionMigrationTest.java b/src/test/java/org/jabref/migrations/MergeReviewIntoCommentActionMigrationTest.java index e72d79235df..ee0691d160f 100644 --- a/src/test/java/org/jabref/migrations/MergeReviewIntoCommentActionMigrationTest.java +++ b/src/test/java/org/jabref/migrations/MergeReviewIntoCommentActionMigrationTest.java @@ -15,6 +15,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; class MergeReviewIntoCommentActionMigrationTest { + private MergeReviewIntoCommentMigration action; private BibEntry entry; private BibEntry expectedEntry; From 1d520a1711ae22cffbb475cf3728635ace398e61 Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 29 Mar 2021 17:44:19 +0200 Subject: [PATCH 13/29] Refactor SpecialFieldsToSeparateFieldsTest General Refactoring --- .../SpecialFieldsToSeparateFieldsTest.java | 54 ++++++++++++------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/src/test/java/org/jabref/migrations/SpecialFieldsToSeparateFieldsTest.java b/src/test/java/org/jabref/migrations/SpecialFieldsToSeparateFieldsTest.java index b1f64b2ca99..15a400bffd3 100644 --- a/src/test/java/org/jabref/migrations/SpecialFieldsToSeparateFieldsTest.java +++ b/src/test/java/org/jabref/migrations/SpecialFieldsToSeparateFieldsTest.java @@ -8,6 +8,8 @@ import org.jabref.model.entry.field.SpecialField; import org.jabref.model.entry.field.StandardField; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -17,10 +19,25 @@ class SpecialFieldsToSeparateFieldsTest { + private BibEntry entry; + private BibEntry expectedEntry; + + @BeforeEach + void setUp(){ + entry = new BibEntry(); + expectedEntry = new BibEntry(); + } + + @AfterEach + void tearDown(){ + entry = null; + expectedEntry = null; + } + @ParameterizedTest @MethodSource("provideKeywordFieldPairs") public void migrateToCorrectField(SpecialField field, String fieldInKeyword, BibEntry expected) { - BibEntry entry = new BibEntry().withField(StandardField.KEYWORDS, fieldInKeyword); + entry = new BibEntry().withField(StandardField.KEYWORDS, fieldInKeyword); new SpecialFieldsToSeparateFields(',').performMigration(new ParserResult(List.of(entry))); @@ -29,41 +46,40 @@ public void migrateToCorrectField(SpecialField field, String fieldInKeyword, Bib @Test public void noKewordToMigrate() { - BibEntry entry = new BibEntry().withField(StandardField.AUTHOR, "JabRef") - .withField(StandardField.KEYWORDS, "tdd"); - BibEntry expected = new BibEntry().withField(StandardField.AUTHOR, "JabRef") - .withField(StandardField.KEYWORDS, "tdd"); + entry.setField(StandardField.AUTHOR, "JabRef"); + entry.setField(StandardField.KEYWORDS, "tdd"); + expectedEntry.setField(StandardField.AUTHOR,"JabRef"); + expectedEntry.setField(StandardField.KEYWORDS, "tdd"); new SpecialFieldsToSeparateFields(',').performMigration(new ParserResult(List.of(entry))); - assertEquals(expected, entry); + assertEquals(expectedEntry, entry); } @Test public void migrateMultipleSpecialFields() { - BibEntry entry = new BibEntry().withField(StandardField.AUTHOR, "JabRef") - .withField(StandardField.KEYWORDS, "printed, prio1"); - BibEntry expected = new BibEntry().withField(StandardField.AUTHOR, "JabRef") - .withField(SpecialField.PRINTED, "printed") - .withField(SpecialField.PRIORITY, "prio1"); + entry.setField(StandardField.AUTHOR, "JabRef"); + entry.setField(StandardField.KEYWORDS, "printed, prio1"); + expectedEntry.setField(StandardField.AUTHOR, "JabRef"); + expectedEntry.setField(SpecialField.PRINTED, "printed"); + expectedEntry.setField(SpecialField.PRIORITY, "prio1"); new SpecialFieldsToSeparateFields(',').performMigration(new ParserResult(List.of(entry))); - assertEquals(expected, entry); + assertEquals(expectedEntry, entry); } @Test public void migrateSpecialFieldsMixedWithKeyword() { - BibEntry entry = new BibEntry().withField(StandardField.AUTHOR, "JabRef") - .withField(StandardField.KEYWORDS, "tdd, prio1, SE"); - - BibEntry expected = new BibEntry().withField(StandardField.AUTHOR, "JabRef") - .withField(StandardField.KEYWORDS, "tdd, SE") - .withField(SpecialField.PRIORITY, "prio1"); + entry.setField(StandardField.AUTHOR, "JabRef"); + entry.setField(StandardField.KEYWORDS, "tdd, prio1, SE"); + expectedEntry.setField(StandardField.AUTHOR, "JabRef"); + expectedEntry.setField(StandardField.KEYWORDS, "tdd, SE"); + expectedEntry.setField(SpecialField.PRIORITY, "prio1"); new SpecialFieldsToSeparateFields(',').performMigration(new ParserResult(List.of(entry))); - assertEquals(expected, entry); + assertEquals(expectedEntry, entry); } private static Stream provideKeywordFieldPairs() { From 250d8593e2a576331c1acfcdd77b09eadf5964f5 Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 29 Mar 2021 17:57:14 +0200 Subject: [PATCH 14/29] remove aftereach methods not needed --- .../MergeReviewIntoCommentActionMigrationTest.java | 7 ------- .../migrations/SpecialFieldsToSeparateFieldsTest.java | 8 +------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/src/test/java/org/jabref/migrations/MergeReviewIntoCommentActionMigrationTest.java b/src/test/java/org/jabref/migrations/MergeReviewIntoCommentActionMigrationTest.java index ee0691d160f..e1f235a6ebc 100644 --- a/src/test/java/org/jabref/migrations/MergeReviewIntoCommentActionMigrationTest.java +++ b/src/test/java/org/jabref/migrations/MergeReviewIntoCommentActionMigrationTest.java @@ -27,13 +27,6 @@ public void setUp() { expectedEntry = createMinimalBibEntry(); } - @AfterEach - public void tearDown(){ - action = null; - entry = null; - expectedEntry = null; - } - @Test public void noFields() { ParserResult actualParserResult = new ParserResult(Collections.singletonList(entry)); diff --git a/src/test/java/org/jabref/migrations/SpecialFieldsToSeparateFieldsTest.java b/src/test/java/org/jabref/migrations/SpecialFieldsToSeparateFieldsTest.java index 15a400bffd3..6d6fe8cb5ce 100644 --- a/src/test/java/org/jabref/migrations/SpecialFieldsToSeparateFieldsTest.java +++ b/src/test/java/org/jabref/migrations/SpecialFieldsToSeparateFieldsTest.java @@ -27,13 +27,7 @@ void setUp(){ entry = new BibEntry(); expectedEntry = new BibEntry(); } - - @AfterEach - void tearDown(){ - entry = null; - expectedEntry = null; - } - + @ParameterizedTest @MethodSource("provideKeywordFieldPairs") public void migrateToCorrectField(SpecialField field, String fieldInKeyword, BibEntry expected) { From a170e5dbd238902c692713529e6c3495d6fd5740 Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 29 Mar 2021 21:06:45 +0200 Subject: [PATCH 15/29] Refactor JournalAbbreviationsViewModelMixedAbbreviationsTabTest Fixed AssertionRoulette, one instance of duplicated test code. --- ...onsViewModelMixedAbbreviationsTabTest.java | 66 +++++++++---------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/src/test/java/org/jabref/gui/journals/JournalAbbreviationsViewModelMixedAbbreviationsTabTest.java b/src/test/java/org/jabref/gui/journals/JournalAbbreviationsViewModelMixedAbbreviationsTabTest.java index 9c906027888..0f01307bda7 100644 --- a/src/test/java/org/jabref/gui/journals/JournalAbbreviationsViewModelMixedAbbreviationsTabTest.java +++ b/src/test/java/org/jabref/gui/journals/JournalAbbreviationsViewModelMixedAbbreviationsTabTest.java @@ -69,8 +69,8 @@ void setUpViewModel(@TempDir Path tempFolder) throws Exception { @Test void testInitialHasNoFilesAndNoAbbreviations() { - assertEquals(0, viewModel.journalFilesProperty().size()); - assertEquals(0, viewModel.abbreviationsProperty().size()); + assertEquals(0, viewModel.journalFilesProperty().size(), "Incorrect setup of test. Journal files not set to 0 at setup."); + assertEquals(0, viewModel.abbreviationsProperty().size(),"Incorrect setup of test. Abbreviations not set to 0 at setup"); } @Test @@ -96,8 +96,8 @@ void addFileIncreasesCounterOfOpenFilesAndHasNoAbbreviations() { when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(emptyTestFile)); viewModel.addNewFile(); - assertEquals(1, viewModel.journalFilesProperty().size()); - assertEquals(1, viewModel.abbreviationsProperty().size()); + assertEquals(1, viewModel.journalFilesProperty().size(), "Incorrect amount of journal files in view model after adding empty test file."); + assertEquals(1, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations in view model after adding empty test file."); } @Test @@ -136,10 +136,10 @@ void testOpenValidFileContainsTheSpecificEntryAndEnoughAbbreviations() { viewModel.addNewFile(); viewModel.selectLastJournalFile(); - assertEquals(1, viewModel.journalFilesProperty().size()); + assertEquals(1, viewModel.journalFilesProperty().size(), "Incorrect amount of journal files in view model after adding one journal."); // our test file has 3 abbreviations and one pseudo abbreviation - assertEquals(4, viewModel.abbreviationsProperty().size()); - assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation))); + assertEquals(4, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations in view model after adding four entries."); + assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation)), "Test abbreviation was not correctly added to view model."); } @Test @@ -148,10 +148,10 @@ void testRemoveLastListSetsCurrentFileAndCurrentAbbreviationToNull() { viewModel.addNewFile(); viewModel.removeCurrentFile(); - assertEquals(0, viewModel.journalFilesProperty().size()); - assertEquals(0, viewModel.abbreviationsProperty().size()); - assertNull(viewModel.currentFileProperty().get()); - assertNull(viewModel.currentAbbreviationProperty().get()); + assertEquals(0, viewModel.journalFilesProperty().size(), "Incorrect amount of journal files in view model after adding and removing file."); + assertEquals(0, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations in view model after adding and removing file."); + assertNull(viewModel.currentFileProperty().get(), "Current file not removed correctly in view model."); + assertNull(viewModel.currentAbbreviationProperty().get(), "Current abbreviation not removed correctly in view model."); } @Test @@ -167,11 +167,11 @@ void testMixedFileUsage() { viewModel.currentFileProperty().set(viewModel.journalFilesProperty().get(1)); // size of the list of journal files should be incremented by two - assertEquals(2, viewModel.journalFilesProperty().size()); + assertEquals(2, viewModel.journalFilesProperty().size(), "Incorrect amount of journal files after adding two files."); // our second test file has 4 abbreviations - assertEquals(5, viewModel.abbreviationsProperty().size()); + assertEquals(5, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations after adding five entries."); // check some abbreviation - assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation))); + assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation)), "Abbreviation 1 was not added correctly."); // simulate add new file button when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(emptyTestFile)); @@ -179,9 +179,9 @@ void testMixedFileUsage() { viewModel.currentFileProperty().set(viewModel.journalFilesProperty().get(2)); // size of the list of journal files should be incremented by one - assertEquals(3, viewModel.journalFilesProperty().size()); + assertEquals(3, viewModel.journalFilesProperty().size(), "Incorrect amount of journal files after adding three files"); // a new file has zero abbreviations - assertEquals(1, viewModel.abbreviationsProperty().size()); + assertEquals(1, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations after adding one entry"); // simulate open file button when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile5EntriesWithDuplicate)); @@ -189,11 +189,11 @@ void testMixedFileUsage() { viewModel.currentFileProperty().set(viewModel.journalFilesProperty().get(3)); // size of the list of journal files should be incremented by one - assertEquals(4, viewModel.journalFilesProperty().size()); + assertEquals(4, viewModel.journalFilesProperty().size(), "Incorrect amount of journal files after simulating open file button."); - assertEquals(5, viewModel.abbreviationsProperty().size()); + assertEquals(5, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations after simulating open file button."); // check some abbreviation - assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation2))); + assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation2)), "Abbreviation 2 was not added correctly."); } @Test @@ -227,21 +227,19 @@ void testCurrentFilePropertyChangeActiveFile() { AbbreviationsFileViewModel test5 = viewModel.journalFilesProperty().get(3); // test if the last opened file is active, but duplicated entry has been removed - assertEquals(5, viewModel.abbreviationsProperty().size()); + assertEquals(5, viewModel.abbreviationsProperty().size(), "Last opened file is not active or duplicated entry was not removed."); viewModel.currentFileProperty().set(test1); // test if the current abbreviations matches with the ones in testFile1Entries - assertEquals(2, viewModel.abbreviationsProperty().size()); + assertEquals(2, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations after setting active testFile1."); viewModel.currentFileProperty().set(test3); - assertEquals(4, viewModel.abbreviationsProperty().size()); - viewModel.currentFileProperty().set(test1); - assertEquals(2, viewModel.abbreviationsProperty().size()); + assertEquals(4, viewModel.abbreviationsProperty().size(), "Incorrect amount of journals after setting active testFile3."); viewModel.currentFileProperty().set(test4); - assertEquals(5, viewModel.abbreviationsProperty().size()); + assertEquals(5, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations after setting active testFile4."); viewModel.currentFileProperty().set(test5); - assertEquals(5, viewModel.abbreviationsProperty().size()); + assertEquals(5, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations after setting active testFile5."); } @Test @@ -254,8 +252,8 @@ void testAddAbbreviationIncludesAbbreviationsInAbbreviationList() { Abbreviation testAbbreviation = new Abbreviation("YetAnotherEntry", "YAE"); addAbbrevaition(testAbbreviation); - assertEquals(6, viewModel.abbreviationsProperty().size()); - assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation))); + assertEquals(6, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations after setting active testFile5 and adding YAE entry."); + assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation)), "YAE abbreviation was not correctly added."); } @Test @@ -291,16 +289,16 @@ void testEditAbbreviationIncludesNewAbbreviationInAbbreviationsList() { Abbreviation testAbbreviation = new Abbreviation("YetAnotherEntry", "YAE"); editAbbreviation(testAbbreviation); - assertEquals(5, viewModel.abbreviationsProperty().size()); - assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation))); + assertEquals(5, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations after setting active testFile5 and adding YAE abbreviation."); + assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation)), "YAE abbreviation was not correctly added."); when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(emptyTestFile)); viewModel.addNewFile(); viewModel.selectLastJournalFile(); editAbbreviation(testAbbreviation); - assertEquals(1, viewModel.abbreviationsProperty().size()); - assertFalse(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation))); + assertEquals(1, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations after setting active emptyTestFile and adding YAE abbreviation."); + assertFalse(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation)), "Test abbreviation YAE was not edited as expected."); } @Test @@ -359,9 +357,9 @@ void testDeleteAbbreviationSelectsPreviousOne() { viewModel.deleteAbbreviation(); - assertEquals(5, viewModel.abbreviationsProperty().size()); + assertEquals(5, viewModel.abbreviationsProperty().size(), "Previously added abbreviation YAE was not deleted correctly."); // check if the previous (the last) element is the current abbreviation - assertEquals(viewModel.currentAbbreviationProperty().get(), viewModel.abbreviationsProperty().get(4)); + assertEquals(viewModel.currentAbbreviationProperty().get(), viewModel.abbreviationsProperty().get(4), "Last element of abbreviation list is not set to current abbreviation."); } @Test From e4e6a9c40090537c4160bd3d058e5384b86c916a Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 29 Mar 2021 22:56:50 +0200 Subject: [PATCH 16/29] Refactor UpdateTimestampListenerTest Test code duplication --- .../org/jabref/gui/UpdateTimestampListenerTest.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/jabref/gui/UpdateTimestampListenerTest.java b/src/test/java/org/jabref/gui/UpdateTimestampListenerTest.java index 23c29c4d623..93761db0d89 100644 --- a/src/test/java/org/jabref/gui/UpdateTimestampListenerTest.java +++ b/src/test/java/org/jabref/gui/UpdateTimestampListenerTest.java @@ -24,7 +24,10 @@ class UpdateTimestampListenerTest { private PreferencesService preferencesMock; private TimestampPreferences timestampPreferencesMock; - @BeforeEach + private final String baseDate = "2000-1-1"; + private final String newDate = "2000-1-2"; + + @BeforeEach void setUp() { database = new BibDatabase(); bibEntry = new BibEntry(); @@ -39,9 +42,6 @@ void setUp() { @Test void updateTimestampEnabled() { - final String baseDate = "2000-1-1"; - final String newDate = "2000-1-2"; - final boolean includeTimestamp = true; when(timestampPreferencesMock.now()).thenReturn(newDate); @@ -60,9 +60,6 @@ void updateTimestampEnabled() { @Test void updateTimestampDisabled() { - final String baseDate = "2000-1-1"; - final String newDate = "2000-1-2"; - final boolean includeTimestamp = false; when(timestampPreferencesMock.now()).thenReturn(newDate); From a7a5373e81db62513f4ff97edfec649307219cc5 Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 29 Mar 2021 23:01:27 +0200 Subject: [PATCH 17/29] Refactor FileFieldWriterTest Assertion Roulette fixed --- .../java/org/jabref/logic/bibtex/FileFieldWriterTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/jabref/logic/bibtex/FileFieldWriterTest.java b/src/test/java/org/jabref/logic/bibtex/FileFieldWriterTest.java index a9c722a3815..835ada7bc5c 100644 --- a/src/test/java/org/jabref/logic/bibtex/FileFieldWriterTest.java +++ b/src/test/java/org/jabref/logic/bibtex/FileFieldWriterTest.java @@ -33,10 +33,10 @@ public void testQuoteNull() { @Test public void testEncodeStringArray() { - assertEquals("a:b;c:d", FileFieldWriter.encodeStringArray(new String[][] {{"a", "b"}, {"c", "d"}})); - assertEquals("a:;c:d", FileFieldWriter.encodeStringArray(new String[][] {{"a", ""}, {"c", "d"}})); - assertEquals("a:" + null + ";c:d", FileFieldWriter.encodeStringArray(new String[][] {{"a", null}, {"c", "d"}})); - assertEquals("a:\\:b;c\\;:d", FileFieldWriter.encodeStringArray(new String[][] {{"a", ":b"}, {"c;", "d"}})); + assertEquals("a:b;c:d", FileFieldWriter.encodeStringArray(new String[][] {{"a", "b"}, {"c", "d"}}), "Encoding of stringArray failed."); + assertEquals("a:;c:d", FileFieldWriter.encodeStringArray(new String[][] {{"a", ""}, {"c", "d"}}), "Encoding of stringArray failed. Check empty string case."); + assertEquals("a:" + null + ";c:d", FileFieldWriter.encodeStringArray(new String[][] {{"a", null}, {"c", "d"}}), "Encoding of stringArray failed. Check null case."); + assertEquals("a:\\:b;c\\;:d", FileFieldWriter.encodeStringArray(new String[][] {{"a", ":b"}, {"c;", "d"}}), "Encoding of stringArray failed. Check escaped character case."); } @Test From 6585b8ea1216d921ef46138b75389f81c1e80cc2 Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 29 Mar 2021 23:09:25 +0200 Subject: [PATCH 18/29] Refactor SentenceAnalyzerTest fixed Assertion Roulette --- .../jabref/model/search/rules/SentenceAnalyzerTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/jabref/model/search/rules/SentenceAnalyzerTest.java b/src/test/java/org/jabref/model/search/rules/SentenceAnalyzerTest.java index 732f4114f5f..b425639e9a0 100644 --- a/src/test/java/org/jabref/model/search/rules/SentenceAnalyzerTest.java +++ b/src/test/java/org/jabref/model/search/rules/SentenceAnalyzerTest.java @@ -11,9 +11,9 @@ public class SentenceAnalyzerTest { @Test public void testGetWords() { - assertEquals(Arrays.asList("a", "b"), new SentenceAnalyzer("a b").getWords()); - assertEquals(Arrays.asList("a", "b"), new SentenceAnalyzer(" a b ").getWords()); - assertEquals(Collections.singletonList("b "), new SentenceAnalyzer("\"b \" ").getWords()); - assertEquals(Collections.singletonList(" a"), new SentenceAnalyzer(" \\ a").getWords()); + assertEquals(Arrays.asList("a", "b"), new SentenceAnalyzer("a b").getWords(), "Sentence was not parsed correctly."); + assertEquals(Arrays.asList("a", "b"), new SentenceAnalyzer(" a b ").getWords(), "Sentence was not parsed correctly. Check leading and trailing spaces."); + assertEquals(Collections.singletonList("b "), new SentenceAnalyzer("\"b \" ").getWords(), "Sentence was not parsed correctly. Check escaped characters and trailing spaces."); + assertEquals(Collections.singletonList(" a"), new SentenceAnalyzer(" \\ a").getWords(), "Sentence was not parsed correctly. Check escaped characters and leading spaces."); } } From 12537a972f13f271835e048a2afd6e44b38d613d Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Tue, 30 Mar 2021 03:06:58 +0200 Subject: [PATCH 19/29] checkstyle Fixes --- .../gui/groups/GroupTreeViewModelTest.java | 8 +++--- ...onsViewModelMixedAbbreviationsTabTest.java | 2 +- .../logic/importer/OpenDatabaseTest.java | 8 +++--- .../jabref/logic/layout/LayoutEntryTest.java | 28 +++++++++---------- ...eReviewIntoCommentActionMigrationTest.java | 1 - .../SpecialFieldsToSeparateFieldsTest.java | 11 ++++---- 6 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java b/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java index 1733f3e1760..a6611bca54d 100644 --- a/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java +++ b/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java @@ -40,12 +40,12 @@ void setUp() throws Exception { @Test void rootGroupIsAllEntriesByDefault() throws Exception { AllEntriesGroup allEntriesGroup = new AllEntriesGroup("All entries"); - assertEquals(new GroupNodeViewModel(databaseContext, stateManager, taskExecutor, allEntriesGroup, new CustomLocalDragboard(), mock(PreferencesService.class)), groupTree.rootGroupProperty().getValue(),"New group view model is not set to all entries by default."); + assertEquals(new GroupNodeViewModel(databaseContext, stateManager, taskExecutor, allEntriesGroup, new CustomLocalDragboard(), mock(PreferencesService.class)), groupTree.rootGroupProperty().getValue(), "New group view model is not set to all entries by default."); } @Test void rootGroupIsSelectedByDefault() { - assertEquals(groupTree.rootGroupProperty().get().getGroupNode(), stateManager.getSelectedGroup(databaseContext).get(0),"Root group not selected by default."); + assertEquals(groupTree.rootGroupProperty().get().getGroupNode(), stateManager.getSelectedGroup(databaseContext).get(0), "Root group not selected by default."); } @Test @@ -58,7 +58,7 @@ void explicitGroupsAreRemovedFromEntriesOnDelete() { model.addEntriesToGroup(databaseContext.getEntries()); groupTree.removeGroupsAndSubGroupsFromEntries(model); - assertEquals(Optional.empty(), entry.getField(StandardField.GROUPS),"Explicit group was not removed from BibEntry."); + assertEquals(Optional.empty(), entry.getField(StandardField.GROUPS), "Explicit group was not removed from BibEntry."); } @Test @@ -72,6 +72,6 @@ void keywordGroupsAreNotRemovedFromEntriesOnDelete() { model.addEntriesToGroup(databaseContext.getEntries()); groupTree.removeGroupsAndSubGroupsFromEntries(model); - assertEquals(groupName, entry.getField(StandardField.KEYWORDS).get(),"Keyword group was not removed from Bibentry."); + assertEquals(groupName, entry.getField(StandardField.KEYWORDS).get(), "Keyword group was not removed from Bibentry."); } } diff --git a/src/test/java/org/jabref/gui/journals/JournalAbbreviationsViewModelMixedAbbreviationsTabTest.java b/src/test/java/org/jabref/gui/journals/JournalAbbreviationsViewModelMixedAbbreviationsTabTest.java index 0f01307bda7..976e98c04e5 100644 --- a/src/test/java/org/jabref/gui/journals/JournalAbbreviationsViewModelMixedAbbreviationsTabTest.java +++ b/src/test/java/org/jabref/gui/journals/JournalAbbreviationsViewModelMixedAbbreviationsTabTest.java @@ -70,7 +70,7 @@ void setUpViewModel(@TempDir Path tempFolder) throws Exception { @Test void testInitialHasNoFilesAndNoAbbreviations() { assertEquals(0, viewModel.journalFilesProperty().size(), "Incorrect setup of test. Journal files not set to 0 at setup."); - assertEquals(0, viewModel.abbreviationsProperty().size(),"Incorrect setup of test. Abbreviations not set to 0 at setup"); + assertEquals(0, viewModel.abbreviationsProperty().size(), "Incorrect setup of test. Abbreviations not set to 0 at setup"); } @Test diff --git a/src/test/java/org/jabref/logic/importer/OpenDatabaseTest.java b/src/test/java/org/jabref/logic/importer/OpenDatabaseTest.java index c71dab89235..25b13ad72c2 100644 --- a/src/test/java/org/jabref/logic/importer/OpenDatabaseTest.java +++ b/src/test/java/org/jabref/logic/importer/OpenDatabaseTest.java @@ -18,8 +18,8 @@ import org.junit.jupiter.api.Test; import org.mockito.Answers; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -36,14 +36,14 @@ class OpenDatabaseTest { private final FileUpdateMonitor fileMonitor = new DummyFileUpdateMonitor(); OpenDatabaseTest() { - try{ + try { bibNoHeader = Path.of(OpenDatabaseTest.class.getResource("headerless.bib").toURI()); bibWrongHeader = Path.of(OpenDatabaseTest.class.getResource("wrong-header.bib").toURI()); bibHeader = Path.of(OpenDatabaseTest.class.getResource("encoding-header.bib").toURI()); bibHeaderAndSignature = Path.of(OpenDatabaseTest.class.getResource("jabref-header.bib").toURI()); bibEncodingWithoutNewline = Path.of(OpenDatabaseTest.class.getResource("encodingWithoutNewline.bib").toURI()); - } catch (Exception e){ - //Ignore Tests if utility files could not be located + } catch (Exception e) { + // Ignore Tests if utility files could not be located assumeTrue(false); } } diff --git a/src/test/java/org/jabref/logic/layout/LayoutEntryTest.java b/src/test/java/org/jabref/logic/layout/LayoutEntryTest.java index a49a5989179..1b142219c85 100644 --- a/src/test/java/org/jabref/logic/layout/LayoutEntryTest.java +++ b/src/test/java/org/jabref/logic/layout/LayoutEntryTest.java @@ -77,22 +77,22 @@ public void testParseMethodCalls() { assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla,").get(0)).get(0), "Parsing of layout entry method calls failed. Input did not match expected output."); assertEquals(1, LayoutEntry.parseMethodsCalls("_bla.bla.blub,").size(), "Parsing of layout entry method calls failed. Check for special characters."); - assertEquals("_bla.bla.blub", (LayoutEntry.parseMethodsCalls("_bla.bla.blub,").get(0)).get(0),"Parsing of layout entry method calls failed. Input did not match expected output. Check for comma behaviour."); + assertEquals("_bla.bla.blub", (LayoutEntry.parseMethodsCalls("_bla.bla.blub,").get(0)).get(0), "Parsing of layout entry method calls failed. Input did not match expected output. Check for comma behaviour."); assertEquals(2, LayoutEntry.parseMethodsCalls("bla,foo").size(), "Parsing of layout entry method calls failed. Not all arguments were parsed correctly."); assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla,foo").get(0)).get(0), "Parsing of layout entry method calls failed. Input did not match expected output. Method calls not separated as expected."); - assertEquals("foo", (LayoutEntry.parseMethodsCalls("bla,foo").get(1)).get(0),"Parsing of layout entry method calls failed. Input did not match expected output. Method calls not separated as expected."); - - assertEquals(2, LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").size(),"Parsing of layout entry method calls failed. Check for escaped characters behaviour."); - assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(0)).get(0),"Parsing of layout entry method calls failed. Input did not match expected output. Check for multiple method calls with escaped characters."); - assertEquals("foo", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(1)).get(0),"Parsing of layout entry method calls failed. Input did not match expected output. Check for multiple method calls with escaped characters."); - assertEquals("test", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(0)).get(1),"Parsing of layout entry method calls failed. Input did not match expected output. Check for multiple method calls with escaped characters."); - assertEquals("fark", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(1)).get(1),"Parsing of layout entry method calls failed. Input did not match expected output. Check for multiple method calls with escaped characters."); - - assertEquals(2, LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").size(),"Parsing of layout method calls failed. Check for arguments in parentheses."); - assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(0)).get(0),"Parsing of layout method calls failed. Input did not match expected output. Check for arguments in parentheses."); - assertEquals("foo", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(1)).get(0),"Parsing of layout method calls failed. Input did not match expected output. Check for arguments in parentheses"); - assertEquals("test", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(0)).get(1),"Parsing of layout method calls failed. Input did not match expected output. Check for arguments in parentheses"); - assertEquals("fark", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(1)).get(1),"Parsing of layout method calls failed. Input did not match expected output. Check for arguments in parentheses"); + assertEquals("foo", (LayoutEntry.parseMethodsCalls("bla,foo").get(1)).get(0), "Parsing of layout entry method calls failed. Input did not match expected output. Method calls not separated as expected."); + + assertEquals(2, LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").size(), "Parsing of layout entry method calls failed. Check for escaped characters behaviour."); + assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(0)).get(0), "Parsing of layout entry method calls failed. Input did not match expected output. Check for multiple method calls with escaped characters."); + assertEquals("foo", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(1)).get(0), "Parsing of layout entry method calls failed. Input did not match expected output. Check for multiple method calls with escaped characters."); + assertEquals("test", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(0)).get(1), "Parsing of layout entry method calls failed. Input did not match expected output. Check for multiple method calls with escaped characters."); + assertEquals("fark", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(1)).get(1), "Parsing of layout entry method calls failed. Input did not match expected output. Check for multiple method calls with escaped characters."); + + assertEquals(2, LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").size(), "Parsing of layout method calls failed. Check for arguments in parentheses."); + assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(0)).get(0), "Parsing of layout method calls failed. Input did not match expected output. Check for arguments in parentheses."); + assertEquals("foo", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(1)).get(0), "Parsing of layout method calls failed. Input did not match expected output. Check for arguments in parentheses"); + assertEquals("test", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(0)).get(1), "Parsing of layout method calls failed. Input did not match expected output. Check for arguments in parentheses"); + assertEquals("fark", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(1)).get(1), "Parsing of layout method calls failed. Input did not match expected output. Check for arguments in parentheses"); } } diff --git a/src/test/java/org/jabref/migrations/MergeReviewIntoCommentActionMigrationTest.java b/src/test/java/org/jabref/migrations/MergeReviewIntoCommentActionMigrationTest.java index e1f235a6ebc..39d94ef7d52 100644 --- a/src/test/java/org/jabref/migrations/MergeReviewIntoCommentActionMigrationTest.java +++ b/src/test/java/org/jabref/migrations/MergeReviewIntoCommentActionMigrationTest.java @@ -7,7 +7,6 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; diff --git a/src/test/java/org/jabref/migrations/SpecialFieldsToSeparateFieldsTest.java b/src/test/java/org/jabref/migrations/SpecialFieldsToSeparateFieldsTest.java index 6d6fe8cb5ce..cbee10c9414 100644 --- a/src/test/java/org/jabref/migrations/SpecialFieldsToSeparateFieldsTest.java +++ b/src/test/java/org/jabref/migrations/SpecialFieldsToSeparateFieldsTest.java @@ -8,7 +8,6 @@ import org.jabref.model.entry.field.SpecialField; import org.jabref.model.entry.field.StandardField; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -23,11 +22,11 @@ class SpecialFieldsToSeparateFieldsTest { private BibEntry expectedEntry; @BeforeEach - void setUp(){ - entry = new BibEntry(); - expectedEntry = new BibEntry(); + void setUp() { + entry = new BibEntry(); + expectedEntry = new BibEntry(); } - + @ParameterizedTest @MethodSource("provideKeywordFieldPairs") public void migrateToCorrectField(SpecialField field, String fieldInKeyword, BibEntry expected) { @@ -42,7 +41,7 @@ public void migrateToCorrectField(SpecialField field, String fieldInKeyword, Bib public void noKewordToMigrate() { entry.setField(StandardField.AUTHOR, "JabRef"); entry.setField(StandardField.KEYWORDS, "tdd"); - expectedEntry.setField(StandardField.AUTHOR,"JabRef"); + expectedEntry.setField(StandardField.AUTHOR, "JabRef"); expectedEntry.setField(StandardField.KEYWORDS, "tdd"); new SpecialFieldsToSeparateFields(',').performMigration(new ParserResult(List.of(entry))); From a3f5753f22645b0fa7344e3a4f3e6ca68f068514 Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Tue, 30 Mar 2021 03:07:35 +0200 Subject: [PATCH 20/29] Add unit tests to increase code coverage --- .../PdfDocumentViewModelTest.java | 28 +++++++++++ .../keybindings/KeyBindingViewModelTest.java | 46 +++++++++++++++++++ .../logic/shared/security/PasswordTest.java | 37 +++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 src/test/java/org/jabref/gui/documentviewer/PdfDocumentViewModelTest.java create mode 100644 src/test/java/org/jabref/gui/preferences/keybindings/KeyBindingViewModelTest.java create mode 100644 src/test/java/org/jabref/logic/shared/security/PasswordTest.java diff --git a/src/test/java/org/jabref/gui/documentviewer/PdfDocumentViewModelTest.java b/src/test/java/org/jabref/gui/documentviewer/PdfDocumentViewModelTest.java new file mode 100644 index 00000000000..91fcd8492d0 --- /dev/null +++ b/src/test/java/org/jabref/gui/documentviewer/PdfDocumentViewModelTest.java @@ -0,0 +1,28 @@ +package org.jabref.gui.documentviewer; + +import java.io.IOException; +import java.nio.file.Path; + +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDPage; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class PdfDocumentViewModelTest { + + @Test + void getPagesTest(@TempDir Path tempDir) throws IOException { + try (PDDocument mockPDF = new PDDocument()) { + Path pdfFile = tempDir.resolve("mockPDF.pdf"); + + mockPDF.addPage(new PDPage()); + mockPDF.save(pdfFile.toAbsolutePath().toString()); + + PdfDocumentViewModel PDFviewModel = new PdfDocumentViewModel(mockPDF); + + assertEquals(1, PDFviewModel.getPages().size()); + } + } +} diff --git a/src/test/java/org/jabref/gui/preferences/keybindings/KeyBindingViewModelTest.java b/src/test/java/org/jabref/gui/preferences/keybindings/KeyBindingViewModelTest.java new file mode 100644 index 00000000000..1d753aba0ad --- /dev/null +++ b/src/test/java/org/jabref/gui/preferences/keybindings/KeyBindingViewModelTest.java @@ -0,0 +1,46 @@ +package org.jabref.gui.preferences.keybindings; + +import java.util.Optional; + +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyEvent; + +import org.jabref.gui.DialogService; +import org.jabref.gui.keyboard.KeyBinding; +import org.jabref.gui.keyboard.KeyBindingRepository; +import org.jabref.preferences.PreferencesService; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; + +class KeyBindingViewModelTest { + + @Test + void resetToDefault() { + // Set new key binding + KeyBindingRepository keyBindingRepository = new KeyBindingRepository(); + KeyBindingsTabViewModel model = new KeyBindingsTabViewModel(keyBindingRepository, mock(DialogService.class), mock(PreferencesService.class)); + KeyBinding binding = KeyBinding.ABBREVIATE; + + KeyBindingViewModel viewModel = new KeyBindingViewModel(keyBindingRepository, binding, binding.getDefaultKeyBinding()); + model.selectedKeyBindingProperty().set(Optional.of(viewModel)); + + KeyEvent shortcutKeyEvent = new KeyEvent(KeyEvent.KEY_PRESSED, "F1", "F1", KeyCode.F1, true, false, false, + false); + + assertFalse(keyBindingRepository.checkKeyCombinationEquality(KeyBinding.ABBREVIATE, shortcutKeyEvent)); + + model.setNewBindingForCurrent(shortcutKeyEvent); + model.storeSettings(); + + assertTrue(keyBindingRepository.checkKeyCombinationEquality(KeyBinding.ABBREVIATE, shortcutKeyEvent)); + + // Reset to default + viewModel.resetToDefault(); + + assertFalse(keyBindingRepository.checkKeyCombinationEquality(KeyBinding.ABBREVIATE, shortcutKeyEvent)); + } +} diff --git a/src/test/java/org/jabref/logic/shared/security/PasswordTest.java b/src/test/java/org/jabref/logic/shared/security/PasswordTest.java new file mode 100644 index 00000000000..851c8e90632 --- /dev/null +++ b/src/test/java/org/jabref/logic/shared/security/PasswordTest.java @@ -0,0 +1,37 @@ +package org.jabref.logic.shared.security; + +import java.io.UnsupportedEncodingException; +import java.security.GeneralSecurityException; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +class PasswordTest { + + @Test + void passwordAESTest() throws GeneralSecurityException, UnsupportedEncodingException { + String phrase = "Password"; + + Password password = new Password(phrase, "someKey"); + + String encryptedPassword = password.encrypt(); + + assertNotEquals(phrase, encryptedPassword); + } + + @Test + void passwordAsCharTest() throws GeneralSecurityException, UnsupportedEncodingException { + char[] charPhrase = "Password".toCharArray(); + String stringPhrase = "Password"; + + Password charPassword = new Password(charPhrase, "someKey"); + Password stringPassword = new Password(stringPhrase, "someKey"); + + String charEncryptedPassword = charPassword.encrypt(); + String stringEncryptedPassword = stringPassword.encrypt(); + + assertEquals(charEncryptedPassword, stringEncryptedPassword); + } +} From de0c98bd0f5baac30bb0d951bbb6e85b24b1bfd0 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Fri, 18 Jun 2021 22:57:52 +0200 Subject: [PATCH 21/29] Fix indent --- src/test/java/org/jabref/gui/UpdateTimestampListenerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/jabref/gui/UpdateTimestampListenerTest.java b/src/test/java/org/jabref/gui/UpdateTimestampListenerTest.java index 93761db0d89..ec0b99431dc 100644 --- a/src/test/java/org/jabref/gui/UpdateTimestampListenerTest.java +++ b/src/test/java/org/jabref/gui/UpdateTimestampListenerTest.java @@ -27,7 +27,7 @@ class UpdateTimestampListenerTest { private final String baseDate = "2000-1-1"; private final String newDate = "2000-1-2"; - @BeforeEach + @BeforeEach void setUp() { database = new BibDatabase(); bibEntry = new BibEntry(); From 29db2be9aff466ab1b40de9932c053f41a00b824 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sun, 20 Jun 2021 08:20:45 +0200 Subject: [PATCH 22/29] Make SuggestionProvidersTest parameterized --- .../autocompleter/SuggestionProviders.java | 1 - .../SuggestionProvidersTest.java | 77 +++++++++++++------ .../casechanger/UpperCaseFormatterTest.java | 3 +- 3 files changed, 55 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/jabref/gui/autocompleter/SuggestionProviders.java b/src/main/java/org/jabref/gui/autocompleter/SuggestionProviders.java index 073cce6acda..3c47d6dd8e3 100644 --- a/src/main/java/org/jabref/gui/autocompleter/SuggestionProviders.java +++ b/src/main/java/org/jabref/gui/autocompleter/SuggestionProviders.java @@ -27,7 +27,6 @@ public SuggestionProviders() { } public SuggestionProvider getForField(Field field) { - if (isEmpty || !autoCompletePreferences.getCompleteFields().contains(field)) { return new EmptySuggestionProvider(); } diff --git a/src/test/java/org/jabref/gui/autocompleter/SuggestionProvidersTest.java b/src/test/java/org/jabref/gui/autocompleter/SuggestionProvidersTest.java index e6614a53ed9..bc968a825b2 100644 --- a/src/test/java/org/jabref/gui/autocompleter/SuggestionProvidersTest.java +++ b/src/test/java/org/jabref/gui/autocompleter/SuggestionProvidersTest.java @@ -1,41 +1,70 @@ package org.jabref.gui.autocompleter; +import java.util.Set; +import java.util.stream.Stream; + 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.BeforeEach; import org.junit.jupiter.api.Test; +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; 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(); - - 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()); - } + private SuggestionProviders suggestionProviders; + + @BeforeEach + public void initializeSuggestionProviders() { + BibDatabase database = new BibDatabase(); + JournalAbbreviationRepository abbreviationRepository = mock(JournalAbbreviationRepository.class); + Set completeFields = Set.of(StandardField.AUTHOR, StandardField.XREF, StandardField.XDATA, StandardField.JOURNAL, StandardField.PUBLISHER, SpecialField.PRINTED); + AutoCompletePreferences autoCompletePreferences = new AutoCompletePreferences( + true, + AutoCompleteFirstNameMode.BOTH, + AutoCompletePreferences.NameFormat.BOTH, + completeFields, + null); + this.suggestionProviders = new SuggestionProviders(database, abbreviationRepository, autoCompletePreferences); + } + + private static Stream getTestPairs() { + return Stream.of( + // a person + Arguments.of(org.jabref.gui.autocompleter.PersonNameSuggestionProvider.class, StandardField.AUTHOR), + + // a single entry field + Arguments.of(org.jabref.gui.autocompleter.BibEntrySuggestionProvider.class, StandardField.XREF), + + // multi entry fieldg + Arguments.of(org.jabref.gui.autocompleter.JournalsSuggestionProvider.class, StandardField.JOURNAL), + + // TODO: We should offer pre-configured publishers + Arguments.of(org.jabref.gui.autocompleter.JournalsSuggestionProvider.class, StandardField.PUBLISHER), + + // TODO: Auto completion should be aware of possible values of special fields + Arguments.of(org.jabref.gui.autocompleter.WordSuggestionProvider.class, SpecialField.PRINTED) + ); + } + + @ParameterizedTest + @MethodSource("getTestPairs") + public void testAppropriateCompleterReturned(Class> expected, Field field) { + assertEquals(expected, suggestionProviders.getForField(field).getClass()); + } + + @Test + void emptySuggestionProviderReturnedForEmptySuggestionProviderList() { + SuggestionProviders empty = new SuggestionProviders(); + assertEquals(EmptySuggestionProvider.class, empty.getForField(StandardField.AUTHOR).getClass()); + } } 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 339c43e122c..b997050305a 100644 --- a/src/test/java/org/jabref/logic/formatter/casechanger/UpperCaseFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/casechanger/UpperCaseFormatterTest.java @@ -2,6 +2,7 @@ import java.util.stream.Stream; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -17,7 +18,7 @@ public class UpperCaseFormatterTest { @ParameterizedTest @MethodSource("upperCaseTests") - public void upperCasetest(String expectedFormat, String inputFormat) { + public void upperCaseTest(String expectedFormat, String inputFormat) { assertEquals(expectedFormat, formatter.format(inputFormat)); } From ebeaa3cb0e4db06dd1d088a2a46c0bc8f792d38e Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sun, 20 Jun 2021 08:52:56 +0200 Subject: [PATCH 23/29] Adress review comments - Remove assertion failure messages - Fix List.of() - Fix variable name - convert to parameterized test - Fix checkstyle / indent - Revert some changes --- .../gui/groups/GroupTreeViewModelTest.java | 4 +- ...onsViewModelMixedAbbreviationsTabTest.java | 66 ++++++++++--------- .../keybindings/KeyBindingViewModelTest.java | 8 +-- .../logic/bibtex/FileFieldWriterTest.java | 24 +++++-- .../citationstyle/CitationStyleCacheTest.java | 6 +- .../casechanger/UpperCaseFormatterTest.java | 14 ++-- .../logic/importer/OpenDatabaseTest.java | 19 ++---- .../integrity/HTMLCharacterCheckerTest.java | 8 +-- .../logic/journals/AbbreviationTest.java | 6 -- .../jabref/logic/layout/LayoutEntryTest.java | 48 +++++++------- .../logic/shared/security/PasswordTest.java | 44 ++++++------- .../SpecialFieldsToSeparateFieldsTest.java | 47 ++++++------- 12 files changed, 139 insertions(+), 155 deletions(-) diff --git a/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java b/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java index a6611bca54d..a0febdc5089 100644 --- a/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java +++ b/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java @@ -40,7 +40,7 @@ void setUp() throws Exception { @Test void rootGroupIsAllEntriesByDefault() throws Exception { AllEntriesGroup allEntriesGroup = new AllEntriesGroup("All entries"); - assertEquals(new GroupNodeViewModel(databaseContext, stateManager, taskExecutor, allEntriesGroup, new CustomLocalDragboard(), mock(PreferencesService.class)), groupTree.rootGroupProperty().getValue(), "New group view model is not set to all entries by default."); + assertEquals(new GroupNodeViewModel(databaseContext, stateManager, taskExecutor, allEntriesGroup, new CustomLocalDragboard(), mock(PreferencesService.class)), groupTree.rootGroupProperty().getValue()); } @Test @@ -72,6 +72,6 @@ void keywordGroupsAreNotRemovedFromEntriesOnDelete() { model.addEntriesToGroup(databaseContext.getEntries()); groupTree.removeGroupsAndSubGroupsFromEntries(model); - assertEquals(groupName, entry.getField(StandardField.KEYWORDS).get(), "Keyword group was not removed from Bibentry."); + assertEquals(groupName, entry.getField(StandardField.KEYWORDS).get()); } } diff --git a/src/test/java/org/jabref/gui/journals/JournalAbbreviationsViewModelMixedAbbreviationsTabTest.java b/src/test/java/org/jabref/gui/journals/JournalAbbreviationsViewModelMixedAbbreviationsTabTest.java index 976e98c04e5..9c906027888 100644 --- a/src/test/java/org/jabref/gui/journals/JournalAbbreviationsViewModelMixedAbbreviationsTabTest.java +++ b/src/test/java/org/jabref/gui/journals/JournalAbbreviationsViewModelMixedAbbreviationsTabTest.java @@ -69,8 +69,8 @@ void setUpViewModel(@TempDir Path tempFolder) throws Exception { @Test void testInitialHasNoFilesAndNoAbbreviations() { - assertEquals(0, viewModel.journalFilesProperty().size(), "Incorrect setup of test. Journal files not set to 0 at setup."); - assertEquals(0, viewModel.abbreviationsProperty().size(), "Incorrect setup of test. Abbreviations not set to 0 at setup"); + assertEquals(0, viewModel.journalFilesProperty().size()); + assertEquals(0, viewModel.abbreviationsProperty().size()); } @Test @@ -96,8 +96,8 @@ void addFileIncreasesCounterOfOpenFilesAndHasNoAbbreviations() { when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(emptyTestFile)); viewModel.addNewFile(); - assertEquals(1, viewModel.journalFilesProperty().size(), "Incorrect amount of journal files in view model after adding empty test file."); - assertEquals(1, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations in view model after adding empty test file."); + assertEquals(1, viewModel.journalFilesProperty().size()); + assertEquals(1, viewModel.abbreviationsProperty().size()); } @Test @@ -136,10 +136,10 @@ void testOpenValidFileContainsTheSpecificEntryAndEnoughAbbreviations() { viewModel.addNewFile(); viewModel.selectLastJournalFile(); - assertEquals(1, viewModel.journalFilesProperty().size(), "Incorrect amount of journal files in view model after adding one journal."); + assertEquals(1, viewModel.journalFilesProperty().size()); // our test file has 3 abbreviations and one pseudo abbreviation - assertEquals(4, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations in view model after adding four entries."); - assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation)), "Test abbreviation was not correctly added to view model."); + assertEquals(4, viewModel.abbreviationsProperty().size()); + assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation))); } @Test @@ -148,10 +148,10 @@ void testRemoveLastListSetsCurrentFileAndCurrentAbbreviationToNull() { viewModel.addNewFile(); viewModel.removeCurrentFile(); - assertEquals(0, viewModel.journalFilesProperty().size(), "Incorrect amount of journal files in view model after adding and removing file."); - assertEquals(0, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations in view model after adding and removing file."); - assertNull(viewModel.currentFileProperty().get(), "Current file not removed correctly in view model."); - assertNull(viewModel.currentAbbreviationProperty().get(), "Current abbreviation not removed correctly in view model."); + assertEquals(0, viewModel.journalFilesProperty().size()); + assertEquals(0, viewModel.abbreviationsProperty().size()); + assertNull(viewModel.currentFileProperty().get()); + assertNull(viewModel.currentAbbreviationProperty().get()); } @Test @@ -167,11 +167,11 @@ void testMixedFileUsage() { viewModel.currentFileProperty().set(viewModel.journalFilesProperty().get(1)); // size of the list of journal files should be incremented by two - assertEquals(2, viewModel.journalFilesProperty().size(), "Incorrect amount of journal files after adding two files."); + assertEquals(2, viewModel.journalFilesProperty().size()); // our second test file has 4 abbreviations - assertEquals(5, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations after adding five entries."); + assertEquals(5, viewModel.abbreviationsProperty().size()); // check some abbreviation - assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation)), "Abbreviation 1 was not added correctly."); + assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation))); // simulate add new file button when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(emptyTestFile)); @@ -179,9 +179,9 @@ void testMixedFileUsage() { viewModel.currentFileProperty().set(viewModel.journalFilesProperty().get(2)); // size of the list of journal files should be incremented by one - assertEquals(3, viewModel.journalFilesProperty().size(), "Incorrect amount of journal files after adding three files"); + assertEquals(3, viewModel.journalFilesProperty().size()); // a new file has zero abbreviations - assertEquals(1, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations after adding one entry"); + assertEquals(1, viewModel.abbreviationsProperty().size()); // simulate open file button when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile5EntriesWithDuplicate)); @@ -189,11 +189,11 @@ void testMixedFileUsage() { viewModel.currentFileProperty().set(viewModel.journalFilesProperty().get(3)); // size of the list of journal files should be incremented by one - assertEquals(4, viewModel.journalFilesProperty().size(), "Incorrect amount of journal files after simulating open file button."); + assertEquals(4, viewModel.journalFilesProperty().size()); - assertEquals(5, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations after simulating open file button."); + assertEquals(5, viewModel.abbreviationsProperty().size()); // check some abbreviation - assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation2)), "Abbreviation 2 was not added correctly."); + assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation2))); } @Test @@ -227,19 +227,21 @@ void testCurrentFilePropertyChangeActiveFile() { AbbreviationsFileViewModel test5 = viewModel.journalFilesProperty().get(3); // test if the last opened file is active, but duplicated entry has been removed - assertEquals(5, viewModel.abbreviationsProperty().size(), "Last opened file is not active or duplicated entry was not removed."); + assertEquals(5, viewModel.abbreviationsProperty().size()); viewModel.currentFileProperty().set(test1); // test if the current abbreviations matches with the ones in testFile1Entries - assertEquals(2, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations after setting active testFile1."); + assertEquals(2, viewModel.abbreviationsProperty().size()); viewModel.currentFileProperty().set(test3); - assertEquals(4, viewModel.abbreviationsProperty().size(), "Incorrect amount of journals after setting active testFile3."); + assertEquals(4, viewModel.abbreviationsProperty().size()); + viewModel.currentFileProperty().set(test1); + assertEquals(2, viewModel.abbreviationsProperty().size()); viewModel.currentFileProperty().set(test4); - assertEquals(5, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations after setting active testFile4."); + assertEquals(5, viewModel.abbreviationsProperty().size()); viewModel.currentFileProperty().set(test5); - assertEquals(5, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations after setting active testFile5."); + assertEquals(5, viewModel.abbreviationsProperty().size()); } @Test @@ -252,8 +254,8 @@ void testAddAbbreviationIncludesAbbreviationsInAbbreviationList() { Abbreviation testAbbreviation = new Abbreviation("YetAnotherEntry", "YAE"); addAbbrevaition(testAbbreviation); - assertEquals(6, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations after setting active testFile5 and adding YAE entry."); - assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation)), "YAE abbreviation was not correctly added."); + assertEquals(6, viewModel.abbreviationsProperty().size()); + assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation))); } @Test @@ -289,16 +291,16 @@ void testEditAbbreviationIncludesNewAbbreviationInAbbreviationsList() { Abbreviation testAbbreviation = new Abbreviation("YetAnotherEntry", "YAE"); editAbbreviation(testAbbreviation); - assertEquals(5, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations after setting active testFile5 and adding YAE abbreviation."); - assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation)), "YAE abbreviation was not correctly added."); + assertEquals(5, viewModel.abbreviationsProperty().size()); + assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation))); when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(emptyTestFile)); viewModel.addNewFile(); viewModel.selectLastJournalFile(); editAbbreviation(testAbbreviation); - assertEquals(1, viewModel.abbreviationsProperty().size(), "Incorrect amount of abbreviations after setting active emptyTestFile and adding YAE abbreviation."); - assertFalse(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation)), "Test abbreviation YAE was not edited as expected."); + assertEquals(1, viewModel.abbreviationsProperty().size()); + assertFalse(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation))); } @Test @@ -357,9 +359,9 @@ void testDeleteAbbreviationSelectsPreviousOne() { viewModel.deleteAbbreviation(); - assertEquals(5, viewModel.abbreviationsProperty().size(), "Previously added abbreviation YAE was not deleted correctly."); + assertEquals(5, viewModel.abbreviationsProperty().size()); // check if the previous (the last) element is the current abbreviation - assertEquals(viewModel.currentAbbreviationProperty().get(), viewModel.abbreviationsProperty().get(4), "Last element of abbreviation list is not set to current abbreviation."); + assertEquals(viewModel.currentAbbreviationProperty().get(), viewModel.abbreviationsProperty().get(4)); } @Test diff --git a/src/test/java/org/jabref/gui/preferences/keybindings/KeyBindingViewModelTest.java b/src/test/java/org/jabref/gui/preferences/keybindings/KeyBindingViewModelTest.java index 1d753aba0ad..54371690bd7 100644 --- a/src/test/java/org/jabref/gui/preferences/keybindings/KeyBindingViewModelTest.java +++ b/src/test/java/org/jabref/gui/preferences/keybindings/KeyBindingViewModelTest.java @@ -22,19 +22,19 @@ class KeyBindingViewModelTest { void resetToDefault() { // Set new key binding KeyBindingRepository keyBindingRepository = new KeyBindingRepository(); - KeyBindingsTabViewModel model = new KeyBindingsTabViewModel(keyBindingRepository, mock(DialogService.class), mock(PreferencesService.class)); + KeyBindingsTabViewModel keyBindingsTabViewModel = new KeyBindingsTabViewModel(keyBindingRepository, mock(DialogService.class), mock(PreferencesService.class)); KeyBinding binding = KeyBinding.ABBREVIATE; KeyBindingViewModel viewModel = new KeyBindingViewModel(keyBindingRepository, binding, binding.getDefaultKeyBinding()); - model.selectedKeyBindingProperty().set(Optional.of(viewModel)); + keyBindingsTabViewModel.selectedKeyBindingProperty().set(Optional.of(viewModel)); KeyEvent shortcutKeyEvent = new KeyEvent(KeyEvent.KEY_PRESSED, "F1", "F1", KeyCode.F1, true, false, false, false); assertFalse(keyBindingRepository.checkKeyCombinationEquality(KeyBinding.ABBREVIATE, shortcutKeyEvent)); - model.setNewBindingForCurrent(shortcutKeyEvent); - model.storeSettings(); + keyBindingsTabViewModel.setNewBindingForCurrent(shortcutKeyEvent); + keyBindingsTabViewModel.storeSettings(); assertTrue(keyBindingRepository.checkKeyCombinationEquality(KeyBinding.ABBREVIATE, shortcutKeyEvent)); diff --git a/src/test/java/org/jabref/logic/bibtex/FileFieldWriterTest.java b/src/test/java/org/jabref/logic/bibtex/FileFieldWriterTest.java index 835ada7bc5c..f5f3a6efbf4 100644 --- a/src/test/java/org/jabref/logic/bibtex/FileFieldWriterTest.java +++ b/src/test/java/org/jabref/logic/bibtex/FileFieldWriterTest.java @@ -5,7 +5,10 @@ import org.jabref.model.entry.LinkedFile; 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; import static org.junit.jupiter.api.Assertions.assertNull; @@ -31,12 +34,19 @@ public void testQuoteNull() { assertNull(FileFieldWriter.quote(null)); } - @Test - public void testEncodeStringArray() { - assertEquals("a:b;c:d", FileFieldWriter.encodeStringArray(new String[][] {{"a", "b"}, {"c", "d"}}), "Encoding of stringArray failed."); - assertEquals("a:;c:d", FileFieldWriter.encodeStringArray(new String[][] {{"a", ""}, {"c", "d"}}), "Encoding of stringArray failed. Check empty string case."); - assertEquals("a:" + null + ";c:d", FileFieldWriter.encodeStringArray(new String[][] {{"a", null}, {"c", "d"}}), "Encoding of stringArray failed. Check null case."); - assertEquals("a:\\:b;c\\;:d", FileFieldWriter.encodeStringArray(new String[][] {{"a", ":b"}, {"c;", "d"}}), "Encoding of stringArray failed. Check escaped character case."); + private static Stream getEncodingTestData() { + return Stream.of( + Arguments.of("a:b;c:d", new String[][] {{"a", "b"}, {"c", "d"}}), + Arguments.of("a:;c:d", new String[][] {{"a", ""}, {"c", "d"}}), + Arguments.of("a:" + null + ";c:d", new String[][] {{"a", null}, {"c", "d"}}), + Arguments.of("a:\\:b;c\\;:d", new String[][] {{"a", ":b"}, {"c;", "d"}}) + ); + } + + @ParameterizedTest + @MethodSource("getEncodingTestData") + public void testEncodeStringArray(String expected, String[][] values) { + assertEquals(expected, FileFieldWriter.encodeStringArray(values)); } @Test diff --git a/src/test/java/org/jabref/logic/citationstyle/CitationStyleCacheTest.java b/src/test/java/org/jabref/logic/citationstyle/CitationStyleCacheTest.java index 51e67f8d382..44b770c5d25 100644 --- a/src/test/java/org/jabref/logic/citationstyle/CitationStyleCacheTest.java +++ b/src/test/java/org/jabref/logic/citationstyle/CitationStyleCacheTest.java @@ -21,10 +21,8 @@ class CitationStyleCacheTest { @Test void getCitationForTest() { - BibEntry bibEntry = new BibEntry(); - bibEntry.setCitationKey("test"); - List entries = new ArrayList<>(); - entries.add(0, bibEntry); + BibEntry bibEntry = new BibEntry().withCitationKey("test"); + List entries = List.of(bibEntry); BibDatabase database = new BibDatabase(entries); BibDatabaseContext databaseContext = new BibDatabaseContext(database); CitationStyleCache csCache = new CitationStyleCache(databaseContext); 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 b997050305a..c1397603348 100644 --- a/src/test/java/org/jabref/logic/formatter/casechanger/UpperCaseFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/casechanger/UpperCaseFormatterTest.java @@ -24,13 +24,13 @@ public void upperCaseTest(String expectedFormat, String inputFormat) { 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("!", "!") + 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/importer/OpenDatabaseTest.java b/src/test/java/org/jabref/logic/importer/OpenDatabaseTest.java index 25b13ad72c2..22e2cba90bf 100644 --- a/src/test/java/org/jabref/logic/importer/OpenDatabaseTest.java +++ b/src/test/java/org/jabref/logic/importer/OpenDatabaseTest.java @@ -1,6 +1,7 @@ package org.jabref.logic.importer; import java.io.IOException; +import java.net.URISyntaxException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Path; @@ -19,7 +20,6 @@ import org.mockito.Answers; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -28,24 +28,19 @@ class OpenDatabaseTest { private final Charset defaultEncoding = StandardCharsets.UTF_8; private ImportFormatPreferences importFormatPreferences; private TimestampPreferences timestampPreferences; - private Path bibNoHeader = null; - private Path bibWrongHeader = null; - private Path bibHeader = null; - private Path bibHeaderAndSignature = null; - private Path bibEncodingWithoutNewline = null; + private final Path bibNoHeader; + private final Path bibWrongHeader; + private final Path bibHeader; + private final Path bibHeaderAndSignature; + private final Path bibEncodingWithoutNewline; private final FileUpdateMonitor fileMonitor = new DummyFileUpdateMonitor(); - OpenDatabaseTest() { - try { + OpenDatabaseTest() throws URISyntaxException { bibNoHeader = Path.of(OpenDatabaseTest.class.getResource("headerless.bib").toURI()); bibWrongHeader = Path.of(OpenDatabaseTest.class.getResource("wrong-header.bib").toURI()); bibHeader = Path.of(OpenDatabaseTest.class.getResource("encoding-header.bib").toURI()); bibHeaderAndSignature = Path.of(OpenDatabaseTest.class.getResource("jabref-header.bib").toURI()); bibEncodingWithoutNewline = Path.of(OpenDatabaseTest.class.getResource("encodingWithoutNewline.bib").toURI()); - } catch (Exception e) { - // Ignore Tests if utility files could not be located - assumeTrue(false); - } } @BeforeEach diff --git a/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java b/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java index 35b92e744d7..3a08d49af93 100644 --- a/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java @@ -17,11 +17,10 @@ public class HTMLCharacterCheckerTest { private final BibEntry entry = new BibEntry(); @Test - void fieldNullValueCheck() { - Exception exception = assertThrows( + void testSettingNullThrowsNPE() { + assertThrows( NullPointerException.class, - () -> entry.setField(StandardField.AUTHOR, null), - "field value must not be null" + () -> entry.setField(StandardField.AUTHOR, null) ); } @@ -60,5 +59,4 @@ void journalDoesNotAcceptHTMLEncodedCharacters() { entry.setField(StandardField.JOURNAL, "Ärling Ström for – ‱"); assertEquals(List.of(new IntegrityMessage("HTML encoded character found", entry, StandardField.JOURNAL)), checker.check(entry)); } - } diff --git a/src/test/java/org/jabref/logic/journals/AbbreviationTest.java b/src/test/java/org/jabref/logic/journals/AbbreviationTest.java index 92043e5f124..ea7532bf8ee 100644 --- a/src/test/java/org/jabref/logic/journals/AbbreviationTest.java +++ b/src/test/java/org/jabref/logic/journals/AbbreviationTest.java @@ -104,12 +104,6 @@ void testDefaultAndShortestUniqueAbbreviationsAreSame() { assertEquals(abbreviation.getAbbreviation(), abbreviation.getShortestUniqueAbbreviation()); } - @Test - void testToString() { - Abbreviation abbreviation = new Abbreviation("Long Name", "L N", "LN"); - assertEquals(abbreviation.toString(), "Abbreviation{name=Long Name, abbreviation=L N, medlineAbbreviation=L N, shortestUniqueAbbreviation=LN}"); - } - @Test void testEquals() { Abbreviation abbreviation = new Abbreviation("Long Name", "L N", "LN"); diff --git a/src/test/java/org/jabref/logic/layout/LayoutEntryTest.java b/src/test/java/org/jabref/logic/layout/LayoutEntryTest.java index 1b142219c85..53a4ff0bf34 100644 --- a/src/test/java/org/jabref/logic/layout/LayoutEntryTest.java +++ b/src/test/java/org/jabref/logic/layout/LayoutEntryTest.java @@ -70,29 +70,29 @@ public String layout(String layoutFile, BibEntry entry) throws IOException { @Test public void testParseMethodCalls() { - assertEquals(1, LayoutEntry.parseMethodsCalls("bla").size(), "Parsing of layout entry method calls failed."); - assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla").get(0)).get(0), "Parsing of layout entry method calls failed. Input did not match expected output."); - - assertEquals(1, LayoutEntry.parseMethodsCalls("bla,").size(), "Parsing of layout entry method calls failed. Check for comma behaviour."); - assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla,").get(0)).get(0), "Parsing of layout entry method calls failed. Input did not match expected output."); - - assertEquals(1, LayoutEntry.parseMethodsCalls("_bla.bla.blub,").size(), "Parsing of layout entry method calls failed. Check for special characters."); - assertEquals("_bla.bla.blub", (LayoutEntry.parseMethodsCalls("_bla.bla.blub,").get(0)).get(0), "Parsing of layout entry method calls failed. Input did not match expected output. Check for comma behaviour."); - - assertEquals(2, LayoutEntry.parseMethodsCalls("bla,foo").size(), "Parsing of layout entry method calls failed. Not all arguments were parsed correctly."); - assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla,foo").get(0)).get(0), "Parsing of layout entry method calls failed. Input did not match expected output. Method calls not separated as expected."); - assertEquals("foo", (LayoutEntry.parseMethodsCalls("bla,foo").get(1)).get(0), "Parsing of layout entry method calls failed. Input did not match expected output. Method calls not separated as expected."); - - assertEquals(2, LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").size(), "Parsing of layout entry method calls failed. Check for escaped characters behaviour."); - assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(0)).get(0), "Parsing of layout entry method calls failed. Input did not match expected output. Check for multiple method calls with escaped characters."); - assertEquals("foo", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(1)).get(0), "Parsing of layout entry method calls failed. Input did not match expected output. Check for multiple method calls with escaped characters."); - assertEquals("test", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(0)).get(1), "Parsing of layout entry method calls failed. Input did not match expected output. Check for multiple method calls with escaped characters."); - assertEquals("fark", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(1)).get(1), "Parsing of layout entry method calls failed. Input did not match expected output. Check for multiple method calls with escaped characters."); - - assertEquals(2, LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").size(), "Parsing of layout method calls failed. Check for arguments in parentheses."); - assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(0)).get(0), "Parsing of layout method calls failed. Input did not match expected output. Check for arguments in parentheses."); - assertEquals("foo", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(1)).get(0), "Parsing of layout method calls failed. Input did not match expected output. Check for arguments in parentheses"); - assertEquals("test", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(0)).get(1), "Parsing of layout method calls failed. Input did not match expected output. Check for arguments in parentheses"); - assertEquals("fark", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(1)).get(1), "Parsing of layout method calls failed. Input did not match expected output. Check for arguments in parentheses"); + assertEquals(1, LayoutEntry.parseMethodsCalls("bla").size()); + assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla").get(0)).get(0)); + + assertEquals(1, LayoutEntry.parseMethodsCalls("bla,").size()); + assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla,").get(0)).get(0)); + + assertEquals(1, LayoutEntry.parseMethodsCalls("_bla.bla.blub,").size()); + assertEquals("_bla.bla.blub", (LayoutEntry.parseMethodsCalls("_bla.bla.blub,").get(0)).get(0)); + + assertEquals(2, LayoutEntry.parseMethodsCalls("bla,foo").size()); + assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla,foo").get(0)).get(0)); + assertEquals("foo", (LayoutEntry.parseMethodsCalls("bla,foo").get(1)).get(0)); + + assertEquals(2, LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").size()); + assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(0)).get(0)); + assertEquals("foo", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(1)).get(0)); + assertEquals("test", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(0)).get(1)); + assertEquals("fark", (LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(1)).get(1)); + + assertEquals(2, LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").size()); + assertEquals("bla", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(0)).get(0)); + assertEquals("foo", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(1)).get(0)); + assertEquals("test", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(0)).get(1)); + assertEquals("fark", (LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(1)).get(1)); } } diff --git a/src/test/java/org/jabref/logic/shared/security/PasswordTest.java b/src/test/java/org/jabref/logic/shared/security/PasswordTest.java index 851c8e90632..d315d0d1e88 100644 --- a/src/test/java/org/jabref/logic/shared/security/PasswordTest.java +++ b/src/test/java/org/jabref/logic/shared/security/PasswordTest.java @@ -10,28 +10,24 @@ class PasswordTest { - @Test - void passwordAESTest() throws GeneralSecurityException, UnsupportedEncodingException { - String phrase = "Password"; - - Password password = new Password(phrase, "someKey"); - - String encryptedPassword = password.encrypt(); - - assertNotEquals(phrase, encryptedPassword); - } - - @Test - void passwordAsCharTest() throws GeneralSecurityException, UnsupportedEncodingException { - char[] charPhrase = "Password".toCharArray(); - String stringPhrase = "Password"; - - Password charPassword = new Password(charPhrase, "someKey"); - Password stringPassword = new Password(stringPhrase, "someKey"); - - String charEncryptedPassword = charPassword.encrypt(); - String stringEncryptedPassword = stringPassword.encrypt(); - - assertEquals(charEncryptedPassword, stringEncryptedPassword); - } + @Test + void passwordAESTest() throws GeneralSecurityException, UnsupportedEncodingException { + String phrase = "Password"; + Password password = new Password(phrase, "someKey"); + String encryptedPassword = password.encrypt(); + assertNotEquals(phrase, encryptedPassword); + } + + @Test + void passwordAsCharTest() throws GeneralSecurityException, UnsupportedEncodingException { + char[] charPhrase = "Password".toCharArray(); + Password charPassword = new Password(charPhrase, "someKey"); + String charEncryptedPassword = charPassword.encrypt(); + + String stringPhrase = "Password"; + Password stringPassword = new Password(stringPhrase, "someKey"); + String stringEncryptedPassword = stringPassword.encrypt(); + + assertEquals(charEncryptedPassword, stringEncryptedPassword); + } } diff --git a/src/test/java/org/jabref/migrations/SpecialFieldsToSeparateFieldsTest.java b/src/test/java/org/jabref/migrations/SpecialFieldsToSeparateFieldsTest.java index cbee10c9414..b1f64b2ca99 100644 --- a/src/test/java/org/jabref/migrations/SpecialFieldsToSeparateFieldsTest.java +++ b/src/test/java/org/jabref/migrations/SpecialFieldsToSeparateFieldsTest.java @@ -8,7 +8,6 @@ import org.jabref.model.entry.field.SpecialField; import org.jabref.model.entry.field.StandardField; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -18,19 +17,10 @@ class SpecialFieldsToSeparateFieldsTest { - private BibEntry entry; - private BibEntry expectedEntry; - - @BeforeEach - void setUp() { - entry = new BibEntry(); - expectedEntry = new BibEntry(); - } - @ParameterizedTest @MethodSource("provideKeywordFieldPairs") public void migrateToCorrectField(SpecialField field, String fieldInKeyword, BibEntry expected) { - entry = new BibEntry().withField(StandardField.KEYWORDS, fieldInKeyword); + BibEntry entry = new BibEntry().withField(StandardField.KEYWORDS, fieldInKeyword); new SpecialFieldsToSeparateFields(',').performMigration(new ParserResult(List.of(entry))); @@ -39,40 +29,41 @@ public void migrateToCorrectField(SpecialField field, String fieldInKeyword, Bib @Test public void noKewordToMigrate() { - entry.setField(StandardField.AUTHOR, "JabRef"); - entry.setField(StandardField.KEYWORDS, "tdd"); - expectedEntry.setField(StandardField.AUTHOR, "JabRef"); - expectedEntry.setField(StandardField.KEYWORDS, "tdd"); + BibEntry entry = new BibEntry().withField(StandardField.AUTHOR, "JabRef") + .withField(StandardField.KEYWORDS, "tdd"); + BibEntry expected = new BibEntry().withField(StandardField.AUTHOR, "JabRef") + .withField(StandardField.KEYWORDS, "tdd"); new SpecialFieldsToSeparateFields(',').performMigration(new ParserResult(List.of(entry))); - assertEquals(expectedEntry, entry); + assertEquals(expected, entry); } @Test public void migrateMultipleSpecialFields() { - entry.setField(StandardField.AUTHOR, "JabRef"); - entry.setField(StandardField.KEYWORDS, "printed, prio1"); - expectedEntry.setField(StandardField.AUTHOR, "JabRef"); - expectedEntry.setField(SpecialField.PRINTED, "printed"); - expectedEntry.setField(SpecialField.PRIORITY, "prio1"); + BibEntry entry = new BibEntry().withField(StandardField.AUTHOR, "JabRef") + .withField(StandardField.KEYWORDS, "printed, prio1"); + BibEntry expected = new BibEntry().withField(StandardField.AUTHOR, "JabRef") + .withField(SpecialField.PRINTED, "printed") + .withField(SpecialField.PRIORITY, "prio1"); new SpecialFieldsToSeparateFields(',').performMigration(new ParserResult(List.of(entry))); - assertEquals(expectedEntry, entry); + assertEquals(expected, entry); } @Test public void migrateSpecialFieldsMixedWithKeyword() { - entry.setField(StandardField.AUTHOR, "JabRef"); - entry.setField(StandardField.KEYWORDS, "tdd, prio1, SE"); - expectedEntry.setField(StandardField.AUTHOR, "JabRef"); - expectedEntry.setField(StandardField.KEYWORDS, "tdd, SE"); - expectedEntry.setField(SpecialField.PRIORITY, "prio1"); + BibEntry entry = new BibEntry().withField(StandardField.AUTHOR, "JabRef") + .withField(StandardField.KEYWORDS, "tdd, prio1, SE"); + + BibEntry expected = new BibEntry().withField(StandardField.AUTHOR, "JabRef") + .withField(StandardField.KEYWORDS, "tdd, SE") + .withField(SpecialField.PRIORITY, "prio1"); new SpecialFieldsToSeparateFields(',').performMigration(new ParserResult(List.of(entry))); - assertEquals(expectedEntry, entry); + assertEquals(expected, entry); } private static Stream provideKeywordFieldPairs() { From 30c9276339e5d48a7b16c149f91679fad4a6cc99 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sun, 20 Jun 2021 13:32:38 +0200 Subject: [PATCH 24/29] Rewrite FieldChangeTest --- .../java/org/jabref/model/FieldChange.java | 4 +- .../org/jabref/model/FieldChangeTest.java | 94 +++++++++---------- 2 files changed, 45 insertions(+), 53 deletions(-) diff --git a/src/main/java/org/jabref/model/FieldChange.java b/src/main/java/org/jabref/model/FieldChange.java index 226cefe6926..74d4416ce39 100644 --- a/src/main/java/org/jabref/model/FieldChange.java +++ b/src/main/java/org/jabref/model/FieldChange.java @@ -16,8 +16,8 @@ public class FieldChange { private final String newValue; public FieldChange(BibEntry entry, Field field, String oldValue, String newValue) { - this.entry = entry; - this.field = field; + this.entry = Objects.requireNonNull(entry); + this.field = Objects.requireNonNull(field); this.oldValue = oldValue; this.newValue = newValue; } diff --git a/src/test/java/org/jabref/model/FieldChangeTest.java b/src/test/java/org/jabref/model/FieldChangeTest.java index 07dbb2a9287..8d0aff7e98f 100644 --- a/src/test/java/org/jabref/model/FieldChangeTest.java +++ b/src/test/java/org/jabref/model/FieldChangeTest.java @@ -1,63 +1,55 @@ package org.jabref.model; import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.StandardField; 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; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; class FieldChangeTest { - private FieldChange Fieldchange; - - @Test - void testHashCode() { - FieldChange fcNull = new FieldChange(null, null, null, null); - assertEquals(923521, fcNull.hashCode()); - } - - @Test - void testEquals() { - BibEntry entry = new BibEntry(); - BibEntry entryOther = new BibEntry(); - final Field field = StandardField.DOI; - final Field fieldOther = StandardField.DOI; - entry.setField(StandardField.DOI, "foo"); - final String oldValue = "foo"; - final String newValue = "bar"; - final String oldValueOther = "fooX"; - final String newValueOther = "barX"; - - FieldChange fc = new FieldChange(entry, field, oldValue, newValue); - FieldChange fcOther = new FieldChange(entryOther, fieldOther, oldValueOther, newValueOther); - FieldChange fcBlankAll = new FieldChange(null, null, null, null); - FieldChange fcBlankField = new FieldChange(entry, null, oldValue, newValue); - FieldChange fcBlankOldValue = new FieldChange(entry, field, null, newValue); - FieldChange fcBlankNewValue = new FieldChange(entry, field, oldValue, null); - - assertFalse(fc.equals("foo")); - assertTrue(fc.equals(fc)); - assertFalse(fcBlankAll.equals(fc)); - assertFalse(fc.equals(fcOther)); - assertFalse(fcBlankField.equals(fc)); - assertFalse(fcBlankOldValue.equals(fc)); - assertFalse(fcBlankNewValue.equals(fc)); - assertTrue(fcBlankAll.equals(fcBlankAll)); - } - - @Test - void testToString() { - BibEntry entry = new BibEntry(); - Field field = StandardField.DOI; - entry.setCitationKey("CitationKey"); - final String oldValue = "Old"; - final String newValue = "New"; - - FieldChange fc = new FieldChange(entry, field, oldValue, newValue); - assertEquals("FieldChange [entry=CitationKey, field=DOI, oldValue=Old, newValue=New]", fc.toString()); - } + private BibEntry entry = new BibEntry() + .withField(StandardField.DOI, "foo"); + private BibEntry entryOther = new BibEntry(); + private FieldChange fc = new FieldChange(entry, StandardField.DOI, "foo", "bar"); + + @Test + void fieldChangeOnNullEntryNotAllowed() { + assertThrows(NullPointerException.class, () -> new FieldChange(null, StandardField.DOI, "foo", "bar")); + } + + @Test + void fieldChangeOnNullFieldNotAllowed() { + assertThrows(NullPointerException.class, () -> new FieldChange(entry, null, "foo", "bar")); + } + + @Test + void blankFieldChangeNotAllowed() { + assertThrows(NullPointerException.class, () -> new FieldChange(null, null, null, null)); + } + + @Test + void equalFieldChange() { + FieldChange fcBlankNewValue = new FieldChange(entry, StandardField.DOI, "foo", null); + assertNotEquals(fc, fcBlankNewValue); + } + + @Test + void fieldChangeDoesNotEqualString() { + assertNotEquals(fc, "foo"); + } + + @Test + void fieldChangeEqualsItSelf() { + assertEquals(fc, fc); + } + + @Test + void differentFieldChangeIsNotEqual() { + FieldChange fcOther = new FieldChange(entryOther, StandardField.DOI, "fooX", "barX"); + assertEquals(fc, fcOther); + } } From 3de65c5537b810ada43be60255d7ec56db365abb Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sun, 20 Jun 2021 14:50:24 +0200 Subject: [PATCH 25/29] Remove obsolete variable --- .../java/org/jabref/model/entry/EntryLinkListTest.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/jabref/model/entry/EntryLinkListTest.java b/src/test/java/org/jabref/model/entry/EntryLinkListTest.java index c360719d452..46f34989c7f 100644 --- a/src/test/java/org/jabref/model/entry/EntryLinkListTest.java +++ b/src/test/java/org/jabref/model/entry/EntryLinkListTest.java @@ -22,7 +22,6 @@ public class EntryLinkListTest { private ParsedEntryLink link; private BibEntry source; private BibEntry target; - private BibEntry entry; @BeforeEach public void before() { @@ -31,12 +30,11 @@ public void before() { link = links.get(0); source = create("source"); target = create("target"); - entry = create("entry"); } private BibEntry create(String citeKey) { - BibEntry entry = new BibEntry(); - entry.setCitationKey(citeKey); + BibEntry entry = new BibEntry() + .withCitationKey(citeKey); database.insertEntry(entry); return entry; } @@ -64,7 +62,7 @@ public void givenFieldValueAndDatabaseWhenParsingThenExpectLink() { @Test public void givenBibEntryWhenParsingThenExpectLink() { - ParsedEntryLink expected = new ParsedEntryLink(entry); + ParsedEntryLink expected = new ParsedEntryLink(new BibEntry().withCitationKey("key")); assertFalse(expected.getLinkedEntry().isEmpty()); } From 281ccca97c1ed39406e84dbbf2d80b5ba2e4c510 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sun, 20 Jun 2021 14:50:39 +0200 Subject: [PATCH 26/29] Rewrite SentenceAnalyzerTest to ParamterizedTest --- .../search/rules/SentenceAnalyzerTest.java | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/test/java/org/jabref/model/search/rules/SentenceAnalyzerTest.java b/src/test/java/org/jabref/model/search/rules/SentenceAnalyzerTest.java index b425639e9a0..61e05e3def4 100644 --- a/src/test/java/org/jabref/model/search/rules/SentenceAnalyzerTest.java +++ b/src/test/java/org/jabref/model/search/rules/SentenceAnalyzerTest.java @@ -1,19 +1,34 @@ package org.jabref.model.search.rules; -import java.util.Arrays; -import java.util.Collections; +import java.util.List; +import java.util.stream.Stream; -import org.junit.jupiter.api.Test; +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; public class SentenceAnalyzerTest { - @Test - public void testGetWords() { - assertEquals(Arrays.asList("a", "b"), new SentenceAnalyzer("a b").getWords(), "Sentence was not parsed correctly."); - assertEquals(Arrays.asList("a", "b"), new SentenceAnalyzer(" a b ").getWords(), "Sentence was not parsed correctly. Check leading and trailing spaces."); - assertEquals(Collections.singletonList("b "), new SentenceAnalyzer("\"b \" ").getWords(), "Sentence was not parsed correctly. Check escaped characters and trailing spaces."); - assertEquals(Collections.singletonList(" a"), new SentenceAnalyzer(" \\ a").getWords(), "Sentence was not parsed correctly. Check escaped characters and leading spaces."); + static Stream getParameters() { + return Stream.of( + Arguments.of(List.of("a", "b"), "a b"), + + // Leading and trailing spaces + Arguments.of(List.of("a", "b"), " a b "), + + // Escaped characters and trailing spaces + Arguments.of(List.of("b "), "\"b \" "), + + // Escaped characters and leading spaces. + Arguments.of(List.of(" a"), " \\ a") + ); + } + + @ParameterizedTest + @MethodSource("getParameters") + public void testGetWords(List expected, String input) { + assertEquals(expected, new SentenceAnalyzer(input).getWords()); } } From 2b5cd88fcc4fd35604f646234048912aabfa4f29 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sun, 20 Jun 2021 15:01:54 +0200 Subject: [PATCH 27/29] Remove assert messages --- .../java/org/jabref/gui/groups/GroupTreeViewModelTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java b/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java index a0febdc5089..f90c5fdf360 100644 --- a/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java +++ b/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java @@ -45,7 +45,7 @@ void rootGroupIsAllEntriesByDefault() throws Exception { @Test void rootGroupIsSelectedByDefault() { - assertEquals(groupTree.rootGroupProperty().get().getGroupNode(), stateManager.getSelectedGroup(databaseContext).get(0), "Root group not selected by default."); + assertEquals(groupTree.rootGroupProperty().get().getGroupNode(), stateManager.getSelectedGroup(databaseContext).get(0)); } @Test @@ -58,7 +58,7 @@ void explicitGroupsAreRemovedFromEntriesOnDelete() { model.addEntriesToGroup(databaseContext.getEntries()); groupTree.removeGroupsAndSubGroupsFromEntries(model); - assertEquals(Optional.empty(), entry.getField(StandardField.GROUPS), "Explicit group was not removed from BibEntry."); + assertEquals(Optional.empty(), entry.getField(StandardField.GROUPS)); } @Test From c1888d3b5580ca686844e08b1dca8e519dec4f1a Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sun, 20 Jun 2021 15:10:23 +0200 Subject: [PATCH 28/29] Fix checkstyle --- src/test/java/org/jabref/logic/bibtex/FileFieldWriterTest.java | 3 ++- .../org/jabref/logic/citationstyle/CitationStyleCacheTest.java | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/jabref/logic/bibtex/FileFieldWriterTest.java b/src/test/java/org/jabref/logic/bibtex/FileFieldWriterTest.java index f5f3a6efbf4..ef0dd2bf5ec 100644 --- a/src/test/java/org/jabref/logic/bibtex/FileFieldWriterTest.java +++ b/src/test/java/org/jabref/logic/bibtex/FileFieldWriterTest.java @@ -1,14 +1,15 @@ package org.jabref.logic.bibtex; import java.nio.file.Path; +import java.util.stream.Stream; import org.jabref.model.entry.LinkedFile; 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; import static org.junit.jupiter.api.Assertions.assertNull; diff --git a/src/test/java/org/jabref/logic/citationstyle/CitationStyleCacheTest.java b/src/test/java/org/jabref/logic/citationstyle/CitationStyleCacheTest.java index 44b770c5d25..faff4fe5f48 100644 --- a/src/test/java/org/jabref/logic/citationstyle/CitationStyleCacheTest.java +++ b/src/test/java/org/jabref/logic/citationstyle/CitationStyleCacheTest.java @@ -1,6 +1,5 @@ package org.jabref.logic.citationstyle; -import java.util.ArrayList; import java.util.List; import org.jabref.model.database.BibDatabase; From 7550426a1a95ca386eab6d799f901e65fca7ab50 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Mon, 21 Jun 2021 22:42:19 +0200 Subject: [PATCH 29/29] Fix assertion --- src/test/java/org/jabref/model/FieldChangeTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/jabref/model/FieldChangeTest.java b/src/test/java/org/jabref/model/FieldChangeTest.java index 8d0aff7e98f..ec2c8300217 100644 --- a/src/test/java/org/jabref/model/FieldChangeTest.java +++ b/src/test/java/org/jabref/model/FieldChangeTest.java @@ -50,6 +50,6 @@ void fieldChangeEqualsItSelf() { @Test void differentFieldChangeIsNotEqual() { FieldChange fcOther = new FieldChange(entryOther, StandardField.DOI, "fooX", "barX"); - assertEquals(fc, fcOther); + assertNotEquals(fc, fcOther); } }