diff --git a/src/test/java/org/jabref/logic/bibtex/comparator/FieldComparatorTest.java b/src/test/java/org/jabref/logic/bibtex/comparator/FieldComparatorTest.java index 706e4f04427..59c9d116132 100644 --- a/src/test/java/org/jabref/logic/bibtex/comparator/FieldComparatorTest.java +++ b/src/test/java/org/jabref/logic/bibtex/comparator/FieldComparatorTest.java @@ -1,5 +1,7 @@ package org.jabref.logic.bibtex.comparator; +import java.util.stream.Stream; + import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.InternalField; import org.jabref.model.entry.field.OrFields; @@ -7,6 +9,9 @@ import org.jabref.model.entry.types.StandardEntryType; 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; @@ -14,8 +19,8 @@ public class FieldComparatorTest { @Test public void compareMonthFieldIdentity() throws Exception { FieldComparator comparator = new FieldComparator(StandardField.MONTH); - BibEntry equal = new BibEntry(); - equal.setField(StandardField.MONTH, "1"); + BibEntry equal = new BibEntry() + .withField(StandardField.MONTH, "1"); assertEquals(0, comparator.compare(equal, equal)); } @@ -23,10 +28,10 @@ public void compareMonthFieldIdentity() throws Exception { @Test public void compareMonthFieldEquality() throws Exception { FieldComparator comparator = new FieldComparator(StandardField.MONTH); - BibEntry equal = new BibEntry(); - equal.setField(StandardField.MONTH, "1"); - BibEntry equal2 = new BibEntry(); - equal2.setField(StandardField.MONTH, "1"); + BibEntry equal = new BibEntry() + .withField(StandardField.MONTH, "1"); + BibEntry equal2 = new BibEntry() + .withField(StandardField.MONTH, "1"); assertEquals(0, comparator.compare(equal, equal2)); } @@ -34,10 +39,10 @@ public void compareMonthFieldEquality() throws Exception { @Test public void compareMonthFieldBiggerAscending() throws Exception { FieldComparator comparator = new FieldComparator(StandardField.MONTH); - BibEntry smaller = new BibEntry(); - smaller.setField(StandardField.MONTH, "jan"); - BibEntry bigger = new BibEntry(); - bigger.setField(StandardField.MONTH, "feb"); + BibEntry smaller = new BibEntry() + .withField(StandardField.MONTH, "jan"); + BibEntry bigger = new BibEntry() + .withField(StandardField.MONTH, "feb"); assertEquals(1, comparator.compare(bigger, smaller)); } @@ -45,10 +50,10 @@ public void compareMonthFieldBiggerAscending() throws Exception { @Test public void compareMonthFieldBiggerDescending() throws Exception { FieldComparator comparator = new FieldComparator(new OrFields(StandardField.MONTH), true); - BibEntry smaller = new BibEntry(); - smaller.setField(StandardField.MONTH, "feb"); - BibEntry bigger = new BibEntry(); - bigger.setField(StandardField.MONTH, "jan"); + BibEntry smaller = new BibEntry() + .withField(StandardField.MONTH, "feb"); + BibEntry bigger = new BibEntry() + .withField(StandardField.MONTH, "jan"); assertEquals(1, comparator.compare(bigger, smaller)); } @@ -56,8 +61,8 @@ public void compareMonthFieldBiggerDescending() throws Exception { @Test public void compareYearFieldIdentity() throws Exception { FieldComparator comparator = new FieldComparator(StandardField.YEAR); - BibEntry equal = new BibEntry(); - equal.setField(StandardField.YEAR, "2016"); + BibEntry equal = new BibEntry() + .withField(StandardField.YEAR, "2016"); assertEquals(0, comparator.compare(equal, equal)); } @@ -65,10 +70,10 @@ public void compareYearFieldIdentity() throws Exception { @Test public void compareYearFieldEquality() throws Exception { FieldComparator comparator = new FieldComparator(StandardField.YEAR); - BibEntry equal = new BibEntry(); - equal.setField(StandardField.YEAR, "2016"); - BibEntry equal2 = new BibEntry(); - equal2.setField(StandardField.YEAR, "2016"); + BibEntry equal = new BibEntry() + .withField(StandardField.YEAR, "2016"); + BibEntry equal2 = new BibEntry() + .withField(StandardField.YEAR, "2016"); assertEquals(0, comparator.compare(equal, equal2)); } @@ -76,10 +81,10 @@ public void compareYearFieldEquality() throws Exception { @Test public void compareYearFieldBiggerAscending() throws Exception { FieldComparator comparator = new FieldComparator(StandardField.YEAR); - BibEntry smaller = new BibEntry(); - smaller.setField(StandardField.YEAR, "2000"); - BibEntry bigger = new BibEntry(); - bigger.setField(StandardField.YEAR, "2016"); + BibEntry smaller = new BibEntry() + .withField(StandardField.YEAR, "2000"); + BibEntry bigger = new BibEntry() + .withField(StandardField.YEAR, "2016"); assertEquals(1, comparator.compare(bigger, smaller)); } @@ -87,10 +92,10 @@ public void compareYearFieldBiggerAscending() throws Exception { @Test public void compareYearFieldBiggerDescending() throws Exception { FieldComparator comparator = new FieldComparator(new OrFields(StandardField.YEAR), true); - BibEntry smaller = new BibEntry(); - smaller.setField(StandardField.YEAR, "2016"); - BibEntry bigger = new BibEntry(); - bigger.setField(StandardField.YEAR, "2000"); + BibEntry smaller = new BibEntry() + .withField(StandardField.YEAR, "2016"); + BibEntry bigger = new BibEntry() + .withField(StandardField.YEAR, "2000"); assertEquals(1, comparator.compare(bigger, smaller)); } @@ -135,8 +140,8 @@ public void compareTypeFieldBiggerDescending() throws Exception { @Test public void compareStringFieldsIdentity() throws Exception { FieldComparator comparator = new FieldComparator(StandardField.TITLE); - BibEntry equal = new BibEntry(); - equal.setField(StandardField.TITLE, "title"); + BibEntry equal = new BibEntry() + .withField(StandardField.TITLE, "title"); assertEquals(0, comparator.compare(equal, equal)); } @@ -144,10 +149,10 @@ public void compareStringFieldsIdentity() throws Exception { @Test public void compareStringFieldsEquality() throws Exception { FieldComparator comparator = new FieldComparator(StandardField.TITLE); - BibEntry equal = new BibEntry(); - equal.setField(StandardField.TITLE, "title"); - BibEntry equal2 = new BibEntry(); - equal2.setField(StandardField.TITLE, "title"); + BibEntry equal = new BibEntry() + .withField(StandardField.TITLE, "title"); + BibEntry equal2 = new BibEntry() + .withField(StandardField.TITLE, "title"); assertEquals(0, comparator.compare(equal, equal2)); } @@ -155,10 +160,10 @@ public void compareStringFieldsEquality() throws Exception { @Test public void compareStringFieldsBiggerAscending() throws Exception { FieldComparator comparator = new FieldComparator(StandardField.TITLE); - BibEntry bigger = new BibEntry(); - bigger.setField(StandardField.TITLE, "b"); - BibEntry smaller = new BibEntry(); - smaller.setField(StandardField.TITLE, "a"); + BibEntry bigger = new BibEntry() + .withField(StandardField.TITLE, "b"); + BibEntry smaller = new BibEntry() + .withField(StandardField.TITLE, "a"); assertEquals(1, comparator.compare(bigger, smaller)); } @@ -166,11 +171,56 @@ public void compareStringFieldsBiggerAscending() throws Exception { @Test public void compareStringFieldsBiggerDescending() throws Exception { FieldComparator comparator = new FieldComparator(new OrFields(StandardField.TITLE), true); - BibEntry bigger = new BibEntry(); - bigger.setField(StandardField.TITLE, "a"); - BibEntry smaller = new BibEntry(); - smaller.setField(StandardField.TITLE, "b"); + BibEntry bigger = new BibEntry() + .withField(StandardField.TITLE, "a"); + BibEntry smaller = new BibEntry() + .withField(StandardField.TITLE, "b"); + + assertEquals(1, comparator.compare(bigger, smaller)); + } + + @Test + public void compareNumericFieldsBiggerDescending() throws Exception { + FieldComparator comparator = new FieldComparator(new OrFields(StandardField.PMID), true); + BibEntry smaller = new BibEntry() + .withField(StandardField.PMID, "234567"); + BibEntry bigger = new BibEntry() + .withField(StandardField.PMID, "123456"); assertEquals(1, comparator.compare(bigger, smaller)); } + + @Test + public void compareParsableWithNonParsableNumericFieldDescending() throws Exception { + FieldComparator comparator = new FieldComparator(new OrFields(StandardField.PMID), true); + BibEntry parsable = new BibEntry() + .withField(StandardField.PMID, "123456"); + BibEntry unparsable = new BibEntry() + .withField(StandardField.PMID, "abc##z"); + + assertEquals(1, comparator.compare(parsable, unparsable)); + } + + @ParameterizedTest + @MethodSource("provideArgumentsForNumericalComparison") + public void compareNumericalValues(int comparisonResult, String id1, String id2, String errorMessage) { + FieldComparator comparator = new FieldComparator(StandardField.PMID); + BibEntry entry1 = new BibEntry() + .withField(StandardField.PMID, id1); + BibEntry entry2 = new BibEntry() + .withField(StandardField.PMID, id2); + + assertEquals(comparisonResult, comparator.compare(entry1, entry2), errorMessage); + } + + private static Stream provideArgumentsForNumericalComparison() { + return Stream.of( + Arguments.of(0, "123456", "123456", "IDs are lexicographically not equal [1]"), + Arguments.of(1, "234567", "123456", "234567 is lexicographically smaller than 123456"), + Arguments.of(1, "abc##z", "123456", "abc##z is lexicographically smaller than 123456 "), + Arguments.of(0, "", "", "IDs are lexicographically not equal [2]"), + Arguments.of(1, "", "123456", "No ID is lexicographically smaller than 123456"), + Arguments.of(-1, "123456", "", "123456 is lexicographically greater than no ID") + ); + } } diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/EscapeAmpersandsFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/EscapeAmpersandsFormatterTest.java index 2e1a3d6b222..0f5258511f7 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/EscapeAmpersandsFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/EscapeAmpersandsFormatterTest.java @@ -28,4 +28,14 @@ void formatEscapesAmpersandsIfPresent() throws Exception { void formatExample() { assertEquals("Text \\& with \\&ersands", formatter.format(formatter.getExampleInput())); } + + @Test + void formatReturnsSameTextInNewUserDefinedLatexCommandIfNoAmpersandsPresent() throws Exception { + assertEquals("\\newcommand[1]{Lorem ipsum}", formatter.format("\\newcommand[1]{Lorem ipsum}")); + } + + @Test + void formatReturnsSameTextInLatexCommandIfOneAmpersandPresent() throws Exception { + assertEquals("\\textbf{Lorem\\&ipsum}", formatter.format("\\textbf{Lorem\\&ipsum}")); + } } diff --git a/src/test/java/org/jabref/logic/integrity/BooktitleCheckerTest.java b/src/test/java/org/jabref/logic/integrity/BooktitleCheckerTest.java index e7014420af5..f021a93e3f1 100644 --- a/src/test/java/org/jabref/logic/integrity/BooktitleCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/BooktitleCheckerTest.java @@ -21,4 +21,9 @@ void booktitleDoesNotAcceptsIfItEndsWithConferenceOn() { assertNotEquals(Optional.empty(), checker.checkValue("Digital Information and Communication Technology and it's Applications (DICTAP), 2014 Fourth International Conference on")); } + @Test + void booktitleIsBlank() { + assertEquals(Optional.empty(), checker.checkValue(" ")); + } + } diff --git a/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java b/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java index 0baec33fded..466bff79167 100644 --- a/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java @@ -2,6 +2,7 @@ import java.util.Optional; +import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; @@ -80,6 +81,28 @@ void bibTexAcceptsOrdinalNumberInNumbers() { assertEquals(Optional.empty(), checker.checkValue("2nd")); } + @Test + void bibTexEmptyValueAsInput() { + assertEquals(Optional.empty(), checker.checkValue("")); + } + + @Test + void bibTexNullValueAsInput() { + assertEquals(Optional.empty(), checker.checkValue(null)); + } + + @Test + void bibTexDoesNotAcceptIntegerOnly() { + var editionChecker = new EditionChecker(bibtex, false); + assertEquals(Optional.of(Localization.lang("no integer as values for edition allowed")), editionChecker.checkValue("3")); + } + + @Test + void bibTexAcceptsFirstEditionAlsoIfIntegerEditionDisallowed() { + var editionChecker = new EditionChecker(bibtex, false); + assertEquals(Optional.of(Localization.lang("edition of book reported as just 1")), editionChecker.checkValue("1")); + } + @Test void bibLaTexAcceptsEditionWithCapitalFirstLetter() { assertEquals(Optional.empty(), checkerb.checkValue("Edition 2000")); diff --git a/src/test/java/org/jabref/logic/integrity/ISBNCheckerTest.java b/src/test/java/org/jabref/logic/integrity/ISBNCheckerTest.java index 6fbea234524..e4dca72548d 100644 --- a/src/test/java/org/jabref/logic/integrity/ISBNCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/ISBNCheckerTest.java @@ -1,8 +1,14 @@ package org.jabref.logic.integrity; import java.util.Optional; +import java.util.stream.Stream; + +import org.jabref.logic.l10n.Localization; 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.junit.jupiter.api.Assertions.assertNotEquals; @@ -31,4 +37,17 @@ void isbnDoesNotAcceptInvalidInput() { assertNotEquals(Optional.empty(), checker.checkValue("0-201-53082-2")); } + @ParameterizedTest + @MethodSource("provideBoundaryArgumentsForISBN13") + public void checkISBNValue(Optional optValue, String id) { + assertEquals(optValue, checker.checkValue(id)); + } + + private static Stream provideBoundaryArgumentsForISBN13() { + return Stream.of( + Arguments.of(Optional.empty(), "978-0-306-40615-7"), + Arguments.of(Optional.of(Localization.lang("incorrect control digit")), "978-0-306-40615-2"), + Arguments.of(Optional.of(Localization.lang("incorrect format")), "978_0_306_40615_7") + ); + } } diff --git a/src/test/java/org/jabref/logic/integrity/ISSNCheckerTest.java b/src/test/java/org/jabref/logic/integrity/ISSNCheckerTest.java index 350412e3ea1..ddf7ffa82b0 100644 --- a/src/test/java/org/jabref/logic/integrity/ISSNCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/ISSNCheckerTest.java @@ -1,8 +1,14 @@ package org.jabref.logic.integrity; import java.util.Optional; +import java.util.stream.Stream; + +import org.jabref.logic.l10n.Localization; 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.junit.jupiter.api.Assertions.assertNotEquals; @@ -31,4 +37,23 @@ void issnDoesNotAcceptInvalidInput() { assertNotEquals(Optional.empty(), checker.checkValue("0020-7218")); } + @Test + void emptyIssnValue() { + assertEquals(Optional.empty(), checker.checkValue("")); + } + + @ParameterizedTest + @MethodSource("provideIncorrectFormatArguments") + public void issnWithWrongFormat(String wrongISSN) { + assertEquals(Optional.of(Localization.lang("incorrect format")), checker.checkValue(wrongISSN)); + } + + private static Stream provideIncorrectFormatArguments() { + return Stream.of( + Arguments.of("020-721"), + Arguments.of("0020-72109"), + Arguments.of("0020~72109") + ); + } + } diff --git a/src/test/java/org/jabref/logic/layout/format/ShortMonthFormatterTest.java b/src/test/java/org/jabref/logic/layout/format/ShortMonthFormatterTest.java index bcd17b9e518..2b8ee803be5 100644 --- a/src/test/java/org/jabref/logic/layout/format/ShortMonthFormatterTest.java +++ b/src/test/java/org/jabref/logic/layout/format/ShortMonthFormatterTest.java @@ -1,9 +1,14 @@ package org.jabref.logic.layout.format; +import java.util.stream.Stream; + import org.jabref.logic.layout.LayoutFormatter; 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; @@ -17,8 +22,24 @@ public void setUp() { } @Test - public void testFormat() { - assertEquals("jan", formatter.format("01")); - assertEquals("jan", formatter.format("Januar")); + public void formatNullInput() { + assertEquals("", formatter.format(null)); + } + + @ParameterizedTest + @MethodSource("provideArguments") + public void formatDifferentInputs(String formattedString, String originalString) { + assertEquals(formattedString, formatter.format(originalString)); + } + + private static Stream provideArguments() { + return Stream.of( + Arguments.of("jan", "jan"), + Arguments.of("jan", "January"), + Arguments.of("jan", "Januar"), + Arguments.of("jan", "01"), + Arguments.of("", "Invented Month"), + Arguments.of("", "") + ); } } diff --git a/src/test/java/org/jabref/logic/layout/format/ToLowerCaseTest.java b/src/test/java/org/jabref/logic/layout/format/ToLowerCaseTest.java index be565fcdc6f..1ab1455925c 100644 --- a/src/test/java/org/jabref/logic/layout/format/ToLowerCaseTest.java +++ b/src/test/java/org/jabref/logic/layout/format/ToLowerCaseTest.java @@ -1,34 +1,37 @@ package org.jabref.logic.layout.format; +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; import static org.junit.jupiter.api.Assertions.assertNull; public class ToLowerCaseTest { - @Test - public void testEmpty() { - assertEquals("", new ToLowerCase().format("")); - } - @Test public void testNull() { assertNull(new ToLowerCase().format(null)); } - @Test - public void testLowerCase() { - assertEquals("abcd efg", new ToLowerCase().format("abcd efg")); + @ParameterizedTest + @MethodSource("provideArguments") + public void toLowerCaseWithDifferentInputs(String expectedString, String originalString) { + assertEquals(expectedString, new ToLowerCase().format(originalString)); } - @Test - public void testUpperCase() { - assertEquals("abcd efg", new ToLowerCase().format("ABCD EFG")); - } - - @Test - public void testMixedCase() { - assertEquals("abcd efg", new ToLowerCase().format("abCD eFg")); + private static Stream provideArguments() { + return Stream.of( + Arguments.of("", ""), + Arguments.of("abcd efg", "abcd efg"), + Arguments.of("abcd efg", "ABCD EFG"), + Arguments.of("abcd efg", "abCD eFg"), + Arguments.of("abcd123efg", "abCD123eFg"), + Arguments.of("hello!*#", "Hello!*#"), + Arguments.of("123*%&456", "123*%&456") + ); } } diff --git a/src/test/java/org/jabref/model/entry/DateTest.java b/src/test/java/org/jabref/model/entry/DateTest.java index 3e8ba6127e7..379f3fe9101 100644 --- a/src/test/java/org/jabref/model/entry/DateTest.java +++ b/src/test/java/org/jabref/model/entry/DateTest.java @@ -4,8 +4,12 @@ import java.time.Year; import java.time.YearMonth; import java.util.Optional; +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; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -40,4 +44,21 @@ void parseCorrectlyYearDate() throws Exception { void parseDateNull() { assertThrows(NullPointerException.class, () -> Date.parse(null)); } + + @ParameterizedTest + @MethodSource("provideInvalidCornerCaseArguments") + public void nonExistentDates(String invalidDate, String errorMessage) { + assertEquals(Optional.empty(), Date.parse(invalidDate), errorMessage); + + } + + private static Stream provideInvalidCornerCaseArguments() { + return Stream.of( + Arguments.of("", "input value not empty"), + Arguments.of("32-06-2014", "day of month exists [1]"), + Arguments.of("00-06-2014", "day of month exists [2]"), + Arguments.of("30-13-2014", "month exists [1]"), + Arguments.of("30-00-2014", "month exists [2]") + ); + } }