From b9c73fd41747dbd440bd9dbb0a0b1bba627cbfcc Mon Sep 17 00:00:00 2001 From: dimitra-karadima Date: Sat, 4 Apr 2020 19:39:52 +0300 Subject: [PATCH 01/14] Unit tests improvement for #6207 Add the following changes: -remove multiple assert statements in test cases -split each assert statement in different test methods with meaningful test names --- .../logic/integrity/IntegrityCheckTest.java | 143 +++++++++++++++++- 1 file changed, 136 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java b/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java index e166869806d..fd275da3d5d 100644 --- a/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java +++ b/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java @@ -39,40 +39,127 @@ class IntegrityCheckTest { @Test - void testEntryTypeChecks() { + void bibTexAcceptsStandardEntryType() { assertCorrect(withMode(createContext(StandardField.TITLE, "sometitle", StandardEntryType.Article), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexDoesNotAcceptIEEETranEntryType() { assertWrong(withMode(createContext(StandardField.TITLE, "sometitle", IEEETranEntryType.Patent), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibLaTexAcceptsIEEETranEntryType() { assertCorrect((withMode(createContext(StandardField.TITLE, "sometitle", IEEETranEntryType.Patent), BibDatabaseMode.BIBLATEX))); + } + + @Test + void bibLaTexAcceptsStandardEntryType() { assertCorrect(withMode(createContext(StandardField.TITLE, "sometitle", StandardEntryType.Article), BibDatabaseMode.BIBLATEX)); } @Test - void testUrlChecks() { + void urlFieldAcceptsHttpAddress() { assertCorrect(createContext(StandardField.URL, "http://www.google.com")); + } + + @Test + void urlFieldAcceptsFullLocalPath() { assertCorrect(createContext(StandardField.URL, "file://c:/asdf/asdf")); + } + + @Test + void urlFieldAcceptsFullPathHttpAddress() { assertCorrect(createContext(StandardField.URL, "http://scikit-learn.org/stable/modules/ensemble.html#random-forests")); + } + @Test + void urlFieldDoesNotAcceptHttpAddressWithoutTheHttp() { assertWrong(createContext(StandardField.URL, "www.google.com")); + } + + @Test + void urlFieldDoesNotAcceptPartialHttpAddress() { assertWrong(createContext(StandardField.URL, "google.com")); + } + + @Test + void urlFieldDoesNotAcceptPartialLocalPath() { assertWrong(createContext(StandardField.URL, "c:/asdf/asdf")); } @Test - void testYearChecks() { + void yearFieldAccepts21stCenturyDate() { assertCorrect(createContext(StandardField.YEAR, "2014")); + } + + @Test + void yearFieldAccepts20thCenturyDate() { assertCorrect(createContext(StandardField.YEAR, "1986")); + } + + @Test + void yearFieldAcceptsApproximateDate() { assertCorrect(createContext(StandardField.YEAR, "around 1986")); + } + + @Test + void yearFieldAcceptsApproximateDateWithParenthesis() { assertCorrect(createContext(StandardField.YEAR, "(around 1986)")); + } + + @Test + void yearFieldRemovesCommaFromYear() { assertCorrect(createContext(StandardField.YEAR, "1986,")); + } + + @Test + void yearFieldRemovesBraceAndPercentageFromYear() { assertCorrect(createContext(StandardField.YEAR, "1986}%")); + } + + @Test + void yearFieldRemovesSpecialCharactersFromYear() { assertCorrect(createContext(StandardField.YEAR, "1986(){},.;!?<>%&$")); + } + + @Test + void yearFieldDoesNotAcceptStringAsInput() { assertWrong(createContext(StandardField.YEAR, "abc")); + } + + @Test + void yearFieldDoesNotAcceptDoubleDigitNumber() { assertWrong(createContext(StandardField.YEAR, "86")); + } + + @Test + void yearFieldDoesNotAcceptTripleDigitNumber() { assertWrong(createContext(StandardField.YEAR, "204")); + } + + @Test + void yearFieldDoesNotRemoveStringInYear() { assertWrong(createContext(StandardField.YEAR, "1986a")); + } + + @Test + void yearFieldDoesNotRemoveStringInParenthesis() { assertWrong(createContext(StandardField.YEAR, "(1986a)")); + } + + @Test + void yearFieldDoesNotRemoveStringBeforeComma() { assertWrong(createContext(StandardField.YEAR, "1986a,")); + } + + @Test + void yearFieldDoesNotRemoveStringInsideBraceAndPercentage() { assertWrong(createContext(StandardField.YEAR, "1986}a%")); + } + + @Test + void yearFieldDoesNotRemoveStringBeforeSpecialCharacters() { assertWrong(createContext(StandardField.YEAR, "1986a(){},.;!?<>%&$")); } @@ -87,19 +174,39 @@ void testEditionChecks() { 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)); + 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(createContext(StandardField.EDITION, "1")); } @Test - void testNoteChecks() { + void bibTexAcceptsNoteWithFirstCapitalLetter() { assertCorrect(withMode(createContext(StandardField.NOTE, "Lorem ipsum"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexAcceptsNoteWithFirstCapitalLetterAndDoesNotCareAboutTheRest() { assertCorrect(withMode(createContext(StandardField.NOTE, "Lorem ipsum? 10"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexDoesNotAcceptFirstLowercaseLetter() { assertWrong(withMode(createContext(StandardField.NOTE, "lorem ipsum"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibLaTexAcceptsNoteWithFirstCapitalLetter() { assertCorrect(withMode(createContext(StandardField.NOTE, "Lorem ipsum"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexAcceptsUrl() { assertCorrect(withMode(createContext(StandardField.NOTE, "\\url{someurl}"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibLaTexAcceptsFirstLowercaseLetter() { assertCorrect(withMode(createContext(StandardField.NOTE, "lorem ipsum"), BibDatabaseMode.BIBLATEX)); } @@ -186,6 +293,17 @@ void testTitleChecks() { 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)); @@ -194,6 +312,17 @@ void testTitleChecks() { 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)); } @Test @@ -356,8 +485,8 @@ void testEntryIsUnchangedAfterChecks() { @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 ⊕")); + assertWrong(createContext(StandardField.MONTH, "Umlauts are nΓ¶t Γ¤llowed")); + assertWrong(createContext(StandardField.AUTHOR, "Some unicode β�•")); } private BibDatabaseContext createContext(Field field, String value, EntryType type) { From b37a9213b36a0d52df74b710948c67ae0db536e1 Mon Sep 17 00:00:00 2001 From: dimitra-karadima Date: Sat, 4 Apr 2020 20:00:01 +0300 Subject: [PATCH 02/14] Fix some problems Fix some encoding problems Fix merge conflict with the master branch --- .../org/jabref/logic/integrity/IntegrityCheckTest.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java b/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java index fd275da3d5d..4013d997ce5 100644 --- a/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java +++ b/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java @@ -173,8 +173,7 @@ void testEditionChecks() { 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, "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(createContext(StandardField.EDITION, "1")); @@ -485,8 +484,8 @@ void testEntryIsUnchangedAfterChecks() { @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 β�•")); + assertWrong(createContext(StandardField.MONTH, "Umlauts are nöt ällowed")); + assertWrong(createContext(StandardField.AUTHOR, "Some unicode ⊕")); } private BibDatabaseContext createContext(Field field, String value, EntryType type) { From 02e8f678d2bb99c6009e1d88f7e92422d4766f58 Mon Sep 17 00:00:00 2001 From: dimitra-karadima Date: Sun, 12 Apr 2020 17:49:21 +0300 Subject: [PATCH 03/14] Add more unit tests Add the following changes: -move tests from IntegrityCheckTest to the appropriate Test classes -remove multiple assert statements in different test methods -fix the capitalization in TitleCheckerTest --- .../integrity/ASCIICharacterCheckerTest.java | 24 + .../integrity/AbbreviationCheckerTest.java | 24 + .../logic/integrity/BibStringCheckerTest.java | 33 ++ .../logic/integrity/BibtexKeyCheckerTest.java | 27 ++ .../logic/integrity/BooktitleCheckerTest.java | 20 + .../logic/integrity/BracketCheckerTest.java | 39 ++ .../integrity/DOIValidityCheckerTest.java | 29 ++ .../logic/integrity/EditionCheckerTest.java | 47 ++ .../logic/integrity/FileCheckerTest.java | 48 ++ .../integrity/HTMLCharacterCheckerTest.java | 40 ++ .../integrity/HowPublishedCheckerTest.java | 40 ++ .../logic/integrity/ISBNCheckerTest.java | 29 ++ .../logic/integrity/ISSNCheckerTest.java | 29 ++ .../logic/integrity/IntegrityCheckTest.java | 431 +----------------- .../JournalInAbbreviationListCheckerTest.java | 29 ++ .../logic/integrity/MonthCheckerTest.java | 65 +++ .../logic/integrity/NoteCheckerTest.java | 40 ++ .../logic/integrity/PagesCheckerTest.java | 90 ++++ .../integrity/PersonNamesCheckerTest.java | 68 +++ .../logic/integrity/TitleCheckerTest.java | 164 ++++++- .../logic/integrity/TypeCheckerTest.java | 20 + .../logic/integrity/UrlCheckerTest.java | 37 ++ .../logic/integrity/YearCheckerTest.java | 83 ++++ 23 files changed, 1023 insertions(+), 433 deletions(-) create mode 100644 src/test/java/org/jabref/logic/integrity/ASCIICharacterCheckerTest.java create mode 100644 src/test/java/org/jabref/logic/integrity/BibStringCheckerTest.java create mode 100644 src/test/java/org/jabref/logic/integrity/BibtexKeyCheckerTest.java create mode 100644 src/test/java/org/jabref/logic/integrity/BooktitleCheckerTest.java create mode 100644 src/test/java/org/jabref/logic/integrity/BracketCheckerTest.java create mode 100644 src/test/java/org/jabref/logic/integrity/DOIValidityCheckerTest.java create mode 100644 src/test/java/org/jabref/logic/integrity/FileCheckerTest.java create mode 100644 src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java create mode 100644 src/test/java/org/jabref/logic/integrity/HowPublishedCheckerTest.java create mode 100644 src/test/java/org/jabref/logic/integrity/ISBNCheckerTest.java create mode 100644 src/test/java/org/jabref/logic/integrity/ISSNCheckerTest.java create mode 100644 src/test/java/org/jabref/logic/integrity/JournalInAbbreviationListCheckerTest.java create mode 100644 src/test/java/org/jabref/logic/integrity/MonthCheckerTest.java create mode 100644 src/test/java/org/jabref/logic/integrity/NoteCheckerTest.java create mode 100644 src/test/java/org/jabref/logic/integrity/PagesCheckerTest.java create mode 100644 src/test/java/org/jabref/logic/integrity/TypeCheckerTest.java create mode 100644 src/test/java/org/jabref/logic/integrity/UrlCheckerTest.java create mode 100644 src/test/java/org/jabref/logic/integrity/YearCheckerTest.java 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..747bdc42fd2 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/ASCIICharacterCheckerTest.java @@ -0,0 +1,24 @@ +package org.jabref.logic.integrity; + +import org.jabref.model.entry.field.StandardField; + +import org.junit.jupiter.api.Test; + +public class ASCIICharacterCheckerTest { + + @Test + void fieldAcceptsASCIICharacters() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.TITLE, "Only ascii characters!'@12")); + } + + @Test + void fieldDoesNotAcceptUmlauts() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.MONTH, "Umlauts are nöt ällowed")); + } + + @Test + void fieldDoesNotAcceptUnicode() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.AUTHOR, "Some unicode ⊕")); + } + +} diff --git a/src/test/java/org/jabref/logic/integrity/AbbreviationCheckerTest.java b/src/test/java/org/jabref/logic/integrity/AbbreviationCheckerTest.java index 033bdbe98d1..a912969f37b 100644 --- a/src/test/java/org/jabref/logic/integrity/AbbreviationCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/AbbreviationCheckerTest.java @@ -1,9 +1,12 @@ package org.jabref.logic.integrity; +import java.util.Arrays; import java.util.Optional; import org.jabref.logic.journals.Abbreviation; import org.jabref.logic.journals.JournalAbbreviationRepository; +import org.jabref.model.entry.field.Field; +import org.jabref.model.entry.field.StandardField; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -32,4 +35,25 @@ void checkValueDoesNotComplainAboutJournalNameThatHasSameAbbreviation() { abbreviationRepository.addEntry(new Abbreviation("Journal", "Journal")); assertEquals(Optional.empty(), checker.checkValue("Journal")); } + + @Test + void journalNameAcceptsFullForm() { + for (Field field : Arrays.asList(StandardField.BOOKTITLE, StandardField.JOURNAL)) { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(field, "IEEE Software")); + } + } + + @Test + void journalNameAcceptsEmptyInput() { + for (Field field : Arrays.asList(StandardField.BOOKTITLE, StandardField.JOURNAL)) { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(field, "")); + } + } + + @Test + void journalNameDoesNotAcceptNonAbbreviatedForm() { + for (Field field : Arrays.asList(StandardField.BOOKTITLE, StandardField.JOURNAL)) { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(field, "IEEE SW")); + } + } } 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..83fb9a6ff4b --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/BibStringCheckerTest.java @@ -0,0 +1,33 @@ +package org.jabref.logic.integrity; + +import org.jabref.model.entry.field.StandardField; + +import org.junit.jupiter.api.Test; + +public class BibStringCheckerTest { + + @Test + void fieldAcceptsNoHashMarks() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.TITLE, "Not a single hash mark")); + } + + @Test + void monthAcceptsEvenNumberOfHashMarks() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.MONTH, "#jan#")); + } + + @Test + void authorAcceptsEvenNumberOfHashMarks() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.AUTHOR, "#einstein# and #newton#")); + } + + @Test + void monthDoesNotAcceptOddNumberOfHashMarks() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.MONTH, "#jan")); + } + + @Test + void authorDoesNotAcceptOddNumberOfHashMarks() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.AUTHOR, "#einstein# #amp; #newton#")); + } +} 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..64180cd5fa8 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/BibtexKeyCheckerTest.java @@ -0,0 +1,27 @@ +package org.jabref.logic.integrity; + +import org.jabref.model.database.BibDatabaseContext; +import org.jabref.model.entry.field.InternalField; +import org.jabref.model.entry.field.StandardField; + +import org.junit.jupiter.api.Test; + +public class BibtexKeyCheckerTest { + + @Test + void bibTexAcceptsKeyFromAuthorAndYear() { + final BibDatabaseContext correctContext = IntegrityCheckTest.createContext(InternalField.KEY_FIELD, "Knuth2014"); + correctContext.getDatabase().getEntries().get(0).setField(StandardField.AUTHOR, "Knuth"); + correctContext.getDatabase().getEntries().get(0).setField(StandardField.YEAR, "2014"); + IntegrityCheckTest.assertCorrect(correctContext); + } + + @Test + void bibtexDooesNotAcceptRandomKey() { + final BibDatabaseContext wrongContext = IntegrityCheckTest.createContext(InternalField.KEY_FIELD, "Knuth2014a"); + wrongContext.getDatabase().getEntries().get(0).setField(StandardField.AUTHOR, "Knuth"); + wrongContext.getDatabase().getEntries().get(0).setField(StandardField.YEAR, "2014"); + IntegrityCheckTest.assertWrong(wrongContext); + } + +} 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..aa721a42d9c --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/BooktitleCheckerTest.java @@ -0,0 +1,20 @@ +package org.jabref.logic.integrity; + +import org.jabref.model.entry.field.StandardField; +import org.jabref.model.entry.types.StandardEntryType; + +import org.junit.jupiter.api.Test; + +public class BooktitleCheckerTest { + + @Test + void booktitleAcceptsIfItDoesNotEndWithConferenceOn() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.BOOKTITLE, "2014 Fourth International Conference on Digital Information and Communication Technology and it's Applications (DICTAP)", StandardEntryType.Proceedings)); + } + + @Test + void booktitleDoesNotAcceptsIfItEndsWithConferenceOn() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.BOOKTITLE, "Digital Information and Communication Technology and it's Applications (DICTAP), 2014 Fourth International Conference on", StandardEntryType.Proceedings)); + } + +} 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..a5972d3318e --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/BracketCheckerTest.java @@ -0,0 +1,39 @@ +package org.jabref.logic.integrity; + +import org.jabref.model.entry.field.StandardField; + +import org.junit.jupiter.api.Test; + +public class BracketCheckerTest { + + @Test + void fieldAcceptsNoBrackets() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.TITLE, "x")); + } + + @Test + void fieldAcceptsEvenNumberOfBrackets() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.TITLE, "{x}")); + } + + @Test + void fieldAcceptsExpectedBracket() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.TITLE, "{x}x{}x{{}}")); + } + + @Test + void fieldDoesNotAcceptOddNumberOfBrackets() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.TITLE, "{x}x{}}x{{}}")); + } + + @Test + void fieldDoesNotAcceptUnexpectedClosingBracket() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.TITLE, "}")); + } + + @Test + void fieldDoesNotAcceptUnexpectedOpeningBracket() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.TITLE, "{")); + } + +} 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..2305fa9a082 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/DOIValidityCheckerTest.java @@ -0,0 +1,29 @@ +package org.jabref.logic.integrity; + +import org.jabref.model.entry.field.StandardField; + +import org.junit.jupiter.api.Test; + +public class DOIValidityCheckerTest { + + @Test + void doiAcceptsValidInput() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.DOI, "10.1023/A:1022883727209")); + } + + @Test + void doiAcceptsValidInputWithNotOnlyNumbers() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.DOI, "10.17487/rfc1436")); + } + + @Test + void doiAcceptsValidInputNoMatterTheLengthOfTheDOIName() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.DOI, "10.1002/(SICI)1097-4571(199205)43:4<284::AID-ASI3>3.0.CO;2-0")); + } + + @Test + void doiDoesNotAcceptInvalidInput() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.DOI, "asdf")); + } + +} diff --git a/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java b/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java index 9ec01b020fe..8f86cba6fbb 100644 --- a/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java @@ -3,6 +3,8 @@ import java.util.Optional; import org.jabref.model.database.BibDatabaseContext; +import org.jabref.model.database.BibDatabaseMode; +import org.jabref.model.entry.field.StandardField; import org.junit.jupiter.api.Test; @@ -42,4 +44,49 @@ void editionCheckerDoesNotComplainIfAllowIntegerEditionIsEnabled() { assertEquals(Optional.empty(), editionChecker.checkValue("2")); } + @Test + void bibTexAcceptsOrdinalNumberInWordsWithCapitalFirstLetter() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.EDITION, "Second"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexDoesNotAcceptOrdinalNumberInWordsWithNonCapitalFirstLetter() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.EDITION, "second"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexDoesNotAcceptIntegerInputInEdition() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.EDITION, "2"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexNowAcceptsIntegerInputInEdition() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.EDITION, "2"), BibDatabaseMode.BIBTEX), true); + } + + @Test + void bibTexDoesNotAcceptOrdinalNumberInNumbers() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.EDITION, "2nd"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibLaTexAcceptsEditionWithCapitalFirstLetter() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.EDITION, "Edition 2000"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexAcceptsIntegerInputInEdition() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.EDITION, "2"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexAcceptsEditionAsLiteralString() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.EDITION, "Third, revised and expanded edition"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexDoesNotAcceptOrdinalNumberInNumbers() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.EDITION, "2nd"), BibDatabaseMode.BIBLATEX)); + } + } diff --git a/src/test/java/org/jabref/logic/integrity/FileCheckerTest.java b/src/test/java/org/jabref/logic/integrity/FileCheckerTest.java new file mode 100644 index 00000000000..43bc69f9139 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/FileCheckerTest.java @@ -0,0 +1,48 @@ +package org.jabref.logic.integrity; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Optional; + +import org.jabref.model.database.BibDatabaseContext; +import org.jabref.model.database.BibDatabaseMode; +import org.jabref.model.entry.field.StandardField; +import org.jabref.model.metadata.MetaData; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.mockito.Mockito; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; + +public class FileCheckerTest { + + @Test + void testFileChecks() { + MetaData metaData = mock(MetaData.class); + Mockito.when(metaData.getDefaultFileDirectory()).thenReturn(Optional.of(".")); + Mockito.when(metaData.getUserFileDirectory(any(String.class))).thenReturn(Optional.empty()); + // FIXME: must be set as checkBibtexDatabase only activates title checker based on database mode + Mockito.when(metaData.getMode()).thenReturn(Optional.of(BibDatabaseMode.BIBTEX)); + + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.FILE, ":build.gradle:gradle", metaData)); + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.FILE, "description:build.gradle:gradle", metaData)); + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.FILE, ":asflakjfwofja:PDF", metaData)); + } + + @Test + void fileCheckFindsFilesRelativeToBibFile(@TempDir Path testFolder) throws IOException { + Path bibFile = testFolder.resolve("lit.bib"); + Files.createFile(bibFile); + Path pdfFile = testFolder.resolve("file.pdf"); + Files.createFile(pdfFile); + + BibDatabaseContext databaseContext = IntegrityCheckTest.createContext(StandardField.FILE, ":file.pdf:PDF"); + databaseContext.setDatabasePath(bibFile); + + IntegrityCheckTest.assertCorrect(databaseContext); + } + +} 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..ee9d86b02ad --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java @@ -0,0 +1,40 @@ +package org.jabref.logic.integrity; + +import org.jabref.model.entry.field.StandardField; + +import org.junit.jupiter.api.Test; + +public class HTMLCharacterCheckerTest { + + @Test + void titleAcceptsNonHTMLEncodedCharacters() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.TITLE, "Not a single {HTML} character")); + } + + @Test + void monthAcceptsNonHTMLEncodedCharacters() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.MONTH, "#jan#")); + } + + @Test + void authorAcceptsNonHTMLEncodedCharacters() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.AUTHOR, "A. Einstein and I. Newton")); + } + + @Test + void urlAcceptsNonHTMLEncodedCharacters() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.URL, "http://www.thinkmind.org/index.php?view=article&articleid=cloud_computing_2013_1_20_20130")); + } + + @Test + void authorDoesNotAcceptHTMLEncodedCharacters() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.AUTHOR, "Lenhard, Jãrg")); + } + + @Test + void journalDoesNotAcceptHTMLEncodedCharacters() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.JOURNAL, "Ärling Ström for – ‱")); + } + + +} 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..8428a2631c1 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/HowPublishedCheckerTest.java @@ -0,0 +1,40 @@ +package org.jabref.logic.integrity; + +import org.jabref.model.database.BibDatabaseMode; +import org.jabref.model.entry.field.StandardField; + +import org.junit.jupiter.api.Test; + +public class HowPublishedCheckerTest { + + @Test + void bibTexAcceptsStringWithCapitalFirstLetter() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.HOWPUBLISHED, "Lorem ipsum"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexDoesNotCareAboutSpecialChracters() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.HOWPUBLISHED, "Lorem ipsum? 10"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexDoesNotAcceptStringWithLowercaseFirstLetter() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.HOWPUBLISHED, "lorem ipsum"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexAcceptsUrl() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.HOWPUBLISHED, "\\url{someurl}"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibLaTexAcceptsStringWithCapitalFirstLetter() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.HOWPUBLISHED, "Lorem ipsum"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexAcceptsStringWithLowercaseFirstLetter() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.HOWPUBLISHED, "lorem ipsum"), BibDatabaseMode.BIBLATEX)); + } + +} 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..8b8c98a8caf --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/ISBNCheckerTest.java @@ -0,0 +1,29 @@ +package org.jabref.logic.integrity; + +import org.jabref.model.entry.field.StandardField; + +import org.junit.jupiter.api.Test; + +public class ISBNCheckerTest { + + @Test + void isbnAcceptsValidInput() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.ISBN, "0-201-53082-1")); + } + + @Test + void isbnAcceptsNumbersAndCharacters() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.ISBN, "0-9752298-0-X")); + } + + @Test + void isbnDoesNotAcceptRandomInput() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.ISBN, "Some other stuff")); + } + + @Test + void isbnDoesNotAcceptInvalidInput() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.ISBN, "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..62a7435879c --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/ISSNCheckerTest.java @@ -0,0 +1,29 @@ +package org.jabref.logic.integrity; + +import org.jabref.model.entry.field.StandardField; + +import org.junit.jupiter.api.Test; + +public class ISSNCheckerTest { + + @Test + void issnAcceptsValidInput() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.ISSN, "0020-7217")); + } + + @Test + void issnAcceptsNumbersAndCharacters() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.ISSN, "2434-561x")); + } + + @Test + void issnDoesNotAcceptRandomInput() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.ISSN, "Some other stuff")); + } + + @Test + void issnDoesNotAcceptInvalidInput() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.ISSN, "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 f3dc955b768..f1be2b718dc 100644 --- a/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java +++ b/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java @@ -1,12 +1,7 @@ package org.jabref.logic.integrity; -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 org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; @@ -19,7 +14,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; @@ -28,12 +22,8 @@ import org.jabref.model.metadata.MetaData; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.io.TempDir; -import org.mockito.Mockito; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; class IntegrityCheckTest { @@ -58,402 +48,6 @@ void bibLaTexAcceptsStandardEntryType() { assertCorrect(withMode(createContext(StandardField.TITLE, "sometitle", StandardEntryType.Article), BibDatabaseMode.BIBLATEX)); } - @Test - void urlFieldAcceptsHttpAddress() { - assertCorrect(createContext(StandardField.URL, "http://www.google.com")); - } - - @Test - void urlFieldAcceptsFullLocalPath() { - assertCorrect(createContext(StandardField.URL, "file://c:/asdf/asdf")); - } - - @Test - void urlFieldAcceptsFullPathHttpAddress() { - assertCorrect(createContext(StandardField.URL, "http://scikit-learn.org/stable/modules/ensemble.html#random-forests")); - } - - @Test - void urlFieldDoesNotAcceptHttpAddressWithoutTheHttp() { - assertWrong(createContext(StandardField.URL, "www.google.com")); - } - - @Test - void urlFieldDoesNotAcceptPartialHttpAddress() { - assertWrong(createContext(StandardField.URL, "google.com")); - } - - @Test - void urlFieldDoesNotAcceptPartialLocalPath() { - assertWrong(createContext(StandardField.URL, "c:/asdf/asdf")); - } - - @Test - void yearFieldAccepts21stCenturyDate() { - assertCorrect(createContext(StandardField.YEAR, "2014")); - } - - @Test - void yearFieldAccepts20thCenturyDate() { - assertCorrect(createContext(StandardField.YEAR, "1986")); - } - - @Test - void yearFieldAcceptsApproximateDate() { - assertCorrect(createContext(StandardField.YEAR, "around 1986")); - } - - @Test - void yearFieldAcceptsApproximateDateWithParenthesis() { - assertCorrect(createContext(StandardField.YEAR, "(around 1986)")); - } - - @Test - void yearFieldRemovesCommaFromYear() { - assertCorrect(createContext(StandardField.YEAR, "1986,")); - } - - @Test - void yearFieldRemovesBraceAndPercentageFromYear() { - assertCorrect(createContext(StandardField.YEAR, "1986}%")); - } - - @Test - void yearFieldRemovesSpecialCharactersFromYear() { - assertCorrect(createContext(StandardField.YEAR, "1986(){},.;!?<>%&$")); - } - - @Test - void yearFieldDoesNotAcceptStringAsInput() { - assertWrong(createContext(StandardField.YEAR, "abc")); - } - - @Test - void yearFieldDoesNotAcceptDoubleDigitNumber() { - assertWrong(createContext(StandardField.YEAR, "86")); - } - - @Test - void yearFieldDoesNotAcceptTripleDigitNumber() { - assertWrong(createContext(StandardField.YEAR, "204")); - } - - @Test - void yearFieldDoesNotRemoveStringInYear() { - assertWrong(createContext(StandardField.YEAR, "1986a")); - } - - @Test - void yearFieldDoesNotRemoveStringInParenthesis() { - assertWrong(createContext(StandardField.YEAR, "(1986a)")); - } - - @Test - void yearFieldDoesNotRemoveStringBeforeComma() { - assertWrong(createContext(StandardField.YEAR, "1986a,")); - } - - @Test - void yearFieldDoesNotRemoveStringInsideBraceAndPercentage() { - assertWrong(createContext(StandardField.YEAR, "1986}a%")); - } - - @Test - void yearFieldDoesNotRemoveStringBeforeSpecialCharacters() { - 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 bibTexAcceptsNoteWithFirstCapitalLetter() { - assertCorrect(withMode(createContext(StandardField.NOTE, "Lorem ipsum"), BibDatabaseMode.BIBTEX)); - } - - @Test - void bibTexAcceptsNoteWithFirstCapitalLetterAndDoesNotCareAboutTheRest() { - assertCorrect(withMode(createContext(StandardField.NOTE, "Lorem ipsum? 10"), BibDatabaseMode.BIBTEX)); - } - - @Test - void bibTexDoesNotAcceptFirstLowercaseLetter() { - assertWrong(withMode(createContext(StandardField.NOTE, "lorem ipsum"), BibDatabaseMode.BIBTEX)); - } - - @Test - void bibLaTexAcceptsNoteWithFirstCapitalLetter() { - assertCorrect(withMode(createContext(StandardField.NOTE, "Lorem ipsum"), BibDatabaseMode.BIBLATEX)); - } - - @Test - void bibLaTexAcceptsUrl() { - assertCorrect(withMode(createContext(StandardField.NOTE, "\\url{someurl}"), BibDatabaseMode.BIBTEX)); - } - - @Test - void bibLaTexAcceptsFirstLowercaseLetter() { - 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)); - } - - @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); - } - - @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, "{")); - } - - @Test - void testAuthorNameChecks() { - 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)); - } - } - - @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)); - } - - @Test - void testAbbreviationChecks() { - for (Field field : Arrays.asList(StandardField.BOOKTITLE, StandardField.JOURNAL)) { - assertCorrect(createContext(field, "IEEE Software")); - assertCorrect(createContext(field, "")); - assertWrong(createContext(field, "IEEE SW")); - } - } - - @Test - void testJournalIsKnownInAbbreviationList() { - assertCorrect(createContext(StandardField.JOURNAL, "IEEE Software")); - assertWrong(createContext(StandardField.JOURNAL, "IEEE Whocares")); - } - - @Test - void testFileChecks() { - MetaData metaData = mock(MetaData.class); - Mockito.when(metaData.getDefaultFileDirectory()).thenReturn(Optional.of(".")); - Mockito.when(metaData.getUserFileDirectory(any(String.class))).thenReturn(Optional.empty()); - // FIXME: must be set as checkBibtexDatabase only activates title checker based on database mode - Mockito.when(metaData.getMode()).thenReturn(Optional.of(BibDatabaseMode.BIBTEX)); - - assertCorrect(createContext(StandardField.FILE, ":build.gradle:gradle", metaData)); - assertCorrect(createContext(StandardField.FILE, "description:build.gradle:gradle", metaData)); - assertWrong(createContext(StandardField.FILE, ":asflakjfwofja:PDF", metaData)); - } - - @Test - void fileCheckFindsFilesRelativeToBibFile(@TempDir Path testFolder) throws IOException { - Path bibFile = testFolder.resolve("lit.bib"); - Files.createFile(bibFile); - Path pdfFile = testFolder.resolve("file.pdf"); - Files.createFile(pdfFile); - - BibDatabaseContext databaseContext = createContext(StandardField.FILE, ":file.pdf:PDF"); - databaseContext.setDatabasePath(bibFile); - - 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(); @@ -481,14 +75,7 @@ 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) { + protected static BibDatabaseContext createContext(Field field, String value, EntryType type) { BibEntry entry = new BibEntry(); entry.setField(field, value); entry.setType(type); @@ -497,7 +84,7 @@ private BibDatabaseContext createContext(Field field, String value, EntryType ty return new BibDatabaseContext(bibDatabase); } - private BibDatabaseContext createContext(Field field, String value, MetaData metaData) { + protected static BibDatabaseContext createContext(Field field, String value, MetaData metaData) { BibEntry entry = new BibEntry(); entry.setField(field, value); BibDatabase bibDatabase = new BibDatabase(); @@ -505,13 +92,13 @@ private BibDatabaseContext createContext(Field field, String value, MetaData met return new BibDatabaseContext(bibDatabase, metaData); } - private BibDatabaseContext createContext(Field field, String value) { + protected static BibDatabaseContext createContext(Field field, String value) { MetaData metaData = new MetaData(); metaData.setMode(BibDatabaseMode.BIBTEX); return createContext(field, value, metaData); } - private void assertWrong(BibDatabaseContext context) { + protected static void assertWrong(BibDatabaseContext context) { List messages = new IntegrityCheck(context, mock(FilePreferences.class), createBibtexKeyPatternPreferences(), @@ -520,7 +107,7 @@ private void assertWrong(BibDatabaseContext context) { assertNotEquals(Collections.emptyList(), messages); } - private void assertCorrect(BibDatabaseContext context) { + protected static void assertCorrect(BibDatabaseContext context) { List messages = new IntegrityCheck(context, mock(FilePreferences.class), createBibtexKeyPatternPreferences(), @@ -529,7 +116,7 @@ private void assertCorrect(BibDatabaseContext context) { assertEquals(Collections.emptyList(), messages); } - private void assertCorrect(BibDatabaseContext context, boolean allowIntegerEdition) { + protected static void assertCorrect(BibDatabaseContext context, boolean allowIntegerEdition) { List messages = new IntegrityCheck(context, mock(FilePreferences.class), createBibtexKeyPatternPreferences(), @@ -539,7 +126,7 @@ private void assertCorrect(BibDatabaseContext context, boolean allowIntegerEditi assertEquals(Collections.emptyList(), messages); } - private BibtexKeyPatternPreferences createBibtexKeyPatternPreferences() { + private static BibtexKeyPatternPreferences createBibtexKeyPatternPreferences() { final GlobalBibtexKeyPattern keyPattern = GlobalBibtexKeyPattern.fromPattern("[auth][year]"); return new BibtexKeyPatternPreferences( "", @@ -551,8 +138,8 @@ private BibtexKeyPatternPreferences createBibtexKeyPatternPreferences() { ','); } - private BibDatabaseContext withMode(BibDatabaseContext context, BibDatabaseMode mode) { + protected static BibDatabaseContext withMode(BibDatabaseContext context, BibDatabaseMode mode) { context.setMode(mode); return context; } -} +} \ No newline at end of file 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..c50d216d1bc --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/JournalInAbbreviationListCheckerTest.java @@ -0,0 +1,29 @@ +package org.jabref.logic.integrity; + +import org.jabref.model.database.BibDatabaseMode; +import org.jabref.model.entry.field.StandardField; + +import org.junit.jupiter.api.Test; + +public class JournalInAbbreviationListCheckerTest { + + @Test + void journalAcceptsNameInTheList() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.JOURNAL, "IEEE Software")); + } + + @Test + void journalDoesNotAcceptNameNotInList() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.JOURNAL, "IEEE Whocares")); + } + + @Test + void bibLaTexDoesNotAcceptRandomInputInTitle() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.JOURNALTITLE, "A journal"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibTexDoesNotAcceptRandomInputInTitle() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.JOURNAL, "A journal"), BibDatabaseMode.BIBTEX)); + } +} 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..21382742642 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/MonthCheckerTest.java @@ -0,0 +1,65 @@ +package org.jabref.logic.integrity; + +import org.jabref.model.database.BibDatabaseMode; +import org.jabref.model.entry.field.StandardField; + +import org.junit.jupiter.api.Test; + +public class MonthCheckerTest { + + @Test + void bibTexAcceptsThreeLetterAbbreviationsWithHashMarks() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.MONTH, "#mar#"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexDoesNotAcceptWhateverThreeLetterAbbreviations() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.MONTH, "#bla#"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexDoesNotAcceptThreeLetterAbbreviationsWithNoHashMarks() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.MONTH, "Dec"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexDoesNotAcceptFullInput() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.MONTH, "December"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexDoesNotAcceptRandomString() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.MONTH, "Lorem"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexDoesNotAcceptInteger() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.MONTH, "10"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibLaTexAcceptsThreeLetterAbbreviationsWithHashMarks() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.MONTH, "#jan#"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexDoesNotAcceptThreeLetterAbbreviationsWithNoHashMarks() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.MONTH, "jan"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexDoesNotAcceptFullInput() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.MONTH, "January"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexDoesNotAcceptRandomString() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.MONTH, "Lorem"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexAcceptsInteger() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.MONTH, "10"), BibDatabaseMode.BIBLATEX)); + + } +} 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..cc291e88f13 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/NoteCheckerTest.java @@ -0,0 +1,40 @@ +package org.jabref.logic.integrity; + +import org.jabref.model.database.BibDatabaseMode; +import org.jabref.model.entry.field.StandardField; + +import org.junit.jupiter.api.Test; + +public class NoteCheckerTest { + + @Test + void bibTexAcceptsNoteWithFirstCapitalLetter() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.NOTE, "Lorem ipsum"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexAcceptsNoteWithFirstCapitalLetterAndDoesNotCareAboutTheRest() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.NOTE, "Lorem ipsum? 10"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexDoesNotAcceptFirstLowercaseLetter() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.NOTE, "lorem ipsum"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibLaTexAcceptsNoteWithFirstCapitalLetter() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.NOTE, "Lorem ipsum"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexAcceptsUrl() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.NOTE, "\\url{someurl}"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibLaTexAcceptsFirstLowercaseLetter() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.NOTE, "lorem ipsum"), BibDatabaseMode.BIBLATEX)); + } + +} 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..7b724c7b0b0 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/PagesCheckerTest.java @@ -0,0 +1,90 @@ +package org.jabref.logic.integrity; + +import org.jabref.model.database.BibDatabaseMode; +import org.jabref.model.entry.field.StandardField; + +import org.junit.jupiter.api.Test; + +public class PagesCheckerTest { + + @Test + void bibTexAcceptsRangeOfNumbersWithDoubleDash() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.PAGES, "1--2")); + } + + @Test + void bibTexAcceptsOnePageNumber() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.PAGES, "12")); + } + + @Test + void bibTexDoesNotAcceptRangeOfNumbersWithSingleDash() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.PAGES, "1-2")); + } + + @Test + void bibTexAcceptsMorePageNumbers() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.PAGES, "1,2,3")); + } + + @Test + void bibTexAcceptsNoSimpleRangeOfNumbers() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.PAGES, "43+")); + } + + @Test + void bibTexDoesNotAcceptMorePageNumbersWithoutComma() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.PAGES, "1 2")); + } + + @Test + void bibTexDoesNotAcceptBrackets() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.PAGES, "{1}-{2}")); + } + + @Test + void bibTexAcceptsMorePageNumbersWithRangeOfNumbers() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.PAGES, "7+,41--43,73")); + } + + @Test + void bibLaTexAcceptsRangeOfNumbersWithDoubleDash() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.PAGES, "1--2"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexAcceptsOnePageNumber() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.PAGES, "12"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexAcceptsRangeOfNumbersWithSingleDash() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.PAGES, "1-2"), BibDatabaseMode.BIBLATEX)); // only diff to bibtex + } + + @Test + void bibLaTexAcceptsMorePageNumbers() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.PAGES, "1,2,3"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexAcceptsNoSimpleRangeOfNumbers() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.PAGES, "43+"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexDoesNotAcceptMorePageNumbersWithoutComma() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.PAGES, "1 2"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexDoesNotAcceptBrackets() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.PAGES, "{1}-{2}"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexAcceptsMorePageNumbersWithRangeOfNumbers() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.PAGES, "7+,41--43,73"), BibDatabaseMode.BIBLATEX)); + } + +} diff --git a/src/test/java/org/jabref/logic/integrity/PersonNamesCheckerTest.java b/src/test/java/org/jabref/logic/integrity/PersonNamesCheckerTest.java index 9baf520aab1..6cd9661790d 100644 --- a/src/test/java/org/jabref/logic/integrity/PersonNamesCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/PersonNamesCheckerTest.java @@ -4,6 +4,8 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; +import org.jabref.model.entry.field.Field; +import org.jabref.model.entry.field.FieldFactory; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -62,4 +64,70 @@ public void validCorporateNameAndPerson() throws Exception { assertEquals(Optional.empty(), checker.checkValue("{JabRef} and Stefan Kolb")); assertEquals(Optional.empty(), checker.checkValue("{JabRef} and Kolb, Stefan")); } + + @Test + void authorAcceptsVoidInput() { + 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 + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(field, ""), BibDatabaseMode.BIBLATEX)); + } + } + + @Test + void authorAcceptsLastNameOnly() { + for (Field field : FieldFactory.getPersonNameFields()) { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(field, "Knuth"), BibDatabaseMode.BIBLATEX)); + } + } + + @Test + void authorDoesNotAcceptSpacesBeforeFormat() { + for (Field field : FieldFactory.getPersonNameFields()) { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(field, " Knuth, Donald E. "), BibDatabaseMode.BIBLATEX)); + } + } + + @Test + void authorDoesNotAcceptDifferentFormats() { + for (Field field : FieldFactory.getPersonNameFields()) { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(field, "Knuth, Donald E. and Kurt Cobain and A. Einstein"), BibDatabaseMode.BIBLATEX)); + } + } + + @Test + void authorAcceptsMultipleAuthors() { + for (Field field : FieldFactory.getPersonNameFields()) { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(field, "Donald E. Knuth and Kurt Cobain and A. Einstein"), BibDatabaseMode.BIBLATEX)); + } + } + + @Test + void authorCanNotStartWithComma() { + for (Field field : FieldFactory.getPersonNameFields()) { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(field, ", and Kurt Cobain and A. Einstein"), BibDatabaseMode.BIBLATEX)); + } + } + + @Test + void authorDoesNotAcceptCommaAsAuthor() { + for (Field field : FieldFactory.getPersonNameFields()) { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(field, "Donald E. Knuth and Kurt Cobain and ,"), BibDatabaseMode.BIBLATEX)); + } + } + + @Test + void authorCanNotStartWithAnd() { + for (Field field : FieldFactory.getPersonNameFields()) { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(field, "and Kurt Cobain and A. Einstein"), BibDatabaseMode.BIBLATEX)); + } + } + + @Test + void authorDoesNotAcceptUnfinishedSentence() { + for (Field field : FieldFactory.getPersonNameFields()) { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(field, "Donald E. Knuth and Kurt Cobain and"), BibDatabaseMode.BIBLATEX)); + } + } + } diff --git a/src/test/java/org/jabref/logic/integrity/TitleCheckerTest.java b/src/test/java/org/jabref/logic/integrity/TitleCheckerTest.java index 930f1598129..b1caa937164 100644 --- a/src/test/java/org/jabref/logic/integrity/TitleCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/TitleCheckerTest.java @@ -4,6 +4,7 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; +import org.jabref.model.entry.field.StandardField; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -23,57 +24,198 @@ public void setUp() { } @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() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a title"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexDoesNotAcceptCapitalLettersInsideTitle() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a Title"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexRemovesCapitalLetterInsideTitle() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a {T}itle"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexRemovesEverythingInBracketsAndAcceptsNoTitleInput() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "{This is a Title}"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexRemovesEverythingInBrackets() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a {Title}"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexAcceptsTitleWithLowercaseFirstLetter() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "{C}urrent {C}hronicle"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexAcceptsSubTitlesWithOnlyFirstCapitalLetter() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a sub title 1: This is a sub title 2"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexAcceptsSubTitleWithLowercaseFirstLetter() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a sub title 1: this is a sub title 2"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexDoesNotAcceptCapitalLettersInsideSubTitle() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a sub title 1: This is A sub title 2"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexRemovesCapitalLetterInsideSubTitle() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a sub title 1: this is {A} sub title 2"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexSplitsSubTitlesBasedOnDots() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a sub title 1...This is a sub title 2"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexSplitsSubTitleBasedOnSpecialCharacters() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is; A sub title 1.... This is a sub title 2"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexAcceptsCapitalLetterAfterSpecialCharacter() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This!is!!A!Title??"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibTexAcceptsCapitalLetterOnlyAfterSpecialCharacter() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This!is!!A!TitlE??"), BibDatabaseMode.BIBTEX)); + } + + @Test + void bibLaTexAcceptsTitleWithOnlyFirstCapitalLetter() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a title"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexAcceptsCapitalLettersInsideTitle() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a Title"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexRemovesCapitalLetterInsideTitle() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a {T}itle"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexRemovesEverythingInBracketsAndAcceptsNoTitleInput() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "{This is a Title}"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexRemovesEverythingInBrackets() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a {Title}"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexAcceptsTitleWithLowercaseFirstLetter() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "{C}urrent {C}hronicle"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexAcceptsSubTitlesWithOnlyFirstCapitalLetter() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a sub title 1: This is a sub title 2"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexAcceptsSubTitleWithLowercaseFirstLetter() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a sub title 1: this is a sub title 2"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexAcceptsCapitalLettersInsideSubTitle() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a sub title 1: This is A sub title 2"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexRemovesCapitalLetterInsideSubTitle() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a sub title 1: this is {A} sub title 2"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexSplitsSubTitlesBasedOnDots() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a sub title 1...This is a sub title 2"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexSplitsSubTitleBasedOnSpecialCharacters() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is; A sub title 1.... This is a sub title 2"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexAcceptsCapitalLetterAfterSpecialCharacter() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This!is!!A!Title??"), BibDatabaseMode.BIBLATEX)); + } + + @Test + void bibLaTexAcceptsCapitalLetterNotOnlyAfterSpecialCharacter() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This!is!!A!TitlE??"), BibDatabaseMode.BIBLATEX)); + } + } 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..3bbb1a5f03d --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/TypeCheckerTest.java @@ -0,0 +1,20 @@ +package org.jabref.logic.integrity; + +import org.jabref.model.entry.field.StandardField; +import org.jabref.model.entry.types.StandardEntryType; + +import org.junit.jupiter.api.Test; + +public class TypeCheckerTest { + + @Test + void inProceedingshasPagesNumbers() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.PAGES, "11--15", StandardEntryType.InProceedings)); + } + + @Test + void proceedingsDoesNotHavePageNumbers() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.PAGES, "11--15", StandardEntryType.Proceedings)); + } + +} 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..1ed00c4637f --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/UrlCheckerTest.java @@ -0,0 +1,37 @@ +package org.jabref.logic.integrity; + +import org.jabref.model.entry.field.StandardField; +import org.junit.jupiter.api.Test; + +public class UrlCheckerTest { + + @Test + void urlFieldAcceptsHttpAddress() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.URL, "http://www.google.com")); + } + + @Test + void urlFieldAcceptsFullLocalPath() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.URL, "file://c:/asdf/asdf")); + } + + @Test + void urlFieldAcceptsFullPathHttpAddress() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.URL, "http://scikit-learn.org/stable/modules/ensemble.html#random-forests")); + } + + @Test + void urlFieldDoesNotAcceptHttpAddressWithoutTheHttp() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.URL, "www.google.com")); + } + + @Test + void urlFieldDoesNotAcceptPartialHttpAddress() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.URL, "google.com")); + } + + @Test + void urlFieldDoesNotAcceptPartialLocalPath() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.URL, "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..8ca76bbadcc --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/YearCheckerTest.java @@ -0,0 +1,83 @@ +package org.jabref.logic.integrity; + +import org.jabref.model.entry.field.StandardField; + +import org.junit.jupiter.api.Test; + +public class YearCheckerTest { + + @Test + void yearFieldAccepts21stCenturyDate() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.YEAR, "2014")); + } + + @Test + void yearFieldAccepts20thCenturyDate() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.YEAR, "1986")); + } + + @Test + void yearFieldAcceptsApproximateDate() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.YEAR, "around 1986")); + } + + @Test + void yearFieldAcceptsApproximateDateWithParenthesis() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.YEAR, "(around 1986)")); + } + + @Test + void yearFieldRemovesCommaFromYear() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.YEAR, "1986,")); + } + + @Test + void yearFieldRemovesBraceAndPercentageFromYear() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.YEAR, "1986}%")); + } + + @Test + void yearFieldRemovesSpecialCharactersFromYear() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.YEAR, "1986(){},.;!?<>%&$")); + } + + @Test + void yearFieldDoesNotAcceptStringAsInput() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.YEAR, "abc")); + } + + @Test + void yearFieldDoesNotAcceptDoubleDigitNumber() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.YEAR, "86")); + } + + @Test + void yearFieldDoesNotAcceptTripleDigitNumber() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.YEAR, "204")); + } + + @Test + void yearFieldDoesNotRemoveStringInYear() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.YEAR, "1986a")); + } + + @Test + void yearFieldDoesNotRemoveStringInParenthesis() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.YEAR, "(1986a)")); + } + + @Test + void yearFieldDoesNotRemoveStringBeforeComma() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.YEAR, "1986a,")); + } + + @Test + void yearFieldDoesNotRemoveStringInsideBraceAndPercentage() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.YEAR, "1986}a%")); + } + + @Test + void yearFieldDoesNotRemoveStringBeforeSpecialCharacters() { + IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.YEAR, "1986a(){},.;!?<>%&$")); + } +} From b204b6bc4009fef11d03ea8d12cc9d8e7d21c26b Mon Sep 17 00:00:00 2001 From: dimitra-karadima Date: Sun, 12 Apr 2020 22:35:09 +0300 Subject: [PATCH 04/14] Solve some issues Change two failing tests to succesfull Remove one test --- .../jabref/logic/integrity/EditionCheckerTest.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java b/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java index 8f86cba6fbb..826d91c107b 100644 --- a/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java @@ -55,18 +55,13 @@ void bibTexDoesNotAcceptOrdinalNumberInWordsWithNonCapitalFirstLetter() { } @Test - void bibTexDoesNotAcceptIntegerInputInEdition() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.EDITION, "2"), BibDatabaseMode.BIBTEX)); + void bibTexAcceptsIntegerInputInEdition() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.EDITION, "2"), BibDatabaseMode.BIBTEX)); } @Test - void bibTexNowAcceptsIntegerInputInEdition() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.EDITION, "2"), BibDatabaseMode.BIBTEX), true); - } - - @Test - void bibTexDoesNotAcceptOrdinalNumberInNumbers() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.EDITION, "2nd"), BibDatabaseMode.BIBTEX)); + void bibTexAcceptsOrdinalNumberInNumbers() { + IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.EDITION, "2nd"), BibDatabaseMode.BIBTEX)); } @Test From 3a4f9d72d4884b4d7234ad7d4b51105c359a337a Mon Sep 17 00:00:00 2001 From: dimitra-karadima Date: Fri, 24 Apr 2020 02:00:23 +0300 Subject: [PATCH 05/14] Rework the added tests Add the following changes: -Use checker.checkValue or checker.check instead of IntegrityCheckTest... -Split a method with multiple assertion methods in FileCheckerTest into three different with a simple assertion method -Rename a method in ASCIICharacterCheckerTest in order to use defined camel case --- .../integrity/ASCIICharacterCheckerTest.java | 27 ++++++- .../integrity/AbbreviationCheckerTest.java | 22 +----- .../logic/integrity/BibStringCheckerTest.java | 31 ++++++-- .../logic/integrity/BooktitleCheckerTest.java | 18 ++++- .../logic/integrity/BracketCheckerTest.java | 25 +++++-- .../integrity/DOIValidityCheckerTest.java | 21 ++++-- .../logic/integrity/EditionCheckerTest.java | 38 +++++++--- .../logic/integrity/FileCheckerTest.java | 54 ++++++++------ .../integrity/HTMLCharacterCheckerTest.java | 34 +++++++-- .../integrity/HowPublishedCheckerTest.java | 34 +++++++-- .../logic/integrity/ISBNCheckerTest.java | 21 ++++-- .../logic/integrity/ISSNCheckerTest.java | 21 ++++-- .../logic/integrity/IntegrityCheckTest.java | 9 +-- .../JournalInAbbreviationListCheckerTest.java | 40 ++++++++-- .../logic/integrity/MonthCheckerTest.java | 45 +++++++---- .../logic/integrity/NoteCheckerTest.java | 37 +++++++--- .../integrity/PagesCheckerBibLatexTest.java | 42 +++++++++++ .../logic/integrity/PagesCheckerTest.java | 74 ++++++------------- .../integrity/PersonNamesCheckerTest.java | 43 +++-------- .../logic/integrity/TitleCheckerTest.java | 62 ++++++++-------- .../logic/integrity/TypeCheckerTest.java | 23 +++++- .../logic/integrity/UrlCheckerTest.java | 26 +++++-- .../logic/integrity/YearCheckerTest.java | 43 +++++++---- 23 files changed, 519 insertions(+), 271 deletions(-) diff --git a/src/test/java/org/jabref/logic/integrity/ASCIICharacterCheckerTest.java b/src/test/java/org/jabref/logic/integrity/ASCIICharacterCheckerTest.java index 747bdc42fd2..66678c4590d 100644 --- a/src/test/java/org/jabref/logic/integrity/ASCIICharacterCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/ASCIICharacterCheckerTest.java @@ -1,24 +1,43 @@ 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.BeforeEach; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class ASCIICharacterCheckerTest { + private ASCIICharacterChecker checker; + private BibEntry entry; + + @BeforeEach + void setUp() { + checker = new ASCIICharacterChecker(); + entry = new BibEntry(); + } + @Test - void fieldAcceptsASCIICharacters() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.TITLE, "Only ascii characters!'@12")); + void fieldAcceptsAsciiCharacters() { + entry.setField(StandardField.TITLE, "Only ascii characters!'@12"); + assertEquals(Collections.emptyList(), checker.check(entry)); } @Test void fieldDoesNotAcceptUmlauts() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.MONTH, "Umlauts are nöt ällowed")); + 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() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.AUTHOR, "Some unicode ⊕")); + 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 a912969f37b..5dcc2b64a06 100644 --- a/src/test/java/org/jabref/logic/integrity/AbbreviationCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/AbbreviationCheckerTest.java @@ -1,13 +1,9 @@ package org.jabref.logic.integrity; -import java.util.Arrays; import java.util.Optional; import org.jabref.logic.journals.Abbreviation; import org.jabref.logic.journals.JournalAbbreviationRepository; -import org.jabref.model.entry.field.Field; -import org.jabref.model.entry.field.StandardField; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -37,23 +33,13 @@ void checkValueDoesNotComplainAboutJournalNameThatHasSameAbbreviation() { } @Test - void journalNameAcceptsFullForm() { - for (Field field : Arrays.asList(StandardField.BOOKTITLE, StandardField.JOURNAL)) { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(field, "IEEE Software")); - } + void checkValueDoesNotComplainAboutJournalNameThatHasΝοAbbreviation() { + assertEquals(Optional.empty(), checker.checkValue("IEEE Software")); } @Test - void journalNameAcceptsEmptyInput() { - for (Field field : Arrays.asList(StandardField.BOOKTITLE, StandardField.JOURNAL)) { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(field, "")); - } + void checkValueDoesNotComplainAboutJournalNameThatHasΝοInput() { + assertEquals(Optional.empty(), checker.checkValue("")); } - @Test - void journalNameDoesNotAcceptNonAbbreviatedForm() { - for (Field field : Arrays.asList(StandardField.BOOKTITLE, StandardField.JOURNAL)) { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(field, "IEEE SW")); - } - } } diff --git a/src/test/java/org/jabref/logic/integrity/BibStringCheckerTest.java b/src/test/java/org/jabref/logic/integrity/BibStringCheckerTest.java index 83fb9a6ff4b..2cd1191feb5 100644 --- a/src/test/java/org/jabref/logic/integrity/BibStringCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/BibStringCheckerTest.java @@ -1,33 +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.BeforeEach; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class BibStringCheckerTest { + private BibStringChecker checker; + private BibEntry entry; + + @BeforeEach + void setUp() { + checker = new BibStringChecker(); + entry = new BibEntry(); + } + @Test void fieldAcceptsNoHashMarks() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.TITLE, "Not a single hash mark")); + entry.setField(StandardField.TITLE, "Not a single hash mark"); + assertEquals(Collections.emptyList(), checker.check(entry)); } @Test void monthAcceptsEvenNumberOfHashMarks() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.MONTH, "#jan#")); + entry.setField(StandardField.MONTH, "#jan#"); + assertEquals(Collections.emptyList(), checker.check(entry)); } @Test void authorAcceptsEvenNumberOfHashMarks() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.AUTHOR, "#einstein# and #newton#")); + entry.setField(StandardField.AUTHOR, "#einstein# and #newton#"); + assertEquals(Collections.emptyList(), checker.check(entry)); } @Test void monthDoesNotAcceptOddNumberOfHashMarks() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.MONTH, "#jan")); + entry.setField(StandardField.MONTH, "#jan"); + assertEquals(List.of(new IntegrityMessage("odd number of unescaped '#'", entry, StandardField.MONTH)), checker.check(entry)); } @Test void authorDoesNotAcceptOddNumberOfHashMarks() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.AUTHOR, "#einstein# #amp; #newton#")); + 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/BooktitleCheckerTest.java b/src/test/java/org/jabref/logic/integrity/BooktitleCheckerTest.java index aa721a42d9c..30af7eae7f2 100644 --- a/src/test/java/org/jabref/logic/integrity/BooktitleCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/BooktitleCheckerTest.java @@ -1,20 +1,30 @@ package org.jabref.logic.integrity; -import org.jabref.model.entry.field.StandardField; -import org.jabref.model.entry.types.StandardEntryType; +import java.util.Optional; +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 BooktitleCheckerTest { + private BooktitleChecker checker; + + @BeforeEach + public void setUp() { + checker = new BooktitleChecker(); + } + @Test void booktitleAcceptsIfItDoesNotEndWithConferenceOn() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.BOOKTITLE, "2014 Fourth International Conference on Digital Information and Communication Technology and it's Applications (DICTAP)", StandardEntryType.Proceedings)); + assertEquals(Optional.empty(), checker.checkValue("2014 Fourth International Conference on Digital Information and Communication Technology and it's Applications (DICTAP)")); } @Test void booktitleDoesNotAcceptsIfItEndsWithConferenceOn() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.BOOKTITLE, "Digital Information and Communication Technology and it's Applications (DICTAP), 2014 Fourth International Conference on", StandardEntryType.Proceedings)); + 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 index a5972d3318e..3824ccda8ee 100644 --- a/src/test/java/org/jabref/logic/integrity/BracketCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/BracketCheckerTest.java @@ -1,39 +1,50 @@ package org.jabref.logic.integrity; -import org.jabref.model.entry.field.StandardField; +import java.util.Optional; +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 BracketCheckerTest { + private BracketChecker checker; + + @BeforeEach + void setUp() { + checker = new BracketChecker(); + } + @Test void fieldAcceptsNoBrackets() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.TITLE, "x")); + assertEquals(Optional.empty(), checker.checkValue("x")); } @Test void fieldAcceptsEvenNumberOfBrackets() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.TITLE, "{x}")); + assertEquals(Optional.empty(), checker.checkValue("{x}")); } @Test void fieldAcceptsExpectedBracket() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.TITLE, "{x}x{}x{{}}")); + assertEquals(Optional.empty(), checker.checkValue("{x}x{}x{{}}")); } @Test void fieldDoesNotAcceptOddNumberOfBrackets() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.TITLE, "{x}x{}}x{{}}")); + assertNotEquals(Optional.empty(), checker.checkValue("{x}x{}}x{{}}")); } @Test void fieldDoesNotAcceptUnexpectedClosingBracket() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.TITLE, "}")); + assertNotEquals(Optional.empty(), checker.checkValue("}")); } @Test void fieldDoesNotAcceptUnexpectedOpeningBracket() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.TITLE, "{")); + 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 index 2305fa9a082..5b931043be6 100644 --- a/src/test/java/org/jabref/logic/integrity/DOIValidityCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/DOIValidityCheckerTest.java @@ -1,29 +1,40 @@ package org.jabref.logic.integrity; -import org.jabref.model.entry.field.StandardField; +import java.util.Optional; +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 DOIValidityCheckerTest { + private DOIValidityChecker checker; + + @BeforeEach + void setUp() { + checker = new DOIValidityChecker(); + } + @Test void doiAcceptsValidInput() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.DOI, "10.1023/A:1022883727209")); + assertEquals(Optional.empty(), checker.checkValue("10.1023/A:1022883727209")); } @Test void doiAcceptsValidInputWithNotOnlyNumbers() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.DOI, "10.17487/rfc1436")); + assertEquals(Optional.empty(), checker.checkValue("10.17487/rfc1436")); } @Test void doiAcceptsValidInputNoMatterTheLengthOfTheDOIName() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.DOI, "10.1002/(SICI)1097-4571(199205)43:4<284::AID-ASI3>3.0.CO;2-0")); + assertEquals(Optional.empty(), checker.checkValue("10.1002/(SICI)1097-4571(199205)43:4<284::AID-ASI3>3.0.CO;2-0")); } @Test void doiDoesNotAcceptInvalidInput() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.DOI, "asdf")); + assertNotEquals(Optional.empty(), checker.checkValue("asdf")); } } diff --git a/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java b/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java index 826d91c107b..a1c3bae79c8 100644 --- a/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java @@ -4,16 +4,34 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.entry.field.StandardField; - +import org.jabref.model.entry.BibEntry; +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 { + private EditionChecker checker; + private EditionChecker checkerb; + private BibEntry entry; + 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); + entry = new BibEntry(); + } + public BibDatabaseContext bibDatabaseContextEdition = new BibDatabaseContext(); @Test @@ -46,42 +64,42 @@ void editionCheckerDoesNotComplainIfAllowIntegerEditionIsEnabled() { @Test void bibTexAcceptsOrdinalNumberInWordsWithCapitalFirstLetter() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.EDITION, "Second"), BibDatabaseMode.BIBTEX)); + assertEquals(Optional.empty(), checker.checkValue("Second")); } @Test void bibTexDoesNotAcceptOrdinalNumberInWordsWithNonCapitalFirstLetter() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.EDITION, "second"), BibDatabaseMode.BIBTEX)); + assertNotEquals(Optional.empty(), checker.checkValue("second")); } @Test void bibTexAcceptsIntegerInputInEdition() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.EDITION, "2"), BibDatabaseMode.BIBTEX)); + assertEquals(Optional.empty(), checker.checkValue("2")); } @Test void bibTexAcceptsOrdinalNumberInNumbers() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.EDITION, "2nd"), BibDatabaseMode.BIBTEX)); + assertEquals(Optional.empty(), checker.checkValue("2nd")); } @Test void bibLaTexAcceptsEditionWithCapitalFirstLetter() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.EDITION, "Edition 2000"), BibDatabaseMode.BIBLATEX)); + assertEquals(Optional.empty(), checkerb.checkValue("Edition 2000")); } @Test void bibLaTexAcceptsIntegerInputInEdition() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.EDITION, "2"), BibDatabaseMode.BIBLATEX)); + assertEquals(Optional.empty(), checkerb.checkValue("2")); } @Test void bibLaTexAcceptsEditionAsLiteralString() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.EDITION, "Third, revised and expanded edition"), BibDatabaseMode.BIBLATEX)); + assertEquals(Optional.empty(), checkerb.checkValue("Third, revised and expanded edition")); } @Test void bibLaTexDoesNotAcceptOrdinalNumberInNumbers() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.EDITION, "2nd"), BibDatabaseMode.BIBLATEX)); + assertNotEquals(Optional.empty(), checkerb.checkValue("2nd")); } } diff --git a/src/test/java/org/jabref/logic/integrity/FileCheckerTest.java b/src/test/java/org/jabref/logic/integrity/FileCheckerTest.java index 43bc69f9139..71db9a1eba6 100644 --- a/src/test/java/org/jabref/logic/integrity/FileCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/FileCheckerTest.java @@ -1,48 +1,58 @@ package org.jabref.logic.integrity; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; +import java.util.List; import java.util.Optional; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.entry.field.StandardField; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.metadata.FilePreferences; import org.jabref.model.metadata.MetaData; - +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.io.TempDir; import org.mockito.Mockito; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; public class FileCheckerTest { - @Test - void testFileChecks() { - MetaData metaData = mock(MetaData.class); + private FileChecker checker; + private BibEntry entry; + private BibDatabaseContext bibDatabaseContext; + private List messages; + MetaData metaData = mock(MetaData.class); + //private FilePreferences f; + //Map hash; + + @BeforeEach + void setUp() { + //hash.put(StandardField.ABSTRACT, ""); + //f = new FilePreferences("", hash, true, "", ""); + bibDatabaseContext = new BibDatabaseContext(); + checker = new FileChecker(bibDatabaseContext, mock(FilePreferences.class)); + entry = new BibEntry(); Mockito.when(metaData.getDefaultFileDirectory()).thenReturn(Optional.of(".")); + //Mockito.when(metaData.getDefaultFileDirectory()).thenReturn(Optional.empty()); Mockito.when(metaData.getUserFileDirectory(any(String.class))).thenReturn(Optional.empty()); // FIXME: must be set as checkBibtexDatabase only activates title checker based on database mode Mockito.when(metaData.getMode()).thenReturn(Optional.of(BibDatabaseMode.BIBTEX)); - - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.FILE, ":build.gradle:gradle", metaData)); - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.FILE, "description:build.gradle:gradle", metaData)); - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.FILE, ":asflakjfwofja:PDF", metaData)); } @Test - void fileCheckFindsFilesRelativeToBibFile(@TempDir Path testFolder) throws IOException { - Path bibFile = testFolder.resolve("lit.bib"); - Files.createFile(bibFile); - Path pdfFile = testFolder.resolve("file.pdf"); - Files.createFile(pdfFile); - - BibDatabaseContext databaseContext = IntegrityCheckTest.createContext(StandardField.FILE, ":file.pdf:PDF"); - databaseContext.setDatabasePath(bibFile); + void fileAcceptsRelativePath() { + assertEquals(Optional.empty(), checker.checkValue(":build.gradle:gradle")); + } - IntegrityCheckTest.assertCorrect(databaseContext); + @Test + void fileAcceptsFullPath() { + assertEquals(Optional.empty(), checker.checkValue("description:build.gradle:gradle")); + } + @Test + void fileDoesNotAcceptWrongPath() { + assertNotEquals(Optional.empty(), checker.checkValue(":asflakjfwofja:PDF")); } } diff --git a/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java b/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java index ee9d86b02ad..93c9996515b 100644 --- a/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java @@ -1,39 +1,61 @@ 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.BeforeEach; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class HTMLCharacterCheckerTest { + private HTMLCharacterChecker checker; + private BibEntry entry; + + @BeforeEach + void setUp() { + checker = new HTMLCharacterChecker(); + entry = new BibEntry(); + } + @Test void titleAcceptsNonHTMLEncodedCharacters() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.TITLE, "Not a single {HTML} character")); + entry.setField(StandardField.TITLE, "Not a single {HTML} character"); + assertEquals(Collections.emptyList(), checker.check(entry)); } @Test void monthAcceptsNonHTMLEncodedCharacters() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.MONTH, "#jan#")); + entry.setField(StandardField.MONTH, "#jan#"); + assertEquals(Collections.emptyList(), checker.check(entry)); } @Test void authorAcceptsNonHTMLEncodedCharacters() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.AUTHOR, "A. Einstein and I. Newton")); + entry.setField(StandardField.AUTHOR, "A. Einstein and I. Newton"); + assertEquals(Collections.emptyList(), checker.check(entry)); } @Test void urlAcceptsNonHTMLEncodedCharacters() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.URL, "http://www.thinkmind.org/index.php?view=article&articleid=cloud_computing_2013_1_20_20130")); + 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() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.AUTHOR, "Lenhard, Jãrg")); + 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() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.JOURNAL, "Ärling Ström for – ‱")); + 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 index 8428a2631c1..bfe9b5fc3e1 100644 --- a/src/test/java/org/jabref/logic/integrity/HowPublishedCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/HowPublishedCheckerTest.java @@ -1,40 +1,58 @@ package org.jabref.logic.integrity; -import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.entry.field.StandardField; +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() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.HOWPUBLISHED, "Lorem ipsum"), BibDatabaseMode.BIBTEX)); + assertEquals(Optional.empty(), checker.checkValue("Lorem ipsum")); } @Test void bibTexDoesNotCareAboutSpecialChracters() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.HOWPUBLISHED, "Lorem ipsum? 10"), BibDatabaseMode.BIBTEX)); + assertEquals(Optional.empty(), checker.checkValue("Lorem ipsum? 10")); } @Test void bibTexDoesNotAcceptStringWithLowercaseFirstLetter() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.HOWPUBLISHED, "lorem ipsum"), BibDatabaseMode.BIBTEX)); + assertNotEquals(Optional.empty(), checker.checkValue("lorem ipsum")); } @Test void bibTexAcceptsUrl() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.HOWPUBLISHED, "\\url{someurl}"), BibDatabaseMode.BIBTEX)); + assertEquals(Optional.empty(), checker.checkValue("\\url{someurl}")); } @Test void bibLaTexAcceptsStringWithCapitalFirstLetter() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.HOWPUBLISHED, "Lorem ipsum"), BibDatabaseMode.BIBLATEX)); + assertEquals(Optional.empty(), checkerBiblatex.checkValue("Lorem ipsum")); } @Test void bibLaTexAcceptsStringWithLowercaseFirstLetter() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.HOWPUBLISHED, "lorem ipsum"), BibDatabaseMode.BIBLATEX)); + 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 index 8b8c98a8caf..5edc640b39e 100644 --- a/src/test/java/org/jabref/logic/integrity/ISBNCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/ISBNCheckerTest.java @@ -1,29 +1,40 @@ package org.jabref.logic.integrity; -import org.jabref.model.entry.field.StandardField; +import java.util.Optional; +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 ISBNCheckerTest { + private ISBNChecker checker; + + @BeforeEach + void setUp() { + checker = new ISBNChecker(); + } + @Test void isbnAcceptsValidInput() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.ISBN, "0-201-53082-1")); + assertEquals(Optional.empty(), checker.checkValue("0-201-53082-1")); } @Test void isbnAcceptsNumbersAndCharacters() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.ISBN, "0-9752298-0-X")); + assertEquals(Optional.empty(), checker.checkValue("0-9752298-0-X")); } @Test void isbnDoesNotAcceptRandomInput() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.ISBN, "Some other stuff")); + assertNotEquals(Optional.empty(), checker.checkValue("Some other stuff")); } @Test void isbnDoesNotAcceptInvalidInput() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.ISBN, "0-201-53082-2")); + 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 index 62a7435879c..f39177ead7b 100644 --- a/src/test/java/org/jabref/logic/integrity/ISSNCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/ISSNCheckerTest.java @@ -1,29 +1,40 @@ package org.jabref.logic.integrity; -import org.jabref.model.entry.field.StandardField; +import java.util.Optional; +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 ISSNCheckerTest { + private ISSNChecker checker; + + @BeforeEach + void setUp() { + checker = new ISSNChecker(); + } + @Test void issnAcceptsValidInput() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.ISSN, "0020-7217")); + assertEquals(Optional.empty(), checker.checkValue("0020-7217")); } @Test void issnAcceptsNumbersAndCharacters() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.ISSN, "2434-561x")); + assertEquals(Optional.empty(), checker.checkValue("2434-561x")); } @Test void issnDoesNotAcceptRandomInput() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.ISSN, "Some other stuff")); + assertNotEquals(Optional.empty(), checker.checkValue("Some other stuff")); } @Test void issnDoesNotAcceptInvalidInput() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.ISSN, "0020-7218")); + 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 f1be2b718dc..63de06d05d0 100644 --- a/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java +++ b/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java @@ -118,11 +118,10 @@ protected static void assertCorrect(BibDatabaseContext context) { protected static void assertCorrect(BibDatabaseContext context, boolean allowIntegerEdition) { List messages = new IntegrityCheck(context, - mock(FilePreferences.class), - createBibtexKeyPatternPreferences(), - new JournalAbbreviationRepository(new Abbreviation("IEEE Software", "IEEE SW")), true, - allowIntegerEdition - ).checkDatabase(); + mock(FilePreferences.class), + createBibtexKeyPatternPreferences(), + new JournalAbbreviationRepository(new Abbreviation("IEEE Software", "IEEE SW")), true, + 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 index c50d216d1bc..de5d105682a 100644 --- a/src/test/java/org/jabref/logic/integrity/JournalInAbbreviationListCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/JournalInAbbreviationListCheckerTest.java @@ -1,29 +1,55 @@ package org.jabref.logic.integrity; -import org.jabref.model.database.BibDatabaseMode; +import java.util.Collections; +import java.util.List; + +import org.jabref.logic.journals.Abbreviation; +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 Abbreviation a; + private BibEntry entry; + + @BeforeEach + void setUp() { + abbreviationRepository = new JournalAbbreviationRepository(new Abbreviation("IEEE Software", "IEEE SW")); + checker = new JournalInAbbreviationListChecker(StandardField.JOURNAL, abbreviationRepository); + checkerb = new JournalInAbbreviationListChecker(StandardField.JOURNALTITLE, abbreviationRepository); + entry = new BibEntry(); + } + @Test void journalAcceptsNameInTheList() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.JOURNAL, "IEEE Software")); + entry.setField(StandardField.JOURNAL, "IEEE Software"); + assertEquals(Collections.emptyList(), checker.check(entry)); } @Test void journalDoesNotAcceptNameNotInList() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.JOURNAL, "IEEE Whocares")); + 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 bibLaTexDoesNotAcceptRandomInputInTitle() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.JOURNALTITLE, "A journal"), BibDatabaseMode.BIBLATEX)); + 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 bibTexDoesNotAcceptRandomInputInTitle() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.JOURNAL, "A journal"), BibDatabaseMode.BIBTEX)); + 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 index 21382742642..e79649736d5 100644 --- a/src/test/java/org/jabref/logic/integrity/MonthCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/MonthCheckerTest.java @@ -1,65 +1,82 @@ package org.jabref.logic.integrity; -import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.entry.field.StandardField; +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() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.MONTH, "#mar#"), BibDatabaseMode.BIBTEX)); + assertEquals(Optional.empty(), checker.checkValue("#mar#")); } @Test void bibTexDoesNotAcceptWhateverThreeLetterAbbreviations() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.MONTH, "#bla#"), BibDatabaseMode.BIBTEX)); + assertNotEquals(Optional.empty(), checker.checkValue("#bla#")); } @Test void bibTexDoesNotAcceptThreeLetterAbbreviationsWithNoHashMarks() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.MONTH, "Dec"), BibDatabaseMode.BIBTEX)); + assertNotEquals(Optional.empty(), checker.checkValue("Dec")); } @Test void bibTexDoesNotAcceptFullInput() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.MONTH, "December"), BibDatabaseMode.BIBTEX)); + assertNotEquals(Optional.empty(), checker.checkValue("December")); } @Test void bibTexDoesNotAcceptRandomString() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.MONTH, "Lorem"), BibDatabaseMode.BIBTEX)); + assertNotEquals(Optional.empty(), checker.checkValue("Lorem")); } @Test void bibTexDoesNotAcceptInteger() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.MONTH, "10"), BibDatabaseMode.BIBTEX)); + assertNotEquals(Optional.empty(), checker.checkValue("10")); } @Test void bibLaTexAcceptsThreeLetterAbbreviationsWithHashMarks() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.MONTH, "#jan#"), BibDatabaseMode.BIBLATEX)); + assertEquals(Optional.empty(), checkerBiblatex.checkValue("#jan#")); } @Test void bibLaTexDoesNotAcceptThreeLetterAbbreviationsWithNoHashMarks() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.MONTH, "jan"), BibDatabaseMode.BIBLATEX)); + assertNotEquals(Optional.empty(), checkerBiblatex.checkValue("jan")); } @Test void bibLaTexDoesNotAcceptFullInput() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.MONTH, "January"), BibDatabaseMode.BIBLATEX)); + assertNotEquals(Optional.empty(), checkerBiblatex.checkValue("January")); } @Test void bibLaTexDoesNotAcceptRandomString() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.MONTH, "Lorem"), BibDatabaseMode.BIBLATEX)); + assertNotEquals(Optional.empty(), checkerBiblatex.checkValue("Lorem")); } @Test void bibLaTexAcceptsInteger() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.MONTH, "10"), BibDatabaseMode.BIBLATEX)); - + 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 index cc291e88f13..865b2476fb3 100644 --- a/src/test/java/org/jabref/logic/integrity/NoteCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/NoteCheckerTest.java @@ -1,40 +1,59 @@ package org.jabref.logic.integrity; -import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.entry.field.StandardField; +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() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.NOTE, "Lorem ipsum"), BibDatabaseMode.BIBTEX)); + assertEquals(Optional.empty(), checker.checkValue("Lorem ipsum")); } @Test void bibTexAcceptsNoteWithFirstCapitalLetterAndDoesNotCareAboutTheRest() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.NOTE, "Lorem ipsum? 10"), BibDatabaseMode.BIBTEX)); + assertEquals(Optional.empty(), checker.checkValue("Lorem ipsum? 10")); } @Test void bibTexDoesNotAcceptFirstLowercaseLetter() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.NOTE, "lorem ipsum"), BibDatabaseMode.BIBTEX)); + assertNotEquals(Optional.empty(), checker.checkValue("lorem ipsum")); } @Test void bibLaTexAcceptsNoteWithFirstCapitalLetter() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.NOTE, "Lorem ipsum"), BibDatabaseMode.BIBLATEX)); + assertEquals(Optional.empty(), checkerBiblatex.checkValue("Lorem ipsum")); } @Test - void bibLaTexAcceptsUrl() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.NOTE, "\\url{someurl}"), BibDatabaseMode.BIBTEX)); + void bibTexAcceptsUrl() { + assertEquals(Optional.empty(), checker.checkValue("\\url{someurl}")); } @Test void bibLaTexAcceptsFirstLowercaseLetter() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.NOTE, "lorem ipsum"), BibDatabaseMode.BIBLATEX)); + 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 index 7b724c7b0b0..016ab020168 100644 --- a/src/test/java/org/jabref/logic/integrity/PagesCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/PagesCheckerTest.java @@ -1,90 +1,64 @@ package org.jabref.logic.integrity; -import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.entry.field.StandardField; +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() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.PAGES, "1--2")); + assertEquals(Optional.empty(), checker.checkValue("1--2")); } @Test void bibTexAcceptsOnePageNumber() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.PAGES, "12")); + assertEquals(Optional.empty(), checker.checkValue("12")); } @Test void bibTexDoesNotAcceptRangeOfNumbersWithSingleDash() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.PAGES, "1-2")); + assertNotEquals(Optional.empty(), checker.checkValue("1-2")); } @Test void bibTexAcceptsMorePageNumbers() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.PAGES, "1,2,3")); + assertEquals(Optional.empty(), checker.checkValue("1,2,3")); } @Test void bibTexAcceptsNoSimpleRangeOfNumbers() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.PAGES, "43+")); + assertEquals(Optional.empty(), checker.checkValue("43+")); } @Test void bibTexDoesNotAcceptMorePageNumbersWithoutComma() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.PAGES, "1 2")); + assertNotEquals(Optional.empty(), checker.checkValue("1 2")); } @Test void bibTexDoesNotAcceptBrackets() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.PAGES, "{1}-{2}")); + assertNotEquals(Optional.empty(), checker.checkValue("{1}-{2}")); } @Test void bibTexAcceptsMorePageNumbersWithRangeOfNumbers() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.PAGES, "7+,41--43,73")); - } - - @Test - void bibLaTexAcceptsRangeOfNumbersWithDoubleDash() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.PAGES, "1--2"), BibDatabaseMode.BIBLATEX)); - } - - @Test - void bibLaTexAcceptsOnePageNumber() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.PAGES, "12"), BibDatabaseMode.BIBLATEX)); - } - - @Test - void bibLaTexAcceptsRangeOfNumbersWithSingleDash() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.PAGES, "1-2"), BibDatabaseMode.BIBLATEX)); // only diff to bibtex - } - - @Test - void bibLaTexAcceptsMorePageNumbers() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.PAGES, "1,2,3"), BibDatabaseMode.BIBLATEX)); - } - - @Test - void bibLaTexAcceptsNoSimpleRangeOfNumbers() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.PAGES, "43+"), BibDatabaseMode.BIBLATEX)); - } - - @Test - void bibLaTexDoesNotAcceptMorePageNumbersWithoutComma() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.PAGES, "1 2"), BibDatabaseMode.BIBLATEX)); - } - - @Test - void bibLaTexDoesNotAcceptBrackets() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.PAGES, "{1}-{2}"), BibDatabaseMode.BIBLATEX)); - } - - @Test - void bibLaTexAcceptsMorePageNumbersWithRangeOfNumbers() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.PAGES, "7+,41--43,73"), BibDatabaseMode.BIBLATEX)); + 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 6cd9661790d..6684652e49f 100644 --- a/src/test/java/org/jabref/logic/integrity/PersonNamesCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/PersonNamesCheckerTest.java @@ -4,13 +4,11 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.entry.field.Field; -import org.jabref.model.entry.field.FieldFactory; - 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 PersonNamesCheckerTest { @@ -67,67 +65,48 @@ public void validCorporateNameAndPerson() throws Exception { @Test void authorAcceptsVoidInput() { - 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 - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(field, ""), BibDatabaseMode.BIBLATEX)); - } + assertEquals(Optional.empty(), checker.checkValue("")); } @Test void authorAcceptsLastNameOnly() { - for (Field field : FieldFactory.getPersonNameFields()) { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(field, "Knuth"), BibDatabaseMode.BIBLATEX)); - } + assertEquals(Optional.empty(), checker.checkValue("Knuth")); } @Test void authorDoesNotAcceptSpacesBeforeFormat() { - for (Field field : FieldFactory.getPersonNameFields()) { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(field, " Knuth, Donald E. "), BibDatabaseMode.BIBLATEX)); - } + assertNotEquals(Optional.empty(), checker.checkValue(" Knuth, Donald E. ")); } @Test void authorDoesNotAcceptDifferentFormats() { - for (Field field : FieldFactory.getPersonNameFields()) { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(field, "Knuth, Donald E. and Kurt Cobain and A. Einstein"), BibDatabaseMode.BIBLATEX)); - } + assertNotEquals(Optional.empty(), checker.checkValue("Knuth, Donald E. and Kurt Cobain and A. Einstein")); } @Test void authorAcceptsMultipleAuthors() { - for (Field field : FieldFactory.getPersonNameFields()) { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(field, "Donald E. Knuth and Kurt Cobain and A. Einstein"), BibDatabaseMode.BIBLATEX)); - } + assertEquals(Optional.empty(), checker.checkValue("Donald E. Knuth and Kurt Cobain and A. Einstein")); } @Test void authorCanNotStartWithComma() { - for (Field field : FieldFactory.getPersonNameFields()) { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(field, ", and Kurt Cobain and A. Einstein"), BibDatabaseMode.BIBLATEX)); - } + assertNotEquals(Optional.empty(), checker.checkValue(", and Kurt Cobain and A. Einstein")); } @Test void authorDoesNotAcceptCommaAsAuthor() { - for (Field field : FieldFactory.getPersonNameFields()) { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(field, "Donald E. Knuth and Kurt Cobain and ,"), BibDatabaseMode.BIBLATEX)); - } + assertNotEquals(Optional.empty(), checker.checkValue("Donald E. Knuth and Kurt Cobain and ,")); + } @Test void authorCanNotStartWithAnd() { - for (Field field : FieldFactory.getPersonNameFields()) { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(field, "and Kurt Cobain and A. Einstein"), BibDatabaseMode.BIBLATEX)); - } + assertNotEquals(Optional.empty(), checker.checkValue("and Kurt Cobain and A. Einstein")); } @Test void authorDoesNotAcceptUnfinishedSentence() { - for (Field field : FieldFactory.getPersonNameFields()) { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(field, "Donald E. Knuth and Kurt Cobain and"), BibDatabaseMode.BIBLATEX)); - } + assertNotEquals(Optional.empty(), checker.checkValue("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 b1caa937164..9d897cfb16a 100644 --- a/src/test/java/org/jabref/logic/integrity/TitleCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/TitleCheckerTest.java @@ -4,8 +4,6 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.entry.field.StandardField; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -15,12 +13,16 @@ 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 @@ -80,142 +82,142 @@ public void moreThanOneCapitalLetterInSubTitleWithoutCurlyBrackets() { @Test void bibTexAcceptsTitleWithOnlyFirstCapitalLetter() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a title"), BibDatabaseMode.BIBTEX)); + assertEquals(Optional.empty(), checker.checkValue("This is a title")); } @Test void bibTexDoesNotAcceptCapitalLettersInsideTitle() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a Title"), BibDatabaseMode.BIBTEX)); + assertNotEquals(Optional.empty(), checker.checkValue("This is a Title")); } @Test void bibTexRemovesCapitalLetterInsideTitle() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a {T}itle"), BibDatabaseMode.BIBTEX)); + assertEquals(Optional.empty(), checker.checkValue("This is a {T}itle")); } @Test void bibTexRemovesEverythingInBracketsAndAcceptsNoTitleInput() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "{This is a Title}"), BibDatabaseMode.BIBTEX)); + assertEquals(Optional.empty(), checker.checkValue("{This is a Title}")); } @Test void bibTexRemovesEverythingInBrackets() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a {Title}"), BibDatabaseMode.BIBTEX)); + assertEquals(Optional.empty(), checker.checkValue("This is a {Title}")); } @Test void bibTexAcceptsTitleWithLowercaseFirstLetter() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "{C}urrent {C}hronicle"), BibDatabaseMode.BIBTEX)); + assertEquals(Optional.empty(), checker.checkValue("{C}urrent {C}hronicle")); } @Test void bibTexAcceptsSubTitlesWithOnlyFirstCapitalLetter() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a sub title 1: This is a sub title 2"), BibDatabaseMode.BIBTEX)); + assertEquals(Optional.empty(), checker.checkValue("This is a sub title 1: This is a sub title 2")); } @Test void bibTexAcceptsSubTitleWithLowercaseFirstLetter() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a sub title 1: this is a sub title 2"), BibDatabaseMode.BIBTEX)); + assertEquals(Optional.empty(), checker.checkValue("This is a sub title 1: this is a sub title 2")); } @Test void bibTexDoesNotAcceptCapitalLettersInsideSubTitle() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a sub title 1: This is A sub title 2"), BibDatabaseMode.BIBTEX)); + assertNotEquals(Optional.empty(), checker.checkValue("This is a sub title 1: This is A sub title 2")); } @Test void bibTexRemovesCapitalLetterInsideSubTitle() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a sub title 1: this is {A} sub title 2"), BibDatabaseMode.BIBTEX)); + assertEquals(Optional.empty(), checker.checkValue("This is a sub title 1: this is {A} sub title 2")); } @Test void bibTexSplitsSubTitlesBasedOnDots() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a sub title 1...This is a sub title 2"), BibDatabaseMode.BIBTEX)); + assertEquals(Optional.empty(), checker.checkValue("This is a sub title 1...This is a sub title 2")); } @Test void bibTexSplitsSubTitleBasedOnSpecialCharacters() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is; A sub title 1.... This is a sub title 2"), BibDatabaseMode.BIBTEX)); + assertEquals(Optional.empty(), checker.checkValue("This is; A sub title 1.... This is a sub title 2")); } @Test void bibTexAcceptsCapitalLetterAfterSpecialCharacter() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This!is!!A!Title??"), BibDatabaseMode.BIBTEX)); + assertEquals(Optional.empty(), checker.checkValue("This!is!!A!Title??")); } @Test void bibTexAcceptsCapitalLetterOnlyAfterSpecialCharacter() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This!is!!A!TitlE??"), BibDatabaseMode.BIBTEX)); + assertNotEquals(Optional.empty(), checker.checkValue("This!is!!A!TitlE??")); } @Test void bibLaTexAcceptsTitleWithOnlyFirstCapitalLetter() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a title"), BibDatabaseMode.BIBLATEX)); + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This is a title")); } @Test void bibLaTexAcceptsCapitalLettersInsideTitle() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a Title"), BibDatabaseMode.BIBLATEX)); + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This is a Title")); } @Test void bibLaTexRemovesCapitalLetterInsideTitle() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a {T}itle"), BibDatabaseMode.BIBLATEX)); + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This is a {T}itle")); } @Test void bibLaTexRemovesEverythingInBracketsAndAcceptsNoTitleInput() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "{This is a Title}"), BibDatabaseMode.BIBLATEX)); + assertEquals(Optional.empty(), checkerBiblatex.checkValue("{This is a Title}")); } @Test void bibLaTexRemovesEverythingInBrackets() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a {Title}"), BibDatabaseMode.BIBLATEX)); + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This is a {Title}")); } @Test void bibLaTexAcceptsTitleWithLowercaseFirstLetter() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "{C}urrent {C}hronicle"), BibDatabaseMode.BIBLATEX)); + assertEquals(Optional.empty(), checkerBiblatex.checkValue("{C}urrent {C}hronicle")); } @Test void bibLaTexAcceptsSubTitlesWithOnlyFirstCapitalLetter() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a sub title 1: This is a sub title 2"), BibDatabaseMode.BIBLATEX)); + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This is a sub title 1: This is a sub title 2")); } @Test void bibLaTexAcceptsSubTitleWithLowercaseFirstLetter() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a sub title 1: this is a sub title 2"), BibDatabaseMode.BIBLATEX)); + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This is a sub title 1: this is a sub title 2")); } @Test void bibLaTexAcceptsCapitalLettersInsideSubTitle() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a sub title 1: This is A sub title 2"), BibDatabaseMode.BIBLATEX)); + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This is a sub title 1: This is A sub title 2")); } @Test void bibLaTexRemovesCapitalLetterInsideSubTitle() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a sub title 1: this is {A} sub title 2"), BibDatabaseMode.BIBLATEX)); + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This is a sub title 1: this is {A} sub title 2")); } @Test void bibLaTexSplitsSubTitlesBasedOnDots() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is a sub title 1...This is a sub title 2"), BibDatabaseMode.BIBLATEX)); + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This is a sub title 1...This is a sub title 2")); } @Test void bibLaTexSplitsSubTitleBasedOnSpecialCharacters() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This is; A sub title 1.... This is a sub title 2"), BibDatabaseMode.BIBLATEX)); + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This is; A sub title 1.... This is a sub title 2")); } @Test void bibLaTexAcceptsCapitalLetterAfterSpecialCharacter() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This!is!!A!Title??"), BibDatabaseMode.BIBLATEX)); + assertEquals(Optional.empty(), checkerBiblatex.checkValue("This!is!!A!Title??")); } @Test void bibLaTexAcceptsCapitalLetterNotOnlyAfterSpecialCharacter() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.withMode(IntegrityCheckTest.createContext(StandardField.TITLE, "This!is!!A!TitlE??"), BibDatabaseMode.BIBLATEX)); + 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 index 3bbb1a5f03d..8975d3ed22d 100644 --- a/src/test/java/org/jabref/logic/integrity/TypeCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/TypeCheckerTest.java @@ -1,20 +1,39 @@ 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.BeforeEach; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class TypeCheckerTest { + private TypeChecker checker; + private BibEntry entry; + + @BeforeEach + void setUp() { + checker = new TypeChecker(); + } + @Test void inProceedingshasPagesNumbers() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.PAGES, "11--15", StandardEntryType.InProceedings)); + entry = new BibEntry(StandardEntryType.InProceedings); + entry.setField(StandardField.PAGES, "11--15"); + assertEquals(Collections.emptyList(), checker.check(entry)); } @Test void proceedingsDoesNotHavePageNumbers() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.PAGES, "11--15", StandardEntryType.Proceedings)); + 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 index 1ed00c4637f..66308bf217d 100644 --- a/src/test/java/org/jabref/logic/integrity/UrlCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/UrlCheckerTest.java @@ -1,37 +1,49 @@ package org.jabref.logic.integrity; -import org.jabref.model.entry.field.StandardField; +import java.util.Optional; + +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 UrlCheckerTest { + private UrlChecker checker; + + @BeforeEach + void setUp() { + checker = new UrlChecker(); + } + @Test void urlFieldAcceptsHttpAddress() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.URL, "http://www.google.com")); + assertEquals(Optional.empty(), checker.checkValue("http://www.google.com")); } @Test void urlFieldAcceptsFullLocalPath() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.URL, "file://c:/asdf/asdf")); + assertEquals(Optional.empty(), checker.checkValue("file://c:/asdf/asdf")); } @Test void urlFieldAcceptsFullPathHttpAddress() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.URL, "http://scikit-learn.org/stable/modules/ensemble.html#random-forests")); + assertEquals(Optional.empty(), checker.checkValue("http://scikit-learn.org/stable/modules/ensemble.html#random-forests")); } @Test void urlFieldDoesNotAcceptHttpAddressWithoutTheHttp() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.URL, "www.google.com")); + assertNotEquals(Optional.empty(), checker.checkValue("www.google.com")); } @Test void urlFieldDoesNotAcceptPartialHttpAddress() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.URL, "google.com")); + assertNotEquals(Optional.empty(), checker.checkValue("google.com")); } @Test void urlFieldDoesNotAcceptPartialLocalPath() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.URL, "c:/asdf/asdf")); + 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 index 8ca76bbadcc..a5cb9da5dbd 100644 --- a/src/test/java/org/jabref/logic/integrity/YearCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/YearCheckerTest.java @@ -1,83 +1,94 @@ package org.jabref.logic.integrity; -import org.jabref.model.entry.field.StandardField; +import java.util.Optional; +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 YearCheckerTest { + private YearChecker checker; + + @BeforeEach + void setUp() { + checker = new YearChecker(); + } + @Test void yearFieldAccepts21stCenturyDate() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.YEAR, "2014")); + assertEquals(Optional.empty(), checker.checkValue("2014")); } @Test void yearFieldAccepts20thCenturyDate() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.YEAR, "1986")); + assertEquals(Optional.empty(), checker.checkValue("1986")); } @Test void yearFieldAcceptsApproximateDate() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.YEAR, "around 1986")); + assertEquals(Optional.empty(), checker.checkValue("around 1986")); } @Test void yearFieldAcceptsApproximateDateWithParenthesis() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.YEAR, "(around 1986)")); + assertEquals(Optional.empty(), checker.checkValue("(around 1986)")); } @Test void yearFieldRemovesCommaFromYear() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.YEAR, "1986,")); + assertEquals(Optional.empty(), checker.checkValue("1986,")); } @Test void yearFieldRemovesBraceAndPercentageFromYear() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.YEAR, "1986}%")); + assertEquals(Optional.empty(), checker.checkValue("1986}%")); } @Test void yearFieldRemovesSpecialCharactersFromYear() { - IntegrityCheckTest.assertCorrect(IntegrityCheckTest.createContext(StandardField.YEAR, "1986(){},.;!?<>%&$")); + assertEquals(Optional.empty(), checker.checkValue("1986(){},.;!?<>%&$")); } @Test void yearFieldDoesNotAcceptStringAsInput() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.YEAR, "abc")); + assertNotEquals(Optional.empty(), checker.checkValue("abc")); } @Test void yearFieldDoesNotAcceptDoubleDigitNumber() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.YEAR, "86")); + assertNotEquals(Optional.empty(), checker.checkValue("86")); } @Test void yearFieldDoesNotAcceptTripleDigitNumber() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.YEAR, "204")); + assertNotEquals(Optional.empty(), checker.checkValue("204")); } @Test void yearFieldDoesNotRemoveStringInYear() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.YEAR, "1986a")); + assertNotEquals(Optional.empty(), checker.checkValue("1986a")); } @Test void yearFieldDoesNotRemoveStringInParenthesis() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.YEAR, "(1986a)")); + assertNotEquals(Optional.empty(), checker.checkValue("(1986a)")); } @Test void yearFieldDoesNotRemoveStringBeforeComma() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.YEAR, "1986a,")); + assertNotEquals(Optional.empty(), checker.checkValue("1986a,")); } @Test void yearFieldDoesNotRemoveStringInsideBraceAndPercentage() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.YEAR, "1986}a%")); + assertNotEquals(Optional.empty(), checker.checkValue("1986}a%")); } @Test void yearFieldDoesNotRemoveStringBeforeSpecialCharacters() { - IntegrityCheckTest.assertWrong(IntegrityCheckTest.createContext(StandardField.YEAR, "1986a(){},.;!?<>%&$")); + assertNotEquals(Optional.empty(), checker.checkValue("1986a(){},.;!?<>%&$")); } } From ca9f2f477b6da1ca79ab5a1c4e75300daa0aaab9 Mon Sep 17 00:00:00 2001 From: dimitra-karadima Date: Thu, 7 May 2020 15:34:07 +0300 Subject: [PATCH 06/14] Rework IntegrityCheckTest and BibtexKeyCheckerTest Add the following changes: -Revert all methods from protected static to private -Change BibtexKeyCheckerTest in order not to use IntegrityCheckTest's methods -Add two tests methods that were moved to another class --- .../logic/integrity/BibtexKeyCheckerTest.java | 25 +++++---- .../logic/integrity/IntegrityCheckTest.java | 52 +++++++++++++++---- 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/src/test/java/org/jabref/logic/integrity/BibtexKeyCheckerTest.java b/src/test/java/org/jabref/logic/integrity/BibtexKeyCheckerTest.java index 64180cd5fa8..30c27c684de 100644 --- a/src/test/java/org/jabref/logic/integrity/BibtexKeyCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/BibtexKeyCheckerTest.java @@ -1,27 +1,26 @@ package org.jabref.logic.integrity; -import org.jabref.model.database.BibDatabaseContext; +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 { - @Test - void bibTexAcceptsKeyFromAuthorAndYear() { - final BibDatabaseContext correctContext = IntegrityCheckTest.createContext(InternalField.KEY_FIELD, "Knuth2014"); - correctContext.getDatabase().getEntries().get(0).setField(StandardField.AUTHOR, "Knuth"); - correctContext.getDatabase().getEntries().get(0).setField(StandardField.YEAR, "2014"); - IntegrityCheckTest.assertCorrect(correctContext); - } + private final BibtexKeyChecker checker = new BibtexKeyChecker(); + private final BibEntry entry = new BibEntry(); @Test - void bibtexDooesNotAcceptRandomKey() { - final BibDatabaseContext wrongContext = IntegrityCheckTest.createContext(InternalField.KEY_FIELD, "Knuth2014a"); - wrongContext.getDatabase().getEntries().get(0).setField(StandardField.AUTHOR, "Knuth"); - wrongContext.getDatabase().getEntries().get(0).setField(StandardField.YEAR, "2014"); - IntegrityCheckTest.assertWrong(wrongContext); + 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/IntegrityCheckTest.java b/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java index 0d7d855289b..4b2dddecb0d 100644 --- a/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java +++ b/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java @@ -1,7 +1,11 @@ package org.jabref.logic.integrity; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.UUID; import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; @@ -22,8 +26,12 @@ import org.jabref.model.metadata.MetaData; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.mockito.Mockito; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; class IntegrityCheckTest { @@ -48,6 +56,32 @@ void bibLaTexAcceptsStandardEntryType() { assertCorrect(withMode(createContext(StandardField.TITLE, "sometitle", StandardEntryType.Article), BibDatabaseMode.BIBLATEX)); } + @Test + void testFileChecks() { + MetaData metaData = mock(MetaData.class); + Mockito.when(metaData.getDefaultFileDirectory()).thenReturn(Optional.of(".")); + Mockito.when(metaData.getUserFileDirectory(any(String.class))).thenReturn(Optional.empty()); + // FIXME: must be set as checkBibtexDatabase only activates title checker based on database mode + Mockito.when(metaData.getMode()).thenReturn(Optional.of(BibDatabaseMode.BIBTEX)); + + assertCorrect(createContext(StandardField.FILE, ":build.gradle:gradle", metaData)); + assertCorrect(createContext(StandardField.FILE, "description:build.gradle:gradle", metaData)); + assertWrong(createContext(StandardField.FILE, ":asflakjfwofja:PDF", metaData)); + } + + @Test + void fileCheckFindsFilesRelativeToBibFile(@TempDir Path testFolder) throws IOException { + Path bibFile = testFolder.resolve("lit.bib"); + Files.createFile(bibFile); + Path pdfFile = testFolder.resolve("file.pdf"); + Files.createFile(pdfFile); + + BibDatabaseContext databaseContext = createContext(StandardField.FILE, ":file.pdf:PDF"); + databaseContext.setDatabasePath(bibFile); + + assertCorrect(databaseContext); + } + @Test void testEntryIsUnchangedAfterChecks() { BibEntry entry = new BibEntry(); @@ -75,7 +109,7 @@ void testEntryIsUnchangedAfterChecks() { assertEquals(clonedEntry, entry); } - protected static BibDatabaseContext createContext(Field field, String value, EntryType type) { + private BibDatabaseContext createContext(Field field, String value, EntryType type) { BibEntry entry = new BibEntry(); entry.setField(field, value); entry.setType(type); @@ -84,7 +118,7 @@ protected static BibDatabaseContext createContext(Field field, String value, Ent return new BibDatabaseContext(bibDatabase); } - protected static BibDatabaseContext createContext(Field field, String value, MetaData metaData) { + private BibDatabaseContext createContext(Field field, String value, MetaData metaData) { BibEntry entry = new BibEntry(); entry.setField(field, value); BibDatabase bibDatabase = new BibDatabase(); @@ -92,13 +126,13 @@ protected static BibDatabaseContext createContext(Field field, String value, Met return new BibDatabaseContext(bibDatabase, metaData); } - protected static BibDatabaseContext createContext(Field field, String value) { + private BibDatabaseContext createContext(Field field, String value) { MetaData metaData = new MetaData(); metaData.setMode(BibDatabaseMode.BIBTEX); return createContext(field, value, metaData); } - protected static void assertWrong(BibDatabaseContext context) { + private void assertWrong(BibDatabaseContext context) { List messages = new IntegrityCheck(context, mock(FilePreferences.class), createBibtexKeyPatternPreferences(), @@ -107,7 +141,7 @@ protected static void assertWrong(BibDatabaseContext context) { assertNotEquals(Collections.emptyList(), messages); } - protected static void assertCorrect(BibDatabaseContext context) { + private void assertCorrect(BibDatabaseContext context) { List messages = new IntegrityCheck(context, mock(FilePreferences.class), createBibtexKeyPatternPreferences(), @@ -116,16 +150,16 @@ protected static void assertCorrect(BibDatabaseContext context) { assertEquals(Collections.emptyList(), messages); } - protected static void assertCorrect(BibDatabaseContext context, boolean allowIntegerEdition) { + private void assertCorrect(BibDatabaseContext context, boolean allowIntegerEdition) { List messages = new IntegrityCheck(context, mock(FilePreferences.class), createBibtexKeyPatternPreferences(), - new JournalAbbreviationRepository(new Abbreviation("IEEE Software", "IEEE SW")), true, + JournalAbbreviationLoader.loadBuiltInRepository(), allowIntegerEdition).checkDatabase(); assertEquals(Collections.emptyList(), messages); } - private static BibtexKeyPatternPreferences createBibtexKeyPatternPreferences() { + private BibtexKeyPatternPreferences createBibtexKeyPatternPreferences() { final GlobalBibtexKeyPattern keyPattern = GlobalBibtexKeyPattern.fromPattern("[auth][year]"); return new BibtexKeyPatternPreferences( "", @@ -138,7 +172,7 @@ private static BibtexKeyPatternPreferences createBibtexKeyPatternPreferences() { BibtexKeyGenerator.DEFAULT_UNWANTED_CHARACTERS); } - protected static BibDatabaseContext withMode(BibDatabaseContext context, BibDatabaseMode mode) { + private BibDatabaseContext withMode(BibDatabaseContext context, BibDatabaseMode mode) { context.setMode(mode); return context; } From 207b28f41080eae124fc69b4125c215bfff6e0af Mon Sep 17 00:00:00 2001 From: dimitra-karadima Date: Thu, 7 May 2020 15:39:34 +0300 Subject: [PATCH 07/14] Change JournalInAbbreviationListCheckerTest Due to recent merges to master the JournalAbbreviationRepository constructor changed so the creation of the object changes as well. --- .../integrity/JournalInAbbreviationListCheckerTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/jabref/logic/integrity/JournalInAbbreviationListCheckerTest.java b/src/test/java/org/jabref/logic/integrity/JournalInAbbreviationListCheckerTest.java index de5d105682a..d770c75f835 100644 --- a/src/test/java/org/jabref/logic/integrity/JournalInAbbreviationListCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/JournalInAbbreviationListCheckerTest.java @@ -1,9 +1,11 @@ package org.jabref.logic.integrity; +import java.nio.file.Path; 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; @@ -18,12 +20,13 @@ public class JournalInAbbreviationListCheckerTest { private JournalInAbbreviationListChecker checker; private JournalInAbbreviationListChecker checkerb; private JournalAbbreviationRepository abbreviationRepository; - private Abbreviation a; private BibEntry entry; + Path file; @BeforeEach void setUp() { - abbreviationRepository = new JournalAbbreviationRepository(new Abbreviation("IEEE Software", "IEEE SW")); + 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(); From 1544c73eeda835fe462dcdd1c874e50c0fe7e281 Mon Sep 17 00:00:00 2001 From: dimitra-karadima Date: Thu, 7 May 2020 15:43:54 +0300 Subject: [PATCH 08/14] Remove @BeforeEach from test classes Remove it wherever it was just creating objects --- .../integrity/ASCIICharacterCheckerTest.java | 11 +--- .../logic/integrity/BibStringCheckerTest.java | 11 +--- .../logic/integrity/BooktitleCheckerTest.java | 8 +-- .../logic/integrity/BracketCheckerTest.java | 8 +-- .../integrity/DOIValidityCheckerTest.java | 8 +-- .../logic/integrity/DateCheckerTest.java | 8 +-- .../logic/integrity/FileCheckerTest.java | 58 ------------------- .../integrity/HTMLCharacterCheckerTest.java | 11 +--- .../logic/integrity/ISBNCheckerTest.java | 8 +-- .../logic/integrity/ISSNCheckerTest.java | 8 +-- .../logic/integrity/TypeCheckerTest.java | 8 +-- .../logic/integrity/UrlCheckerTest.java | 8 +-- .../logic/integrity/YearCheckerTest.java | 8 +-- 13 files changed, 15 insertions(+), 148 deletions(-) delete mode 100644 src/test/java/org/jabref/logic/integrity/FileCheckerTest.java diff --git a/src/test/java/org/jabref/logic/integrity/ASCIICharacterCheckerTest.java b/src/test/java/org/jabref/logic/integrity/ASCIICharacterCheckerTest.java index 66678c4590d..0b5ca6a9d9e 100644 --- a/src/test/java/org/jabref/logic/integrity/ASCIICharacterCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/ASCIICharacterCheckerTest.java @@ -6,21 +6,14 @@ 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 ASCIICharacterCheckerTest { - private ASCIICharacterChecker checker; - private BibEntry entry; - - @BeforeEach - void setUp() { - checker = new ASCIICharacterChecker(); - entry = new BibEntry(); - } + private final ASCIICharacterChecker checker = new ASCIICharacterChecker(); + private final BibEntry entry = new BibEntry(); @Test void fieldAcceptsAsciiCharacters() { diff --git a/src/test/java/org/jabref/logic/integrity/BibStringCheckerTest.java b/src/test/java/org/jabref/logic/integrity/BibStringCheckerTest.java index 2cd1191feb5..dba7f6bb196 100644 --- a/src/test/java/org/jabref/logic/integrity/BibStringCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/BibStringCheckerTest.java @@ -6,21 +6,14 @@ 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 BibStringCheckerTest { - private BibStringChecker checker; - private BibEntry entry; - - @BeforeEach - void setUp() { - checker = new BibStringChecker(); - entry = new BibEntry(); - } + private final BibStringChecker checker = new BibStringChecker(); + private final BibEntry entry = new BibEntry(); @Test void fieldAcceptsNoHashMarks() { diff --git a/src/test/java/org/jabref/logic/integrity/BooktitleCheckerTest.java b/src/test/java/org/jabref/logic/integrity/BooktitleCheckerTest.java index 30af7eae7f2..e7014420af5 100644 --- a/src/test/java/org/jabref/logic/integrity/BooktitleCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/BooktitleCheckerTest.java @@ -2,7 +2,6 @@ import java.util.Optional; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,12 +9,7 @@ public class BooktitleCheckerTest { - private BooktitleChecker checker; - - @BeforeEach - public void setUp() { - checker = new BooktitleChecker(); - } + private final BooktitleChecker checker = new BooktitleChecker(); @Test void booktitleAcceptsIfItDoesNotEndWithConferenceOn() { diff --git a/src/test/java/org/jabref/logic/integrity/BracketCheckerTest.java b/src/test/java/org/jabref/logic/integrity/BracketCheckerTest.java index 3824ccda8ee..4b5762edafd 100644 --- a/src/test/java/org/jabref/logic/integrity/BracketCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/BracketCheckerTest.java @@ -2,7 +2,6 @@ import java.util.Optional; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,12 +9,7 @@ public class BracketCheckerTest { - private BracketChecker checker; - - @BeforeEach - void setUp() { - checker = new BracketChecker(); - } + private final BracketChecker checker = new BracketChecker(); @Test void fieldAcceptsNoBrackets() { diff --git a/src/test/java/org/jabref/logic/integrity/DOIValidityCheckerTest.java b/src/test/java/org/jabref/logic/integrity/DOIValidityCheckerTest.java index 5b931043be6..fd0893186c6 100644 --- a/src/test/java/org/jabref/logic/integrity/DOIValidityCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/DOIValidityCheckerTest.java @@ -2,7 +2,6 @@ import java.util.Optional; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,12 +9,7 @@ public class DOIValidityCheckerTest { - private DOIValidityChecker checker; - - @BeforeEach - void setUp() { - checker = new DOIValidityChecker(); - } + private final DOIValidityChecker checker = new DOIValidityChecker(); @Test void doiAcceptsValidInput() { 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/FileCheckerTest.java b/src/test/java/org/jabref/logic/integrity/FileCheckerTest.java deleted file mode 100644 index 71db9a1eba6..00000000000 --- a/src/test/java/org/jabref/logic/integrity/FileCheckerTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.jabref.logic.integrity; - -import java.util.List; -import java.util.Optional; - -import org.jabref.model.database.BibDatabaseContext; -import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.metadata.FilePreferences; -import org.jabref.model.metadata.MetaData; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; - -public class FileCheckerTest { - - private FileChecker checker; - private BibEntry entry; - private BibDatabaseContext bibDatabaseContext; - private List messages; - MetaData metaData = mock(MetaData.class); - //private FilePreferences f; - //Map hash; - - @BeforeEach - void setUp() { - //hash.put(StandardField.ABSTRACT, ""); - //f = new FilePreferences("", hash, true, "", ""); - bibDatabaseContext = new BibDatabaseContext(); - checker = new FileChecker(bibDatabaseContext, mock(FilePreferences.class)); - entry = new BibEntry(); - Mockito.when(metaData.getDefaultFileDirectory()).thenReturn(Optional.of(".")); - //Mockito.when(metaData.getDefaultFileDirectory()).thenReturn(Optional.empty()); - Mockito.when(metaData.getUserFileDirectory(any(String.class))).thenReturn(Optional.empty()); - // FIXME: must be set as checkBibtexDatabase only activates title checker based on database mode - Mockito.when(metaData.getMode()).thenReturn(Optional.of(BibDatabaseMode.BIBTEX)); - } - - @Test - void fileAcceptsRelativePath() { - assertEquals(Optional.empty(), checker.checkValue(":build.gradle:gradle")); - } - - @Test - void fileAcceptsFullPath() { - assertEquals(Optional.empty(), checker.checkValue("description:build.gradle:gradle")); - } - @Test - void fileDoesNotAcceptWrongPath() { - assertNotEquals(Optional.empty(), checker.checkValue(":asflakjfwofja:PDF")); - } - -} diff --git a/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java b/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java index 93c9996515b..a01ab7fbc79 100644 --- a/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java @@ -6,21 +6,14 @@ 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 HTMLCharacterCheckerTest { - private HTMLCharacterChecker checker; - private BibEntry entry; - - @BeforeEach - void setUp() { - checker = new HTMLCharacterChecker(); - entry = new BibEntry(); - } + private final HTMLCharacterChecker checker = new HTMLCharacterChecker(); + private final BibEntry entry = new BibEntry(); @Test void titleAcceptsNonHTMLEncodedCharacters() { diff --git a/src/test/java/org/jabref/logic/integrity/ISBNCheckerTest.java b/src/test/java/org/jabref/logic/integrity/ISBNCheckerTest.java index 5edc640b39e..6fbea234524 100644 --- a/src/test/java/org/jabref/logic/integrity/ISBNCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/ISBNCheckerTest.java @@ -2,7 +2,6 @@ import java.util.Optional; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,12 +9,7 @@ public class ISBNCheckerTest { - private ISBNChecker checker; - - @BeforeEach - void setUp() { - checker = new ISBNChecker(); - } + private final ISBNChecker checker = new ISBNChecker(); @Test void isbnAcceptsValidInput() { diff --git a/src/test/java/org/jabref/logic/integrity/ISSNCheckerTest.java b/src/test/java/org/jabref/logic/integrity/ISSNCheckerTest.java index f39177ead7b..350412e3ea1 100644 --- a/src/test/java/org/jabref/logic/integrity/ISSNCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/ISSNCheckerTest.java @@ -2,7 +2,6 @@ import java.util.Optional; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,12 +9,7 @@ public class ISSNCheckerTest { - private ISSNChecker checker; - - @BeforeEach - void setUp() { - checker = new ISSNChecker(); - } + private final ISSNChecker checker = new ISSNChecker(); @Test void issnAcceptsValidInput() { diff --git a/src/test/java/org/jabref/logic/integrity/TypeCheckerTest.java b/src/test/java/org/jabref/logic/integrity/TypeCheckerTest.java index 8975d3ed22d..3d2f10ac6e9 100644 --- a/src/test/java/org/jabref/logic/integrity/TypeCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/TypeCheckerTest.java @@ -7,21 +7,15 @@ import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.StandardEntryType; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class TypeCheckerTest { - private TypeChecker checker; + private final TypeChecker checker = new TypeChecker(); private BibEntry entry; - @BeforeEach - void setUp() { - checker = new TypeChecker(); - } - @Test void inProceedingshasPagesNumbers() { entry = new BibEntry(StandardEntryType.InProceedings); diff --git a/src/test/java/org/jabref/logic/integrity/UrlCheckerTest.java b/src/test/java/org/jabref/logic/integrity/UrlCheckerTest.java index 66308bf217d..747e2babe41 100644 --- a/src/test/java/org/jabref/logic/integrity/UrlCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/UrlCheckerTest.java @@ -2,7 +2,6 @@ import java.util.Optional; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,12 +9,7 @@ public class UrlCheckerTest { - private UrlChecker checker; - - @BeforeEach - void setUp() { - checker = new UrlChecker(); - } + private final UrlChecker checker = new UrlChecker(); @Test void urlFieldAcceptsHttpAddress() { diff --git a/src/test/java/org/jabref/logic/integrity/YearCheckerTest.java b/src/test/java/org/jabref/logic/integrity/YearCheckerTest.java index a5cb9da5dbd..89dfc884e5a 100644 --- a/src/test/java/org/jabref/logic/integrity/YearCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/YearCheckerTest.java @@ -2,7 +2,6 @@ import java.util.Optional; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,12 +9,7 @@ public class YearCheckerTest { - private YearChecker checker; - - @BeforeEach - void setUp() { - checker = new YearChecker(); - } + private final YearChecker checker = new YearChecker(); @Test void yearFieldAccepts21stCenturyDate() { From 16129ca2777001e367473c0a73add01a7fe22e10 Mon Sep 17 00:00:00 2001 From: dimitra-karadima Date: Thu, 7 May 2020 15:47:06 +0300 Subject: [PATCH 09/14] Rework EditionCheckerTest Remove unnecessary BibEntry initialization and import --- .../java/org/jabref/logic/integrity/EditionCheckerTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java b/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java index a1c3bae79c8..ad8a27beba0 100644 --- a/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java @@ -4,7 +4,6 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.entry.BibEntry; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -17,7 +16,6 @@ public class EditionCheckerTest { private EditionChecker checker; private EditionChecker checkerb; - private BibEntry entry; private BibDatabaseContext bibtex; private BibDatabaseContext biblatex; @@ -29,7 +27,6 @@ void setUp() { biblatex.setMode(BibDatabaseMode.BIBLATEX); checker = new EditionChecker(bibtex, true); checkerb = new EditionChecker(biblatex, true); - entry = new BibEntry(); } public BibDatabaseContext bibDatabaseContextEdition = new BibDatabaseContext(); From 870ce0da24cdc28a7e84820e7662df61e7178291 Mon Sep 17 00:00:00 2001 From: dimitra-karadima Date: Sat, 9 May 2020 12:51:39 +0300 Subject: [PATCH 10/14] Fix checkstyle Rework test class because checkstyle is failing --- .../org/jabref/logic/integrity/AbbreviationCheckerTest.java | 1 + .../java/org/jabref/logic/integrity/EditionCheckerTest.java | 3 ++- .../org/jabref/logic/integrity/HTMLCharacterCheckerTest.java | 1 - .../org/jabref/logic/integrity/HowPublishedCheckerTest.java | 1 + .../logic/integrity/JournalInAbbreviationListCheckerTest.java | 2 -- src/test/java/org/jabref/logic/integrity/MonthCheckerTest.java | 1 + src/test/java/org/jabref/logic/integrity/NoteCheckerTest.java | 1 + src/test/java/org/jabref/logic/integrity/PagesCheckerTest.java | 1 + .../org/jabref/logic/integrity/PersonNamesCheckerTest.java | 1 + src/test/java/org/jabref/logic/integrity/TitleCheckerTest.java | 1 + 10 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/jabref/logic/integrity/AbbreviationCheckerTest.java b/src/test/java/org/jabref/logic/integrity/AbbreviationCheckerTest.java index a7af1e3e21c..802e1d7c042 100644 --- a/src/test/java/org/jabref/logic/integrity/AbbreviationCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/AbbreviationCheckerTest.java @@ -5,6 +5,7 @@ import org.jabref.logic.journals.Abbreviation; import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.journals.JournalAbbreviationRepository; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java b/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java index ad8a27beba0..c6975f0310a 100644 --- a/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java @@ -4,6 +4,7 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -34,7 +35,7 @@ void setUp() { @Test void isFirstCharacterANumber() { boolean allowIntegerEdition = false; - var editionChecker = new EditionChecker(bibDatabaseContextEdition, allowIntegerEdition); + EditionChecker editionChecker = new EditionChecker(bibDatabaseContextEdition, allowIntegerEdition); assertTrue(editionChecker.isFirstCharDigit("0HelloWorld")); } diff --git a/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java b/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java index a01ab7fbc79..c2ee7af10b3 100644 --- a/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java @@ -51,5 +51,4 @@ void journalDoesNotAcceptHTMLEncodedCharacters() { 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 index bfe9b5fc3e1..c9263efadf6 100644 --- a/src/test/java/org/jabref/logic/integrity/HowPublishedCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/HowPublishedCheckerTest.java @@ -4,6 +4,7 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/src/test/java/org/jabref/logic/integrity/JournalInAbbreviationListCheckerTest.java b/src/test/java/org/jabref/logic/integrity/JournalInAbbreviationListCheckerTest.java index d770c75f835..775ca2dd7a9 100644 --- a/src/test/java/org/jabref/logic/integrity/JournalInAbbreviationListCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/JournalInAbbreviationListCheckerTest.java @@ -1,6 +1,5 @@ package org.jabref.logic.integrity; -import java.nio.file.Path; import java.util.Collections; import java.util.List; @@ -21,7 +20,6 @@ public class JournalInAbbreviationListCheckerTest { private JournalInAbbreviationListChecker checkerb; private JournalAbbreviationRepository abbreviationRepository; private BibEntry entry; - Path file; @BeforeEach void setUp() { diff --git a/src/test/java/org/jabref/logic/integrity/MonthCheckerTest.java b/src/test/java/org/jabref/logic/integrity/MonthCheckerTest.java index e79649736d5..44c1603bb81 100644 --- a/src/test/java/org/jabref/logic/integrity/MonthCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/MonthCheckerTest.java @@ -4,6 +4,7 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/src/test/java/org/jabref/logic/integrity/NoteCheckerTest.java b/src/test/java/org/jabref/logic/integrity/NoteCheckerTest.java index 865b2476fb3..aada4446f23 100644 --- a/src/test/java/org/jabref/logic/integrity/NoteCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/NoteCheckerTest.java @@ -4,6 +4,7 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/src/test/java/org/jabref/logic/integrity/PagesCheckerTest.java b/src/test/java/org/jabref/logic/integrity/PagesCheckerTest.java index 016ab020168..a6c5cd385c2 100644 --- a/src/test/java/org/jabref/logic/integrity/PagesCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/PagesCheckerTest.java @@ -4,6 +4,7 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/src/test/java/org/jabref/logic/integrity/PersonNamesCheckerTest.java b/src/test/java/org/jabref/logic/integrity/PersonNamesCheckerTest.java index 6684652e49f..60f3d652a08 100644 --- a/src/test/java/org/jabref/logic/integrity/PersonNamesCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/PersonNamesCheckerTest.java @@ -4,6 +4,7 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/src/test/java/org/jabref/logic/integrity/TitleCheckerTest.java b/src/test/java/org/jabref/logic/integrity/TitleCheckerTest.java index 9d897cfb16a..9238fdc73ef 100644 --- a/src/test/java/org/jabref/logic/integrity/TitleCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/TitleCheckerTest.java @@ -4,6 +4,7 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; From 85290507c5f381371caa1e2b693a0dc2d9894fb5 Mon Sep 17 00:00:00 2001 From: dimitra-karadima Date: Tue, 12 May 2020 00:14:12 +0300 Subject: [PATCH 11/14] Fix checkstyle again Fix because instance variable definition was in wrong order. --- .../java/org/jabref/logic/integrity/EditionCheckerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java b/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java index c6975f0310a..0baec33fded 100644 --- a/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java @@ -15,6 +15,8 @@ public class EditionCheckerTest { + public BibDatabaseContext bibDatabaseContextEdition = new BibDatabaseContext(); + private EditionChecker checker; private EditionChecker checkerb; private BibDatabaseContext bibtex; @@ -30,8 +32,6 @@ void setUp() { checkerb = new EditionChecker(biblatex, true); } - public BibDatabaseContext bibDatabaseContextEdition = new BibDatabaseContext(); - @Test void isFirstCharacterANumber() { boolean allowIntegerEdition = false; From 193d420b7ea3e72b5e59082d0ff932d1c80a5a33 Mon Sep 17 00:00:00 2001 From: dimitra-karadima Date: Tue, 12 May 2020 00:26:01 +0300 Subject: [PATCH 12/14] Rework PersonNamesCheckersTest Change from multiple test methods to two parameterized with @MethodSource --- .../integrity/PersonNamesCheckerTest.java | 60 +++++++------------ 1 file changed, 22 insertions(+), 38 deletions(-) diff --git a/src/test/java/org/jabref/logic/integrity/PersonNamesCheckerTest.java b/src/test/java/org/jabref/logic/integrity/PersonNamesCheckerTest.java index 60f3d652a08..82671114d96 100644 --- a/src/test/java/org/jabref/logic/integrity/PersonNamesCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/PersonNamesCheckerTest.java @@ -7,6 +7,8 @@ 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; @@ -14,12 +16,16 @@ 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 @@ -64,50 +70,28 @@ public void validCorporateNameAndPerson() throws Exception { assertEquals(Optional.empty(), checker.checkValue("{JabRef} and Kolb, Stefan")); } - @Test - void authorAcceptsVoidInput() { - assertEquals(Optional.empty(), checker.checkValue("")); - } - - @Test - void authorAcceptsLastNameOnly() { - assertEquals(Optional.empty(), checker.checkValue("Knuth")); - } - - @Test - void authorDoesNotAcceptSpacesBeforeFormat() { - assertNotEquals(Optional.empty(), checker.checkValue(" Knuth, Donald E. ")); - } - - @Test - void authorDoesNotAcceptDifferentFormats() { - assertNotEquals(Optional.empty(), checker.checkValue("Knuth, Donald E. and Kurt Cobain and A. Einstein")); + @ParameterizedTest + @MethodSource("provideCorrectFormats") + public void authorNameInCorrectFormatsShouldNotComplain(String input) { + assertEquals(Optional.empty(), checkerb.checkValue(input)); } - @Test - void authorAcceptsMultipleAuthors() { - assertEquals(Optional.empty(), checker.checkValue("Donald E. Knuth and Kurt Cobain and A. Einstein")); - } - - @Test - void authorCanNotStartWithComma() { - assertNotEquals(Optional.empty(), checker.checkValue(", and Kurt Cobain and A. Einstein")); - } - - @Test - void authorDoesNotAcceptCommaAsAuthor() { - assertNotEquals(Optional.empty(), checker.checkValue("Donald E. Knuth and Kurt Cobain and ,")); - + @ParameterizedTest + @MethodSource("provideIncorrectFormats") + public void authorNameInIncorrectFormatsShouldComplain(String input) { + assertNotEquals(Optional.empty(), checkerb.checkValue(input)); } - @Test - void authorCanNotStartWithAnd() { - assertNotEquals(Optional.empty(), checker.checkValue("and Kurt Cobain and A. Einstein")); + private static String[] provideCorrectFormats() { + String[] data = new String[] {"", "Knuth", "Donald E. Knuth and Kurt Cobain and A. Einstein"}; + return data; } - @Test - void authorDoesNotAcceptUnfinishedSentence() { - assertNotEquals(Optional.empty(), checker.checkValue("Donald E. Knuth and Kurt Cobain and")); + private static String[] provideIncorrectFormats() { + String[] data = new String[] {" 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"}; + return data; } } From 08afd1235e4318ec23261d7503f5ed943b6768bf Mon Sep 17 00:00:00 2001 From: dimitra-karadima Date: Tue, 12 May 2020 16:01:32 +0300 Subject: [PATCH 13/14] Update PersonNamesCheckerTest Change the return type of two methods from String[] to Stream since it is more readable. --- .../logic/integrity/PersonNamesCheckerTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/jabref/logic/integrity/PersonNamesCheckerTest.java b/src/test/java/org/jabref/logic/integrity/PersonNamesCheckerTest.java index 82671114d96..44bdb3465ac 100644 --- a/src/test/java/org/jabref/logic/integrity/PersonNamesCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/PersonNamesCheckerTest.java @@ -1,6 +1,7 @@ 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; @@ -82,16 +83,15 @@ public void authorNameInIncorrectFormatsShouldComplain(String input) { assertNotEquals(Optional.empty(), checkerb.checkValue(input)); } - private static String[] provideCorrectFormats() { - String[] data = new String[] {"", "Knuth", "Donald E. Knuth and Kurt Cobain and A. Einstein"}; - return data; + private static Stream provideCorrectFormats() { + return Stream.of("", "Knuth", "Donald E. Knuth and Kurt Cobain and A. Einstein"); } - private static String[] provideIncorrectFormats() { - String[] data = new String[] {" Knuth, Donald E. ", "Knuth, Donald E. 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"}; - return data; + "and Kurt Cobain and A. Einstein", "Donald E. Knuth and Kurt Cobain and"); } } From 4eae95ae5d25df72c0579a1868733d7a452e351a Mon Sep 17 00:00:00 2001 From: dimitra-karadima Date: Tue, 12 May 2020 16:06:04 +0300 Subject: [PATCH 14/14] Update IntegrityCheckTest Add the following changes: -Add Javadoc -Rewrite testAuthorNameChecks with @MethodSource --- .../logic/integrity/IntegrityCheckTest.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java b/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java index 4b2dddecb0d..7e78032b051 100644 --- a/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java +++ b/src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java @@ -7,6 +7,7 @@ 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; @@ -27,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; @@ -34,6 +37,12 @@ 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 @@ -56,6 +65,33 @@ void bibLaTexAcceptsStandardEntryType() { assertCorrect(withMode(createContext(StandardField.TITLE, "sometitle", StandardEntryType.Article), BibDatabaseMode.BIBLATEX)); } + @ParameterizedTest + @MethodSource("provideCorrectFormat") + void authorNameChecksCorrectFormat(String input) { + for (Field field : FieldFactory.getPersonNameFields()) { + assertCorrect(withMode(createContext(field, input), BibDatabaseMode.BIBLATEX)); + } + } + + @ParameterizedTest + @MethodSource("provideIncorrectFormat") + void authorNameChecksIncorrectFormat(String input) { + for (Field field : FieldFactory.getPersonNameFields()) { + assertWrong(withMode(createContext(field, input), BibDatabaseMode.BIBLATEX)); + } + } + + private static Stream provideCorrectFormat() { + return Stream.of("", "Knuth", "Donald E. Knuth and Kurt Cobain and A. Einstein"); + } + + 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 void testFileChecks() { MetaData metaData = mock(MetaData.class);