diff --git a/src/test/java/org/jabref/logic/integrity/ASCIICharacterCheckerTest.java b/src/test/java/org/jabref/logic/integrity/ASCIICharacterCheckerTest.java new file mode 100644 index 00000000000..0b5ca6a9d9e --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/ASCIICharacterCheckerTest.java @@ -0,0 +1,36 @@ +package org.jabref.logic.integrity; + +import java.util.Collections; +import java.util.List; + +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.StandardField; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ASCIICharacterCheckerTest { + + private final ASCIICharacterChecker checker = new ASCIICharacterChecker(); + private final BibEntry entry = new BibEntry(); + + @Test + void fieldAcceptsAsciiCharacters() { + entry.setField(StandardField.TITLE, "Only ascii characters!'@12"); + assertEquals(Collections.emptyList(), checker.check(entry)); + } + + @Test + void fieldDoesNotAcceptUmlauts() { + entry.setField(StandardField.MONTH, "Umlauts are nöt ällowed"); + assertEquals(List.of(new IntegrityMessage("Non-ASCII encoded character found", entry, StandardField.MONTH)), checker.check(entry)); + } + + @Test + void fieldDoesNotAcceptUnicode() { + entry.setField(StandardField.AUTHOR, "Some unicode ⊕"); + assertEquals(List.of(new IntegrityMessage("Non-ASCII encoded character found", entry, StandardField.AUTHOR)), checker.check(entry)); + } + +} diff --git a/src/test/java/org/jabref/logic/integrity/AbbreviationCheckerTest.java b/src/test/java/org/jabref/logic/integrity/AbbreviationCheckerTest.java index a4b881833d6..802e1d7c042 100644 --- a/src/test/java/org/jabref/logic/integrity/AbbreviationCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/AbbreviationCheckerTest.java @@ -34,4 +34,15 @@ void checkValueDoesNotComplainAboutJournalNameThatHasSameAbbreviation() { abbreviationRepository.addCustomAbbreviation(new Abbreviation("Journal", "Journal")); assertEquals(Optional.empty(), checker.checkValue("Journal")); } + + @Test + void checkValueDoesNotComplainAboutJournalNameThatHasΝοAbbreviation() { + assertEquals(Optional.empty(), checker.checkValue("IEEE Software")); + } + + @Test + void checkValueDoesNotComplainAboutJournalNameThatHasΝοInput() { + assertEquals(Optional.empty(), checker.checkValue("")); + } + } diff --git a/src/test/java/org/jabref/logic/integrity/BibStringCheckerTest.java b/src/test/java/org/jabref/logic/integrity/BibStringCheckerTest.java new file mode 100644 index 00000000000..dba7f6bb196 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/BibStringCheckerTest.java @@ -0,0 +1,47 @@ +package org.jabref.logic.integrity; + +import java.util.Collections; +import java.util.List; + +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.StandardField; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class BibStringCheckerTest { + + private final BibStringChecker checker = new BibStringChecker(); + private final BibEntry entry = new BibEntry(); + + @Test + void fieldAcceptsNoHashMarks() { + entry.setField(StandardField.TITLE, "Not a single hash mark"); + assertEquals(Collections.emptyList(), checker.check(entry)); + } + + @Test + void monthAcceptsEvenNumberOfHashMarks() { + entry.setField(StandardField.MONTH, "#jan#"); + assertEquals(Collections.emptyList(), checker.check(entry)); + } + + @Test + void authorAcceptsEvenNumberOfHashMarks() { + entry.setField(StandardField.AUTHOR, "#einstein# and #newton#"); + assertEquals(Collections.emptyList(), checker.check(entry)); + } + + @Test + void monthDoesNotAcceptOddNumberOfHashMarks() { + entry.setField(StandardField.MONTH, "#jan"); + assertEquals(List.of(new IntegrityMessage("odd number of unescaped '#'", entry, StandardField.MONTH)), checker.check(entry)); + } + + @Test + void authorDoesNotAcceptOddNumberOfHashMarks() { + entry.setField(StandardField.AUTHOR, "#einstein# #amp; #newton#"); + assertEquals(List.of(new IntegrityMessage("odd number of unescaped '#'", entry, StandardField.AUTHOR)), checker.check(entry)); + } +} diff --git a/src/test/java/org/jabref/logic/integrity/BibtexKeyCheckerTest.java b/src/test/java/org/jabref/logic/integrity/BibtexKeyCheckerTest.java new file mode 100644 index 00000000000..30c27c684de --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/BibtexKeyCheckerTest.java @@ -0,0 +1,26 @@ +package org.jabref.logic.integrity; + +import java.util.Collections; + +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.InternalField; +import org.jabref.model.entry.field.StandardField; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class BibtexKeyCheckerTest { + + private final BibtexKeyChecker checker = new BibtexKeyChecker(); + private final BibEntry entry = new BibEntry(); + + @Test + void bibTexAcceptsKeyFromAuthorAndYear() { + entry.setField(InternalField.KEY_FIELD, "Knuth2014"); + entry.setField(StandardField.AUTHOR, "Knuth"); + entry.setField(StandardField.YEAR, "2014"); + assertEquals(Collections.emptyList(), checker.check(entry)); + } + +} diff --git a/src/test/java/org/jabref/logic/integrity/BooktitleCheckerTest.java b/src/test/java/org/jabref/logic/integrity/BooktitleCheckerTest.java new file mode 100644 index 00000000000..e7014420af5 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/BooktitleCheckerTest.java @@ -0,0 +1,24 @@ +package org.jabref.logic.integrity; + +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.assertNotEquals; + +public class BooktitleCheckerTest { + + private final BooktitleChecker checker = new BooktitleChecker(); + + @Test + void booktitleAcceptsIfItDoesNotEndWithConferenceOn() { + assertEquals(Optional.empty(), checker.checkValue("2014 Fourth International Conference on Digital Information and Communication Technology and it's Applications (DICTAP)")); + } + + @Test + void booktitleDoesNotAcceptsIfItEndsWithConferenceOn() { + assertNotEquals(Optional.empty(), checker.checkValue("Digital Information and Communication Technology and it's Applications (DICTAP), 2014 Fourth International Conference on")); + } + +} diff --git a/src/test/java/org/jabref/logic/integrity/BracketCheckerTest.java b/src/test/java/org/jabref/logic/integrity/BracketCheckerTest.java new file mode 100644 index 00000000000..4b5762edafd --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/BracketCheckerTest.java @@ -0,0 +1,44 @@ +package org.jabref.logic.integrity; + +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.assertNotEquals; + +public class BracketCheckerTest { + + private final BracketChecker checker = new BracketChecker(); + + @Test + void fieldAcceptsNoBrackets() { + assertEquals(Optional.empty(), checker.checkValue("x")); + } + + @Test + void fieldAcceptsEvenNumberOfBrackets() { + assertEquals(Optional.empty(), checker.checkValue("{x}")); + } + + @Test + void fieldAcceptsExpectedBracket() { + assertEquals(Optional.empty(), checker.checkValue("{x}x{}x{{}}")); + } + + @Test + void fieldDoesNotAcceptOddNumberOfBrackets() { + assertNotEquals(Optional.empty(), checker.checkValue("{x}x{}}x{{}}")); + } + + @Test + void fieldDoesNotAcceptUnexpectedClosingBracket() { + assertNotEquals(Optional.empty(), checker.checkValue("}")); + } + + @Test + void fieldDoesNotAcceptUnexpectedOpeningBracket() { + assertNotEquals(Optional.empty(), checker.checkValue("{")); + } + +} diff --git a/src/test/java/org/jabref/logic/integrity/DOIValidityCheckerTest.java b/src/test/java/org/jabref/logic/integrity/DOIValidityCheckerTest.java new file mode 100644 index 00000000000..fd0893186c6 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/DOIValidityCheckerTest.java @@ -0,0 +1,34 @@ +package org.jabref.logic.integrity; + +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.assertNotEquals; + +public class DOIValidityCheckerTest { + + private final DOIValidityChecker checker = new DOIValidityChecker(); + + @Test + void doiAcceptsValidInput() { + assertEquals(Optional.empty(), checker.checkValue("10.1023/A:1022883727209")); + } + + @Test + void doiAcceptsValidInputWithNotOnlyNumbers() { + assertEquals(Optional.empty(), checker.checkValue("10.17487/rfc1436")); + } + + @Test + void doiAcceptsValidInputNoMatterTheLengthOfTheDOIName() { + assertEquals(Optional.empty(), checker.checkValue("10.1002/(SICI)1097-4571(199205)43:4<284::AID-ASI3>3.0.CO;2-0")); + } + + @Test + void doiDoesNotAcceptInvalidInput() { + assertNotEquals(Optional.empty(), checker.checkValue("asdf")); + } + +} diff --git a/src/test/java/org/jabref/logic/integrity/DateCheckerTest.java b/src/test/java/org/jabref/logic/integrity/DateCheckerTest.java index 21cf8306ef4..a493ee80f76 100644 --- a/src/test/java/org/jabref/logic/integrity/DateCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/DateCheckerTest.java @@ -2,19 +2,13 @@ import java.util.Optional; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; class DateCheckerTest { - private DateChecker checker; - - @BeforeEach - void setUp() { - checker = new DateChecker(); - } + private final DateChecker checker = new DateChecker(); @Test void complainsAboutInvalidIsoLikeDate() { diff --git a/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java b/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java index 9ec01b020fe..0baec33fded 100644 --- a/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java @@ -3,21 +3,39 @@ import java.util.Optional; import org.jabref.model.database.BibDatabaseContext; +import org.jabref.model.database.BibDatabaseMode; +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.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertTrue; public class EditionCheckerTest { public BibDatabaseContext bibDatabaseContextEdition = new BibDatabaseContext(); + private EditionChecker checker; + private EditionChecker checkerb; + private BibDatabaseContext bibtex; + private BibDatabaseContext biblatex; + + @BeforeEach + void setUp() { + bibtex = new BibDatabaseContext(); + bibtex.setMode(BibDatabaseMode.BIBTEX); + biblatex = new BibDatabaseContext(); + biblatex.setMode(BibDatabaseMode.BIBLATEX); + checker = new EditionChecker(bibtex, true); + checkerb = new EditionChecker(biblatex, true); + } + @Test void isFirstCharacterANumber() { boolean allowIntegerEdition = false; - var editionChecker = new EditionChecker(bibDatabaseContextEdition, allowIntegerEdition); + EditionChecker editionChecker = new EditionChecker(bibDatabaseContextEdition, allowIntegerEdition); assertTrue(editionChecker.isFirstCharDigit("0HelloWorld")); } @@ -42,4 +60,44 @@ void editionCheckerDoesNotComplainIfAllowIntegerEditionIsEnabled() { assertEquals(Optional.empty(), editionChecker.checkValue("2")); } + @Test + void bibTexAcceptsOrdinalNumberInWordsWithCapitalFirstLetter() { + assertEquals(Optional.empty(), checker.checkValue("Second")); + } + + @Test + void bibTexDoesNotAcceptOrdinalNumberInWordsWithNonCapitalFirstLetter() { + assertNotEquals(Optional.empty(), checker.checkValue("second")); + } + + @Test + void bibTexAcceptsIntegerInputInEdition() { + assertEquals(Optional.empty(), checker.checkValue("2")); + } + + @Test + void bibTexAcceptsOrdinalNumberInNumbers() { + assertEquals(Optional.empty(), checker.checkValue("2nd")); + } + + @Test + void bibLaTexAcceptsEditionWithCapitalFirstLetter() { + assertEquals(Optional.empty(), checkerb.checkValue("Edition 2000")); + } + + @Test + void bibLaTexAcceptsIntegerInputInEdition() { + assertEquals(Optional.empty(), checkerb.checkValue("2")); + } + + @Test + void bibLaTexAcceptsEditionAsLiteralString() { + assertEquals(Optional.empty(), checkerb.checkValue("Third, revised and expanded edition")); + } + + @Test + void bibLaTexDoesNotAcceptOrdinalNumberInNumbers() { + assertNotEquals(Optional.empty(), checkerb.checkValue("2nd")); + } + } diff --git a/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java b/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java new file mode 100644 index 00000000000..c2ee7af10b3 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java @@ -0,0 +1,54 @@ +package org.jabref.logic.integrity; + +import java.util.Collections; +import java.util.List; + +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.StandardField; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class HTMLCharacterCheckerTest { + + private final HTMLCharacterChecker checker = new HTMLCharacterChecker(); + private final BibEntry entry = new BibEntry(); + + @Test + void titleAcceptsNonHTMLEncodedCharacters() { + entry.setField(StandardField.TITLE, "Not a single {HTML} character"); + assertEquals(Collections.emptyList(), checker.check(entry)); + } + + @Test + void monthAcceptsNonHTMLEncodedCharacters() { + entry.setField(StandardField.MONTH, "#jan#"); + assertEquals(Collections.emptyList(), checker.check(entry)); + } + + @Test + void authorAcceptsNonHTMLEncodedCharacters() { + entry.setField(StandardField.AUTHOR, "A. Einstein and I. Newton"); + assertEquals(Collections.emptyList(), checker.check(entry)); + } + + @Test + void urlAcceptsNonHTMLEncodedCharacters() { + entry.setField(StandardField.URL, "http://www.thinkmind.org/index.php?view=article&articleid=cloud_computing_2013_1_20_20130"); + assertEquals(Collections.emptyList(), checker.check(entry)); + } + + @Test + void authorDoesNotAcceptHTMLEncodedCharacters() { + entry.setField(StandardField.AUTHOR, "Lenhard, Jãrg"); + assertEquals(List.of(new IntegrityMessage("HTML encoded character found", entry, StandardField.AUTHOR)), checker.check(entry)); + } + + @Test + 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/integrity/HowPublishedCheckerTest.java b/src/test/java/org/jabref/logic/integrity/HowPublishedCheckerTest.java new file mode 100644 index 00000000000..c9263efadf6 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/HowPublishedCheckerTest.java @@ -0,0 +1,59 @@ +package org.jabref.logic.integrity; + +import java.util.Optional; + +import org.jabref.model.database.BibDatabaseContext; +import org.jabref.model.database.BibDatabaseMode; + +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.assertNotEquals; + +public class HowPublishedCheckerTest { + + private HowPublishedChecker checker; + private HowPublishedChecker checkerBiblatex; + + @BeforeEach + public void setUp() { + BibDatabaseContext databaseContext = new BibDatabaseContext(); + BibDatabaseContext databaseBiblatex = new BibDatabaseContext(); + databaseContext.setMode(BibDatabaseMode.BIBTEX); + checker = new HowPublishedChecker(databaseContext); + databaseBiblatex.setMode(BibDatabaseMode.BIBLATEX); + checkerBiblatex = new HowPublishedChecker(databaseBiblatex); + } + + @Test + void bibTexAcceptsStringWithCapitalFirstLetter() { + assertEquals(Optional.empty(), checker.checkValue("Lorem ipsum")); + } + + @Test + void bibTexDoesNotCareAboutSpecialChracters() { + assertEquals(Optional.empty(), checker.checkValue("Lorem ipsum? 10")); + } + + @Test + void bibTexDoesNotAcceptStringWithLowercaseFirstLetter() { + assertNotEquals(Optional.empty(), checker.checkValue("lorem ipsum")); + } + + @Test + void bibTexAcceptsUrl() { + assertEquals(Optional.empty(), checker.checkValue("\\url{someurl}")); + } + + @Test + void bibLaTexAcceptsStringWithCapitalFirstLetter() { + assertEquals(Optional.empty(), checkerBiblatex.checkValue("Lorem ipsum")); + } + + @Test + void bibLaTexAcceptsStringWithLowercaseFirstLetter() { + assertEquals(Optional.empty(), checkerBiblatex.checkValue("lorem ipsum")); + } + +} diff --git a/src/test/java/org/jabref/logic/integrity/ISBNCheckerTest.java b/src/test/java/org/jabref/logic/integrity/ISBNCheckerTest.java new file mode 100644 index 00000000000..6fbea234524 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/ISBNCheckerTest.java @@ -0,0 +1,34 @@ +package org.jabref.logic.integrity; + +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.assertNotEquals; + +public class ISBNCheckerTest { + + private final ISBNChecker checker = new ISBNChecker(); + + @Test + void isbnAcceptsValidInput() { + assertEquals(Optional.empty(), checker.checkValue("0-201-53082-1")); + } + + @Test + void isbnAcceptsNumbersAndCharacters() { + assertEquals(Optional.empty(), checker.checkValue("0-9752298-0-X")); + } + + @Test + void isbnDoesNotAcceptRandomInput() { + assertNotEquals(Optional.empty(), checker.checkValue("Some other stuff")); + } + + @Test + void isbnDoesNotAcceptInvalidInput() { + assertNotEquals(Optional.empty(), checker.checkValue("0-201-53082-2")); + } + +} diff --git a/src/test/java/org/jabref/logic/integrity/ISSNCheckerTest.java b/src/test/java/org/jabref/logic/integrity/ISSNCheckerTest.java new file mode 100644 index 00000000000..350412e3ea1 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/ISSNCheckerTest.java @@ -0,0 +1,34 @@ +package org.jabref.logic.integrity; + +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.assertNotEquals; + +public class ISSNCheckerTest { + + private final ISSNChecker checker = new ISSNChecker(); + + @Test + void issnAcceptsValidInput() { + assertEquals(Optional.empty(), checker.checkValue("0020-7217")); + } + + @Test + void issnAcceptsNumbersAndCharacters() { + assertEquals(Optional.empty(), checker.checkValue("2434-561x")); + } + + @Test + void issnDoesNotAcceptRandomInput() { + assertNotEquals(Optional.empty(), checker.checkValue("Some other stuff")); + } + + @Test + void issnDoesNotAcceptInvalidInput() { + assertNotEquals(Optional.empty(), checker.checkValue("0020-7218")); + } + +} diff --git a/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java b/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java index 4da2ccc6d2b..7e78032b051 100644 --- a/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java +++ b/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java @@ -3,11 +3,11 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.UUID; +import java.util.stream.Stream; import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; @@ -19,7 +19,6 @@ 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.InternalField; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.EntryType; import org.jabref.model.entry.types.IEEETranEntryType; @@ -29,6 +28,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Mockito; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -36,200 +37,59 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; +/** + * This class tests the Integrity Checker as a whole. + * Aspects are: selected fields, issues arising in a complete BibTeX entry, ... When testing a checker works with a certain input, + * this test has to go to a test belonging to the respective checker. See PersonNamesCheckerTest for an example test. + */ + class IntegrityCheckTest { @Test - void testEntryTypeChecks() { + void bibTexAcceptsStandardEntryType() { assertCorrect(withMode(createContext(StandardField.TITLE, "sometitle", StandardEntryType.Article), BibDatabaseMode.BIBTEX)); - assertWrong(withMode(createContext(StandardField.TITLE, "sometitle", IEEETranEntryType.Patent), BibDatabaseMode.BIBTEX)); - assertCorrect((withMode(createContext(StandardField.TITLE, "sometitle", IEEETranEntryType.Patent), BibDatabaseMode.BIBLATEX))); - assertCorrect(withMode(createContext(StandardField.TITLE, "sometitle", StandardEntryType.Article), BibDatabaseMode.BIBLATEX)); } @Test - void testUrlChecks() { - assertCorrect(createContext(StandardField.URL, "http://www.google.com")); - assertCorrect(createContext(StandardField.URL, "file://c:/asdf/asdf")); - assertCorrect(createContext(StandardField.URL, "http://scikit-learn.org/stable/modules/ensemble.html#random-forests")); - - assertWrong(createContext(StandardField.URL, "www.google.com")); - assertWrong(createContext(StandardField.URL, "google.com")); - assertWrong(createContext(StandardField.URL, "c:/asdf/asdf")); - } - - @Test - void testYearChecks() { - assertCorrect(createContext(StandardField.YEAR, "2014")); - assertCorrect(createContext(StandardField.YEAR, "1986")); - assertCorrect(createContext(StandardField.YEAR, "around 1986")); - assertCorrect(createContext(StandardField.YEAR, "(around 1986)")); - assertCorrect(createContext(StandardField.YEAR, "1986,")); - assertCorrect(createContext(StandardField.YEAR, "1986}%")); - assertCorrect(createContext(StandardField.YEAR, "1986(){},.;!?<>%&$")); - assertWrong(createContext(StandardField.YEAR, "abc")); - assertWrong(createContext(StandardField.YEAR, "86")); - assertWrong(createContext(StandardField.YEAR, "204")); - assertWrong(createContext(StandardField.YEAR, "1986a")); - assertWrong(createContext(StandardField.YEAR, "(1986a)")); - assertWrong(createContext(StandardField.YEAR, "1986a,")); - assertWrong(createContext(StandardField.YEAR, "1986}a%")); - assertWrong(createContext(StandardField.YEAR, "1986a(){},.;!?<>%&$")); - } - - @Test - void testEditionChecks() { - assertCorrect(withMode(createContext(StandardField.EDITION, "Second"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.EDITION, "Third"), BibDatabaseMode.BIBTEX)); - assertWrong(withMode(createContext(StandardField.EDITION, "second"), BibDatabaseMode.BIBTEX)); - assertWrong(withMode(createContext(StandardField.EDITION, "2"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.EDITION, "2"), BibDatabaseMode.BIBTEX), true); - assertWrong(withMode(createContext(StandardField.EDITION, "2nd"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.EDITION, "2"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.EDITION, "10"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.EDITION, "Third, revised and expanded edition"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.EDITION, "Edition 2000"), BibDatabaseMode.BIBLATEX)); - assertWrong(withMode(createContext(StandardField.EDITION, "2nd"), BibDatabaseMode.BIBLATEX)); - assertWrong(withMode(createContext(StandardField.EDITION, "1"), BibDatabaseMode.BIBTEX)); - } - - @Test - void testNoteChecks() { - assertCorrect(withMode(createContext(StandardField.NOTE, "Lorem ipsum"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.NOTE, "Lorem ipsum? 10"), BibDatabaseMode.BIBTEX)); - assertWrong(withMode(createContext(StandardField.NOTE, "lorem ipsum"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.NOTE, "Lorem ipsum"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.NOTE, "\\url{someurl}"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.NOTE, "lorem ipsum"), BibDatabaseMode.BIBLATEX)); - } - - @Test - void testHowpublishedChecks() { - assertCorrect(withMode(createContext(StandardField.HOWPUBLISHED, "Lorem ipsum"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.HOWPUBLISHED, "Lorem ipsum? 10"), BibDatabaseMode.BIBTEX)); - assertWrong(withMode(createContext(StandardField.HOWPUBLISHED, "lorem ipsum"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.HOWPUBLISHED, "\\url{someurl}"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.HOWPUBLISHED, "Lorem ipsum"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.HOWPUBLISHED, "lorem ipsum"), BibDatabaseMode.BIBLATEX)); - } - - @Test - void testMonthChecks() { - assertCorrect(withMode(createContext(StandardField.MONTH, "#mar#"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.MONTH, "#dec#"), BibDatabaseMode.BIBTEX)); - assertWrong(withMode(createContext(StandardField.MONTH, "#bla#"), BibDatabaseMode.BIBTEX)); - assertWrong(withMode(createContext(StandardField.MONTH, "Dec"), BibDatabaseMode.BIBTEX)); - assertWrong(withMode(createContext(StandardField.MONTH, "December"), BibDatabaseMode.BIBTEX)); - assertWrong(withMode(createContext(StandardField.MONTH, "Lorem"), BibDatabaseMode.BIBTEX)); - assertWrong(withMode(createContext(StandardField.MONTH, "10"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.MONTH, "1"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.MONTH, "10"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.MONTH, "#jan#"), BibDatabaseMode.BIBLATEX)); - assertWrong(withMode(createContext(StandardField.MONTH, "jan"), BibDatabaseMode.BIBLATEX)); - assertWrong(withMode(createContext(StandardField.MONTH, "january"), BibDatabaseMode.BIBLATEX)); - assertWrong(withMode(createContext(StandardField.MONTH, "January"), BibDatabaseMode.BIBLATEX)); - assertWrong(withMode(createContext(StandardField.MONTH, "Lorem"), BibDatabaseMode.BIBLATEX)); - } - - @Test - void testJournaltitleChecks() { - assertWrong(withMode(createContext(StandardField.JOURNALTITLE, "A journal"), BibDatabaseMode.BIBLATEX)); - assertWrong(withMode(createContext(StandardField.JOURNAL, "A journal"), BibDatabaseMode.BIBTEX)); + void bibTexDoesNotAcceptIEEETranEntryType() { + assertWrong(withMode(createContext(StandardField.TITLE, "sometitle", IEEETranEntryType.Patent), BibDatabaseMode.BIBTEX)); } @Test - void testBibtexkeyChecks() { - final BibDatabaseContext correctContext = createContext(InternalField.KEY_FIELD, "Knuth2014"); - correctContext.getDatabase().getEntries().get(0).setField(StandardField.AUTHOR, "Knuth"); - correctContext.getDatabase().getEntries().get(0).setField(StandardField.YEAR, "2014"); - assertCorrect(correctContext); - - final BibDatabaseContext wrongContext = createContext(InternalField.KEY_FIELD, "Knuth2014a"); - wrongContext.getDatabase().getEntries().get(0).setField(StandardField.AUTHOR, "Knuth"); - wrongContext.getDatabase().getEntries().get(0).setField(StandardField.YEAR, "2014"); - assertWrong(wrongContext); + void bibLaTexAcceptsIEEETranEntryType() { + assertCorrect((withMode(createContext(StandardField.TITLE, "sometitle", IEEETranEntryType.Patent), BibDatabaseMode.BIBLATEX))); } @Test - void testBracketChecks() { - assertCorrect(createContext(StandardField.TITLE, "x")); - assertCorrect(createContext(StandardField.TITLE, "{x}")); - assertCorrect(createContext(StandardField.TITLE, "{x}x{}x{{}}")); - assertWrong(createContext(StandardField.TITLE, "{x}x{}}x{{}}")); - assertWrong(createContext(StandardField.TITLE, "}")); - assertWrong(createContext(StandardField.TITLE, "{")); + void bibLaTexAcceptsStandardEntryType() { + assertCorrect(withMode(createContext(StandardField.TITLE, "sometitle", StandardEntryType.Article), BibDatabaseMode.BIBLATEX)); } - @Test - void testAuthorNameChecks() { + @ParameterizedTest + @MethodSource("provideCorrectFormat") + void authorNameChecksCorrectFormat(String input) { for (Field field : FieldFactory.getPersonNameFields()) { - // getPersonNameFields returns fields that are available in biblatex only - // if run without mode, the NoBibtexFieldChecker will complain that "afterword" is a biblatex only field - assertCorrect(withMode(createContext(field, ""), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(field, "Knuth"), BibDatabaseMode.BIBLATEX)); - assertWrong(withMode(createContext(field, " Knuth, Donald E. "), BibDatabaseMode.BIBLATEX)); - assertWrong(withMode(createContext(field, "Knuth, Donald E. and Kurt Cobain and A. Einstein"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(field, "Donald E. Knuth and Kurt Cobain and A. Einstein"), BibDatabaseMode.BIBLATEX)); - assertWrong(withMode(createContext(field, ", and Kurt Cobain and A. Einstein"), BibDatabaseMode.BIBLATEX)); - assertWrong(withMode(createContext(field, "Donald E. Knuth and Kurt Cobain and ,"), BibDatabaseMode.BIBLATEX)); - assertWrong(withMode(createContext(field, "and Kurt Cobain and A. Einstein"), BibDatabaseMode.BIBLATEX)); - assertWrong(withMode(createContext(field, "Donald E. Knuth and Kurt Cobain and"), BibDatabaseMode.BIBLATEX)); + assertCorrect(withMode(createContext(field, input), BibDatabaseMode.BIBLATEX)); } } - @Test - void testTitleChecks() { - assertCorrect(withMode(createContext(StandardField.TITLE, "This is a title"), BibDatabaseMode.BIBTEX)); - assertWrong(withMode(createContext(StandardField.TITLE, "This is a Title"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This is a {T}itle"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "{This is a Title}"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This is a {Title}"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "{C}urrent {C}hronicle"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "{A Model-Driven Approach for Monitoring {ebBP} BusinessTransactions}"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This is a sub title 1: This is a sub title 2"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This is a sub title 1: this is a sub title 2"), BibDatabaseMode.BIBTEX)); - assertWrong(withMode(createContext(StandardField.TITLE, "This is a sub title 1: This is A sub title 2"), BibDatabaseMode.BIBTEX)); - assertWrong(withMode(createContext(StandardField.TITLE, "This is a sub title 1: this is A sub title 2"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This is a sub title 1: This is {A} sub title 2"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This is a sub title 1: this is {A} sub title 2"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This is a sub title 1...This is a sub title 2"), BibDatabaseMode.BIBTEX)); - assertWrong(withMode(createContext(StandardField.TITLE, "This is a sub title 1... this is a sub Title 2"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This is; A sub title 1.... This is a sub title 2"), BibDatabaseMode.BIBTEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This!is!!A!Title??"), BibDatabaseMode.BIBTEX)); - assertWrong(withMode(createContext(StandardField.TITLE, "This!is!!A!TitlE??"), BibDatabaseMode.BIBTEX)); - - assertCorrect(withMode(createContext(StandardField.TITLE, "This is a title"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This is a Title"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This is a {T}itle"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "{This is a Title}"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This is a {Title}"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "{C}urrent {C}hronicle"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "{A Model-Driven Approach for Monitoring {ebBP} BusinessTransactions}"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This is a sub title 1: This is a sub title 2"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This is a sub title 1: this is a sub title 2"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This is a sub title 1: This is A sub title 2"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This is a sub title 1: this is A sub title 2"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This is a sub title 1: This is {A} sub title 2"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This is a sub title 1: this is {A} sub title 2"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This is a sub title 1...This is a sub title 2"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This is a sub title 1... this is a sub Title 2"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This is; A sub title 1.... This is a sub title 2"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This!is!!A!Title??"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.TITLE, "This!is!!A!TitlE??"), BibDatabaseMode.BIBLATEX)); + @ParameterizedTest + @MethodSource("provideIncorrectFormat") + void authorNameChecksIncorrectFormat(String input) { + for (Field field : FieldFactory.getPersonNameFields()) { + assertWrong(withMode(createContext(field, input), BibDatabaseMode.BIBLATEX)); + } } - @Test - void testAbbreviationChecks() { - for (Field field : Arrays.asList(StandardField.BOOKTITLE, StandardField.JOURNAL)) { - assertCorrect(createContext(field, "2D Materials")); - assertCorrect(createContext(field, "")); - assertWrong(createContext(field, "2D Mater.")); - } + private static Stream provideCorrectFormat() { + return Stream.of("", "Knuth", "Donald E. Knuth and Kurt Cobain and A. Einstein"); } - @Test - void testJournalIsKnownInAbbreviationList() { - assertCorrect(createContext(StandardField.JOURNAL, "2D Materials")); - assertWrong(createContext(StandardField.JOURNAL, "Some unknown journal")); + private static Stream provideIncorrectFormat() { + return Stream.of(" Knuth, Donald E. ", + "Knuth, Donald E. and Kurt Cobain and A. Einstein", + ", and Kurt Cobain and A. Einstein", "Donald E. Knuth and Kurt Cobain and ,", + "and Kurt Cobain and A. Einstein", "Donald E. Knuth and Kurt Cobain and"); } @Test @@ -258,95 +118,6 @@ void fileCheckFindsFilesRelativeToBibFile(@TempDir Path testFolder) throws IOExc assertCorrect(databaseContext); } - @Test - void testTypeChecks() { - assertCorrect(createContext(StandardField.PAGES, "11--15", StandardEntryType.InProceedings)); - assertWrong(createContext(StandardField.PAGES, "11--15", StandardEntryType.Proceedings)); - } - - @Test - void testBooktitleChecks() { - assertCorrect(createContext(StandardField.BOOKTITLE, "2014 Fourth International Conference on Digital Information and Communication Technology and it's Applications (DICTAP)", StandardEntryType.Proceedings)); - assertWrong(createContext(StandardField.BOOKTITLE, "Digital Information and Communication Technology and it's Applications (DICTAP), 2014 Fourth International Conference on", StandardEntryType.Proceedings)); - } - - @Test - void testPageNumbersChecks() { - assertCorrect(createContext(StandardField.PAGES, "1--2")); - assertCorrect(createContext(StandardField.PAGES, "12")); - assertWrong(createContext(StandardField.PAGES, "1-2")); - assertCorrect(createContext(StandardField.PAGES, "1,2,3")); - assertCorrect(createContext(StandardField.PAGES, "43+")); - assertWrong(createContext(StandardField.PAGES, "1 2")); - assertWrong(createContext(StandardField.PAGES, "{1}-{2}")); - assertCorrect(createContext(StandardField.PAGES, "7,41,73--97")); - assertCorrect(createContext(StandardField.PAGES, "7,41--42,73")); - assertCorrect(createContext(StandardField.PAGES, "7--11,41--43,73")); - assertCorrect(createContext(StandardField.PAGES, "7+,41--43,73")); - } - - @Test - void testBiblatexPageNumbersChecks() { - assertCorrect(withMode(createContext(StandardField.PAGES, "1--2"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.PAGES, "12"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.PAGES, "1-2"), BibDatabaseMode.BIBLATEX)); // only diff to bibtex - assertCorrect(withMode(createContext(StandardField.PAGES, "1,2,3"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.PAGES, "43+"), BibDatabaseMode.BIBLATEX)); - assertWrong(withMode(createContext(StandardField.PAGES, "1 2"), BibDatabaseMode.BIBLATEX)); - assertWrong(withMode(createContext(StandardField.PAGES, "{1}-{2}"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.PAGES, "7,41,73--97"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.PAGES, "7,41--42,73"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.PAGES, "7--11,41--43,73"), BibDatabaseMode.BIBLATEX)); - assertCorrect(withMode(createContext(StandardField.PAGES, "7+,41--43,73"), BibDatabaseMode.BIBLATEX)); - } - - @Test - void testBibStringChecks() { - assertCorrect(createContext(StandardField.TITLE, "Not a single hash mark")); - assertCorrect(createContext(StandardField.MONTH, "#jan#")); - assertCorrect(createContext(StandardField.AUTHOR, "#einstein# and #newton#")); - assertWrong(createContext(StandardField.MONTH, "#jan")); - assertWrong(createContext(StandardField.AUTHOR, "#einstein# #amp; #newton#")); - } - - @Test - void testHTMLCharacterChecks() { - assertCorrect(createContext(StandardField.TITLE, "Not a single {HTML} character")); - assertCorrect(createContext(StandardField.MONTH, "#jan#")); - assertCorrect(createContext(StandardField.AUTHOR, "A. Einstein and I. Newton")); - assertCorrect(createContext(StandardField.URL, "http://www.thinkmind.org/index.php?view=article&articleid=cloud_computing_2013_1_20_20130")); - assertWrong(createContext(StandardField.AUTHOR, "Lenhard, Jörg")); - assertWrong(createContext(StandardField.AUTHOR, "Lenhard, Jãrg")); - assertWrong(createContext(StandardField.JOURNAL, "Ärling Ström for – ‱")); - } - - @Test - void testISSNChecks() { - assertCorrect(createContext(StandardField.ISSN, "0020-7217")); - assertCorrect(createContext(StandardField.ISSN, "1687-6180")); - assertCorrect(createContext(StandardField.ISSN, "2434-561x")); - assertWrong(createContext(StandardField.ISSN, "Some other stuff")); - assertWrong(createContext(StandardField.ISSN, "0020-7218")); - } - - @Test - void testISBNChecks() { - assertCorrect(createContext(StandardField.ISBN, "0-201-53082-1")); - assertCorrect(createContext(StandardField.ISBN, "0-9752298-0-X")); - assertCorrect(createContext(StandardField.ISBN, "978-0-306-40615-7")); - assertWrong(createContext(StandardField.ISBN, "Some other stuff")); - assertWrong(createContext(StandardField.ISBN, "0-201-53082-2")); - assertWrong(createContext(StandardField.ISBN, "978-0-306-40615-8")); - } - - @Test - void testDOIChecks() { - assertCorrect(createContext(StandardField.DOI, "10.1023/A:1022883727209")); - assertCorrect(createContext(StandardField.DOI, "10.17487/rfc1436")); - assertCorrect(createContext(StandardField.DOI, "10.1002/(SICI)1097-4571(199205)43:4<284::AID-ASI3>3.0.CO;2-0")); - assertWrong(createContext(StandardField.DOI, "asdf")); - } - @Test void testEntryIsUnchangedAfterChecks() { BibEntry entry = new BibEntry(); @@ -374,13 +145,6 @@ void testEntryIsUnchangedAfterChecks() { assertEquals(clonedEntry, entry); } - @Test - void testASCIIChecks() { - assertCorrect(createContext(StandardField.TITLE, "Only ascii characters!'@12")); - assertWrong(createContext(StandardField.MONTH, "Umlauts are nöt ällowed")); - assertWrong(createContext(StandardField.AUTHOR, "Some unicode ⊕")); - } - private BibDatabaseContext createContext(Field field, String value, EntryType type) { BibEntry entry = new BibEntry(); entry.setField(field, value); @@ -424,11 +188,10 @@ private void assertCorrect(BibDatabaseContext context) { private void assertCorrect(BibDatabaseContext context, boolean allowIntegerEdition) { List messages = new IntegrityCheck(context, - mock(FilePreferences.class), - createBibtexKeyPatternPreferences(), - JournalAbbreviationLoader.loadBuiltInRepository(), - allowIntegerEdition - ).checkDatabase(); + mock(FilePreferences.class), + createBibtexKeyPatternPreferences(), + JournalAbbreviationLoader.loadBuiltInRepository(), + allowIntegerEdition).checkDatabase(); assertEquals(Collections.emptyList(), messages); } diff --git a/src/test/java/org/jabref/logic/integrity/JournalInAbbreviationListCheckerTest.java b/src/test/java/org/jabref/logic/integrity/JournalInAbbreviationListCheckerTest.java new file mode 100644 index 00000000000..775ca2dd7a9 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/JournalInAbbreviationListCheckerTest.java @@ -0,0 +1,56 @@ +package org.jabref.logic.integrity; + +import java.util.Collections; +import java.util.List; + +import org.jabref.logic.journals.Abbreviation; +import org.jabref.logic.journals.JournalAbbreviationLoader; +import org.jabref.logic.journals.JournalAbbreviationRepository; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.StandardField; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class JournalInAbbreviationListCheckerTest { + + private JournalInAbbreviationListChecker checker; + private JournalInAbbreviationListChecker checkerb; + private JournalAbbreviationRepository abbreviationRepository; + private BibEntry entry; + + @BeforeEach + void setUp() { + abbreviationRepository = JournalAbbreviationLoader.loadBuiltInRepository(); + abbreviationRepository.addCustomAbbreviation(new Abbreviation("IEEE Software", "IEEE SW")); + checker = new JournalInAbbreviationListChecker(StandardField.JOURNAL, abbreviationRepository); + checkerb = new JournalInAbbreviationListChecker(StandardField.JOURNALTITLE, abbreviationRepository); + entry = new BibEntry(); + } + + @Test + void journalAcceptsNameInTheList() { + entry.setField(StandardField.JOURNAL, "IEEE Software"); + assertEquals(Collections.emptyList(), checker.check(entry)); + } + + @Test + void journalDoesNotAcceptNameNotInList() { + entry.setField(StandardField.JOURNAL, "IEEE Whocares"); + assertEquals(List.of(new IntegrityMessage("journal not found in abbreviation list", entry, StandardField.JOURNAL)), checker.check(entry)); + } + + @Test + void journalTitleDoesNotAcceptRandomInputInTitle() { + entry.setField(StandardField.JOURNALTITLE, "A journal"); + assertEquals(List.of(new IntegrityMessage("journal not found in abbreviation list", entry, StandardField.JOURNALTITLE)), checkerb.check(entry)); + } + + @Test + void journalDoesNotAcceptRandomInputInTitle() { + entry.setField(StandardField.JOURNAL, "A journal"); + assertEquals(List.of(new IntegrityMessage("journal not found in abbreviation list", entry, StandardField.JOURNAL)), checker.check(entry)); + } +} diff --git a/src/test/java/org/jabref/logic/integrity/MonthCheckerTest.java b/src/test/java/org/jabref/logic/integrity/MonthCheckerTest.java new file mode 100644 index 00000000000..44c1603bb81 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/MonthCheckerTest.java @@ -0,0 +1,83 @@ +package org.jabref.logic.integrity; + +import java.util.Optional; + +import org.jabref.model.database.BibDatabaseContext; +import org.jabref.model.database.BibDatabaseMode; + +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.assertNotEquals; + +public class MonthCheckerTest { + + private MonthChecker checker; + private MonthChecker checkerBiblatex; + + @BeforeEach + public void setUp() { + BibDatabaseContext databaseContext = new BibDatabaseContext(); + BibDatabaseContext databaseBiblatex = new BibDatabaseContext(); + databaseContext.setMode(BibDatabaseMode.BIBTEX); + checker = new MonthChecker(databaseContext); + databaseBiblatex.setMode(BibDatabaseMode.BIBLATEX); + checkerBiblatex = new MonthChecker(databaseBiblatex); + } + + @Test + void bibTexAcceptsThreeLetterAbbreviationsWithHashMarks() { + assertEquals(Optional.empty(), checker.checkValue("#mar#")); + } + + @Test + void bibTexDoesNotAcceptWhateverThreeLetterAbbreviations() { + assertNotEquals(Optional.empty(), checker.checkValue("#bla#")); + } + + @Test + void bibTexDoesNotAcceptThreeLetterAbbreviationsWithNoHashMarks() { + assertNotEquals(Optional.empty(), checker.checkValue("Dec")); + } + + @Test + void bibTexDoesNotAcceptFullInput() { + assertNotEquals(Optional.empty(), checker.checkValue("December")); + } + + @Test + void bibTexDoesNotAcceptRandomString() { + assertNotEquals(Optional.empty(), checker.checkValue("Lorem")); + } + + @Test + void bibTexDoesNotAcceptInteger() { + assertNotEquals(Optional.empty(), checker.checkValue("10")); + } + + @Test + void bibLaTexAcceptsThreeLetterAbbreviationsWithHashMarks() { + assertEquals(Optional.empty(), checkerBiblatex.checkValue("#jan#")); + } + + @Test + void bibLaTexDoesNotAcceptThreeLetterAbbreviationsWithNoHashMarks() { + assertNotEquals(Optional.empty(), checkerBiblatex.checkValue("jan")); + } + + @Test + void bibLaTexDoesNotAcceptFullInput() { + assertNotEquals(Optional.empty(), checkerBiblatex.checkValue("January")); + } + + @Test + void bibLaTexDoesNotAcceptRandomString() { + assertNotEquals(Optional.empty(), checkerBiblatex.checkValue("Lorem")); + } + + @Test + void bibLaTexAcceptsInteger() { + assertEquals(Optional.empty(), checkerBiblatex.checkValue("10")); + } +} diff --git a/src/test/java/org/jabref/logic/integrity/NoteCheckerTest.java b/src/test/java/org/jabref/logic/integrity/NoteCheckerTest.java new file mode 100644 index 00000000000..aada4446f23 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/NoteCheckerTest.java @@ -0,0 +1,60 @@ +package org.jabref.logic.integrity; + +import java.util.Optional; + +import org.jabref.model.database.BibDatabaseContext; +import org.jabref.model.database.BibDatabaseMode; + +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.assertNotEquals; + +public class NoteCheckerTest { + + private NoteChecker checker; + private NoteChecker checkerBiblatex; + + @BeforeEach + void setUp() { + BibDatabaseContext database = new BibDatabaseContext(); + BibDatabaseContext databaseBiblatex = new BibDatabaseContext(); + database.setMode(BibDatabaseMode.BIBTEX); + checker = new NoteChecker(database); + databaseBiblatex.setMode(BibDatabaseMode.BIBLATEX); + checkerBiblatex = new NoteChecker(databaseBiblatex); + + } + + @Test + void bibTexAcceptsNoteWithFirstCapitalLetter() { + assertEquals(Optional.empty(), checker.checkValue("Lorem ipsum")); + } + + @Test + void bibTexAcceptsNoteWithFirstCapitalLetterAndDoesNotCareAboutTheRest() { + assertEquals(Optional.empty(), checker.checkValue("Lorem ipsum? 10")); + } + + @Test + void bibTexDoesNotAcceptFirstLowercaseLetter() { + assertNotEquals(Optional.empty(), checker.checkValue("lorem ipsum")); + } + + @Test + void bibLaTexAcceptsNoteWithFirstCapitalLetter() { + assertEquals(Optional.empty(), checkerBiblatex.checkValue("Lorem ipsum")); + } + + @Test + void bibTexAcceptsUrl() { + assertEquals(Optional.empty(), checker.checkValue("\\url{someurl}")); + } + + @Test + void bibLaTexAcceptsFirstLowercaseLetter() { + assertEquals(Optional.empty(), checkerBiblatex.checkValue("lorem ipsum")); + } + +} diff --git a/src/test/java/org/jabref/logic/integrity/PagesCheckerBibLatexTest.java b/src/test/java/org/jabref/logic/integrity/PagesCheckerBibLatexTest.java index 9958b8c4172..07e17a0ac3f 100644 --- a/src/test/java/org/jabref/logic/integrity/PagesCheckerBibLatexTest.java +++ b/src/test/java/org/jabref/logic/integrity/PagesCheckerBibLatexTest.java @@ -9,6 +9,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; class PagesCheckerBibLatexTest { @@ -70,4 +71,45 @@ void complainsAboutPPrefix() { void complainsAboutPPPrefix() { assertEquals(Optional.of("should contain a valid page number range"), checker.checkValue("pp. 12-15")); } + + @Test + void bibLaTexAcceptsRangeOfNumbersWithDoubleDash() { + assertEquals(Optional.empty(), checker.checkValue("1--2")); + } + + @Test + void bibLaTexAcceptsOnePageNumber() { + assertEquals(Optional.empty(), checker.checkValue("12")); + } + + @Test + void bibLaTexAcceptsRangeOfNumbersWithSingleDash() { + assertEquals(Optional.empty(), checker.checkValue("1-2")); + } + + @Test + void bibLaTexAcceptsMorePageNumbers() { + assertEquals(Optional.empty(), checker.checkValue("1,2,3")); + } + + @Test + void bibLaTexAcceptsNoSimpleRangeOfNumbers() { + assertEquals(Optional.empty(), checker.checkValue("43+")); + } + + @Test + void bibLaTexDoesNotAcceptMorePageNumbersWithoutComma() { + assertNotEquals(Optional.empty(), checker.checkValue("1 2")); + } + + @Test + void bibLaTexDoesNotAcceptBrackets() { + assertNotEquals(Optional.empty(), checker.checkValue("{1}-{2}")); + } + + @Test + void bibLaTexAcceptsMorePageNumbersWithRangeOfNumbers() { + assertEquals(Optional.empty(), checker.checkValue("7+,41--43,73")); + } + } diff --git a/src/test/java/org/jabref/logic/integrity/PagesCheckerTest.java b/src/test/java/org/jabref/logic/integrity/PagesCheckerTest.java new file mode 100644 index 00000000000..a6c5cd385c2 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/PagesCheckerTest.java @@ -0,0 +1,65 @@ +package org.jabref.logic.integrity; + +import java.util.Optional; + +import org.jabref.model.database.BibDatabaseContext; +import org.jabref.model.database.BibDatabaseMode; + +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.assertNotEquals; + +public class PagesCheckerTest { + + private PagesChecker checker; + + @BeforeEach + void setUp() { + BibDatabaseContext database = new BibDatabaseContext(); + database.setMode(BibDatabaseMode.BIBTEX); + checker = new PagesChecker(database); + } + + @Test + void bibTexAcceptsRangeOfNumbersWithDoubleDash() { + assertEquals(Optional.empty(), checker.checkValue("1--2")); + } + + @Test + void bibTexAcceptsOnePageNumber() { + assertEquals(Optional.empty(), checker.checkValue("12")); + } + + @Test + void bibTexDoesNotAcceptRangeOfNumbersWithSingleDash() { + assertNotEquals(Optional.empty(), checker.checkValue("1-2")); + } + + @Test + void bibTexAcceptsMorePageNumbers() { + assertEquals(Optional.empty(), checker.checkValue("1,2,3")); + } + + @Test + void bibTexAcceptsNoSimpleRangeOfNumbers() { + assertEquals(Optional.empty(), checker.checkValue("43+")); + } + + @Test + void bibTexDoesNotAcceptMorePageNumbersWithoutComma() { + assertNotEquals(Optional.empty(), checker.checkValue("1 2")); + } + + @Test + void bibTexDoesNotAcceptBrackets() { + assertNotEquals(Optional.empty(), checker.checkValue("{1}-{2}")); + } + + @Test + void bibTexAcceptsMorePageNumbersWithRangeOfNumbers() { + assertEquals(Optional.empty(), checker.checkValue("7+,41--43,73")); + } + +} diff --git a/src/test/java/org/jabref/logic/integrity/PersonNamesCheckerTest.java b/src/test/java/org/jabref/logic/integrity/PersonNamesCheckerTest.java index 9baf520aab1..44bdb3465ac 100644 --- a/src/test/java/org/jabref/logic/integrity/PersonNamesCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/PersonNamesCheckerTest.java @@ -1,24 +1,32 @@ package org.jabref.logic.integrity; import java.util.Optional; +import java.util.stream.Stream; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; public class PersonNamesCheckerTest { private PersonNamesChecker checker; + private PersonNamesChecker checkerb; @BeforeEach public void setUp() throws Exception { BibDatabaseContext databaseContext = new BibDatabaseContext(); databaseContext.setMode(BibDatabaseMode.BIBTEX); checker = new PersonNamesChecker(databaseContext); + BibDatabaseContext database = new BibDatabaseContext(); + database.setMode(BibDatabaseMode.BIBLATEX); + checkerb = new PersonNamesChecker(database); } @Test @@ -62,4 +70,28 @@ public void validCorporateNameAndPerson() throws Exception { assertEquals(Optional.empty(), checker.checkValue("{JabRef} and Stefan Kolb")); assertEquals(Optional.empty(), checker.checkValue("{JabRef} and Kolb, Stefan")); } + + @ParameterizedTest + @MethodSource("provideCorrectFormats") + public void authorNameInCorrectFormatsShouldNotComplain(String input) { + assertEquals(Optional.empty(), checkerb.checkValue(input)); + } + + @ParameterizedTest + @MethodSource("provideIncorrectFormats") + public void authorNameInIncorrectFormatsShouldComplain(String input) { + assertNotEquals(Optional.empty(), checkerb.checkValue(input)); + } + + private static Stream provideCorrectFormats() { + return Stream.of("", "Knuth", "Donald E. Knuth and Kurt Cobain and A. Einstein"); + } + + private static Stream provideIncorrectFormats() { + return Stream.of(" Knuth, Donald E. ", + "Knuth, Donald E. and Kurt Cobain and A. Einstein", + ", and Kurt Cobain and A. Einstein", "Donald E. Knuth and Kurt Cobain and ,", + "and Kurt Cobain and A. Einstein", "Donald E. Knuth and Kurt Cobain and"); + } + } diff --git a/src/test/java/org/jabref/logic/integrity/TitleCheckerTest.java b/src/test/java/org/jabref/logic/integrity/TitleCheckerTest.java index 930f1598129..9238fdc73ef 100644 --- a/src/test/java/org/jabref/logic/integrity/TitleCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/TitleCheckerTest.java @@ -14,66 +14,211 @@ public class TitleCheckerTest { private TitleChecker checker; + private TitleChecker checkerBiblatex; @BeforeEach public void setUp() { BibDatabaseContext databaseContext = new BibDatabaseContext(); + BibDatabaseContext databaseBiblatex = new BibDatabaseContext(); databaseContext.setMode(BibDatabaseMode.BIBTEX); checker = new TitleChecker(databaseContext); + databaseBiblatex.setMode(BibDatabaseMode.BIBLATEX); + checkerBiblatex = new TitleChecker(databaseBiblatex); } @Test - public void FirstLetterAsOnlyCapitalLetterInSubTitle2() { + public void firstLetterAsOnlyCapitalLetterInSubTitle2() { assertEquals(Optional.empty(), checker.checkValue("This is a sub title 1: This is a sub title 2")); } @Test - public void NoCapitalLetterInSubTitle2() { + public void noCapitalLetterInSubTitle2() { assertEquals(Optional.empty(), checker.checkValue("This is a sub title 1: this is a sub title 2")); } @Test - public void TwoCapitalLettersInSubTitle2() { + public void twoCapitalLettersInSubTitle2() { assertNotEquals(Optional.empty(), checker.checkValue("This is a sub title 1: This is A sub title 2")); } @Test - public void MiddleLetterAsOnlyCapitalLetterInSubTitle2() { + public void middleLetterAsOnlyCapitalLetterInSubTitle2() { assertNotEquals(Optional.empty(), checker.checkValue("This is a sub title 1: this is A sub title 2")); } @Test - public void TwoCapitalLettersInSubTitle2WithCurlyBrackets() { + public void twoCapitalLettersInSubTitle2WithCurlyBrackets() { assertEquals(Optional.empty(), checker.checkValue("This is a sub title 1: This is {A} sub title 2")); } @Test - public void MiddleLetterAsOnlyCapitalLetterInSubTitle2WithCurlyBrackets() { + public void middleLetterAsOnlyCapitalLetterInSubTitle2WithCurlyBrackets() { assertEquals(Optional.empty(), checker.checkValue("This is a sub title 1: this is {A} sub title 2")); } @Test - public void FirstLetterAsOnlyCapitalLetterInSubTitle2AfterContinuousDelimiters() { + public void firstLetterAsOnlyCapitalLetterInSubTitle2AfterContinuousDelimiters() { assertEquals(Optional.empty(), checker.checkValue("This is a sub title 1...This is a sub title 2")); } @Test - public void MiddleLetterAsOnlyCapitalLetterInSubTitle2AfterContinuousDelimiters() { + public void middleLetterAsOnlyCapitalLetterInSubTitle2AfterContinuousDelimiters() { assertNotEquals(Optional.empty(), checker.checkValue("This is a sub title 1... this is a sub Title 2")); } @Test - public void FirstLetterAsOnlyCapitalLetterInEverySubTitleWithContinuousDelimiters() { + public void firstLetterAsOnlyCapitalLetterInEverySubTitleWithContinuousDelimiters() { assertEquals(Optional.empty(), checker.checkValue("This is; A sub title 1.... This is a sub title 2")); } @Test - public void FirstLetterAsOnlyCapitalLetterInEverySubTitleWithRandomDelimiters() { + public void firstLetterAsOnlyCapitalLetterInEverySubTitleWithRandomDelimiters() { assertEquals(Optional.empty(), checker.checkValue("This!is!!A!Title??")); } @Test - public void MoreThanOneCapitalLetterInSubTitleWithoutCurlyBrackets() { + public void moreThanOneCapitalLetterInSubTitleWithoutCurlyBrackets() { assertNotEquals(Optional.empty(), checker.checkValue("This!is!!A!TitlE??")); } + + @Test + void bibTexAcceptsTitleWithOnlyFirstCapitalLetter() { + assertEquals(Optional.empty(), checker.checkValue("This is a title")); + } + + @Test + void bibTexDoesNotAcceptCapitalLettersInsideTitle() { + assertNotEquals(Optional.empty(), checker.checkValue("This is a Title")); + } + + @Test + void bibTexRemovesCapitalLetterInsideTitle() { + assertEquals(Optional.empty(), checker.checkValue("This is a {T}itle")); + } + + @Test + void bibTexRemovesEverythingInBracketsAndAcceptsNoTitleInput() { + assertEquals(Optional.empty(), checker.checkValue("{This is a Title}")); + } + + @Test + void bibTexRemovesEverythingInBrackets() { + assertEquals(Optional.empty(), checker.checkValue("This is a {Title}")); + } + + @Test + void bibTexAcceptsTitleWithLowercaseFirstLetter() { + assertEquals(Optional.empty(), checker.checkValue("{C}urrent {C}hronicle")); + } + + @Test + void bibTexAcceptsSubTitlesWithOnlyFirstCapitalLetter() { + assertEquals(Optional.empty(), checker.checkValue("This is a sub title 1: This is a sub title 2")); + } + + @Test + void bibTexAcceptsSubTitleWithLowercaseFirstLetter() { + assertEquals(Optional.empty(), checker.checkValue("This is a sub title 1: this is a sub title 2")); + } + + @Test + void bibTexDoesNotAcceptCapitalLettersInsideSubTitle() { + assertNotEquals(Optional.empty(), checker.checkValue("This is a sub title 1: This is A sub title 2")); + } + + @Test + void bibTexRemovesCapitalLetterInsideSubTitle() { + assertEquals(Optional.empty(), checker.checkValue("This is a sub title 1: this is {A} sub title 2")); + } + + @Test + void bibTexSplitsSubTitlesBasedOnDots() { + assertEquals(Optional.empty(), checker.checkValue("This is a sub title 1...This is a sub title 2")); + } + + @Test + void bibTexSplitsSubTitleBasedOnSpecialCharacters() { + assertEquals(Optional.empty(), checker.checkValue("This is; A sub title 1.... This is a sub title 2")); + } + + @Test + void bibTexAcceptsCapitalLetterAfterSpecialCharacter() { + assertEquals(Optional.empty(), checker.checkValue("This!is!!A!Title??")); + } + + @Test + void bibTexAcceptsCapitalLetterOnlyAfterSpecialCharacter() { + assertNotEquals(Optional.empty(), checker.checkValue("This!is!!A!TitlE??")); + } + + @Test + void bibLaTexAcceptsTitleWithOnlyFirstCapitalLetter() { + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This is a title")); + } + + @Test + void bibLaTexAcceptsCapitalLettersInsideTitle() { + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This is a Title")); + } + + @Test + void bibLaTexRemovesCapitalLetterInsideTitle() { + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This is a {T}itle")); + } + + @Test + void bibLaTexRemovesEverythingInBracketsAndAcceptsNoTitleInput() { + assertEquals(Optional.empty(), checkerBiblatex.checkValue("{This is a Title}")); + } + + @Test + void bibLaTexRemovesEverythingInBrackets() { + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This is a {Title}")); + } + + @Test + void bibLaTexAcceptsTitleWithLowercaseFirstLetter() { + assertEquals(Optional.empty(), checkerBiblatex.checkValue("{C}urrent {C}hronicle")); + } + + @Test + void bibLaTexAcceptsSubTitlesWithOnlyFirstCapitalLetter() { + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This is a sub title 1: This is a sub title 2")); + } + + @Test + void bibLaTexAcceptsSubTitleWithLowercaseFirstLetter() { + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This is a sub title 1: this is a sub title 2")); + } + + @Test + void bibLaTexAcceptsCapitalLettersInsideSubTitle() { + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This is a sub title 1: This is A sub title 2")); + } + + @Test + void bibLaTexRemovesCapitalLetterInsideSubTitle() { + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This is a sub title 1: this is {A} sub title 2")); + } + + @Test + void bibLaTexSplitsSubTitlesBasedOnDots() { + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This is a sub title 1...This is a sub title 2")); + } + + @Test + void bibLaTexSplitsSubTitleBasedOnSpecialCharacters() { + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This is; A sub title 1.... This is a sub title 2")); + } + + @Test + void bibLaTexAcceptsCapitalLetterAfterSpecialCharacter() { + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This!is!!A!Title??")); + } + + @Test + void bibLaTexAcceptsCapitalLetterNotOnlyAfterSpecialCharacter() { + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This!is!!A!TitlE??")); + } + } diff --git a/src/test/java/org/jabref/logic/integrity/TypeCheckerTest.java b/src/test/java/org/jabref/logic/integrity/TypeCheckerTest.java new file mode 100644 index 00000000000..3d2f10ac6e9 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/TypeCheckerTest.java @@ -0,0 +1,33 @@ +package org.jabref.logic.integrity; + +import java.util.Collections; +import java.util.List; + +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.StandardField; +import org.jabref.model.entry.types.StandardEntryType; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TypeCheckerTest { + + private final TypeChecker checker = new TypeChecker(); + private BibEntry entry; + + @Test + void inProceedingshasPagesNumbers() { + entry = new BibEntry(StandardEntryType.InProceedings); + entry.setField(StandardField.PAGES, "11--15"); + assertEquals(Collections.emptyList(), checker.check(entry)); + } + + @Test + void proceedingsDoesNotHavePageNumbers() { + entry = new BibEntry(StandardEntryType.Proceedings); + entry.setField(StandardField.PAGES, "11--15"); + assertEquals(List.of(new IntegrityMessage("wrong entry type as proceedings has page numbers", entry, StandardField.PAGES)), checker.check(entry)); + } + +} diff --git a/src/test/java/org/jabref/logic/integrity/UrlCheckerTest.java b/src/test/java/org/jabref/logic/integrity/UrlCheckerTest.java new file mode 100644 index 00000000000..747e2babe41 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/UrlCheckerTest.java @@ -0,0 +1,43 @@ +package org.jabref.logic.integrity; + +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.assertNotEquals; + +public class UrlCheckerTest { + + private final UrlChecker checker = new UrlChecker(); + + @Test + void urlFieldAcceptsHttpAddress() { + assertEquals(Optional.empty(), checker.checkValue("http://www.google.com")); + } + + @Test + void urlFieldAcceptsFullLocalPath() { + assertEquals(Optional.empty(), checker.checkValue("file://c:/asdf/asdf")); + } + + @Test + void urlFieldAcceptsFullPathHttpAddress() { + assertEquals(Optional.empty(), checker.checkValue("http://scikit-learn.org/stable/modules/ensemble.html#random-forests")); + } + + @Test + void urlFieldDoesNotAcceptHttpAddressWithoutTheHttp() { + assertNotEquals(Optional.empty(), checker.checkValue("www.google.com")); + } + + @Test + void urlFieldDoesNotAcceptPartialHttpAddress() { + assertNotEquals(Optional.empty(), checker.checkValue("google.com")); + } + + @Test + void urlFieldDoesNotAcceptPartialLocalPath() { + assertNotEquals(Optional.empty(), checker.checkValue("c:/asdf/asdf")); + } +} diff --git a/src/test/java/org/jabref/logic/integrity/YearCheckerTest.java b/src/test/java/org/jabref/logic/integrity/YearCheckerTest.java new file mode 100644 index 00000000000..89dfc884e5a --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/YearCheckerTest.java @@ -0,0 +1,88 @@ +package org.jabref.logic.integrity; + +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.assertNotEquals; + +public class YearCheckerTest { + + private final YearChecker checker = new YearChecker(); + + @Test + void yearFieldAccepts21stCenturyDate() { + assertEquals(Optional.empty(), checker.checkValue("2014")); + } + + @Test + void yearFieldAccepts20thCenturyDate() { + assertEquals(Optional.empty(), checker.checkValue("1986")); + } + + @Test + void yearFieldAcceptsApproximateDate() { + assertEquals(Optional.empty(), checker.checkValue("around 1986")); + } + + @Test + void yearFieldAcceptsApproximateDateWithParenthesis() { + assertEquals(Optional.empty(), checker.checkValue("(around 1986)")); + } + + @Test + void yearFieldRemovesCommaFromYear() { + assertEquals(Optional.empty(), checker.checkValue("1986,")); + } + + @Test + void yearFieldRemovesBraceAndPercentageFromYear() { + assertEquals(Optional.empty(), checker.checkValue("1986}%")); + } + + @Test + void yearFieldRemovesSpecialCharactersFromYear() { + assertEquals(Optional.empty(), checker.checkValue("1986(){},.;!?<>%&$")); + } + + @Test + void yearFieldDoesNotAcceptStringAsInput() { + assertNotEquals(Optional.empty(), checker.checkValue("abc")); + } + + @Test + void yearFieldDoesNotAcceptDoubleDigitNumber() { + assertNotEquals(Optional.empty(), checker.checkValue("86")); + } + + @Test + void yearFieldDoesNotAcceptTripleDigitNumber() { + assertNotEquals(Optional.empty(), checker.checkValue("204")); + } + + @Test + void yearFieldDoesNotRemoveStringInYear() { + assertNotEquals(Optional.empty(), checker.checkValue("1986a")); + } + + @Test + void yearFieldDoesNotRemoveStringInParenthesis() { + assertNotEquals(Optional.empty(), checker.checkValue("(1986a)")); + } + + @Test + void yearFieldDoesNotRemoveStringBeforeComma() { + assertNotEquals(Optional.empty(), checker.checkValue("1986a,")); + } + + @Test + void yearFieldDoesNotRemoveStringInsideBraceAndPercentage() { + assertNotEquals(Optional.empty(), checker.checkValue("1986}a%")); + } + + @Test + void yearFieldDoesNotRemoveStringBeforeSpecialCharacters() { + assertNotEquals(Optional.empty(), checker.checkValue("1986a(){},.;!?<>%&$")); + } +}