Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple Unit Tests for #6207 #6240

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 134 additions & 6 deletions src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,40 +39,127 @@
class IntegrityCheckTest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, a JavaDoc should be added explaning the difference between this test and the CheckerTests. Here a proposal:

Suggested change
class IntegrityCheckTest {
/**
* This class tests the Integrity Checker as a whole. Aspects are: selected fields, issues arising in a complete BibTeX entry, ... When testing a checker works with a certain input, this test has to go to a test belonging to the respective checker. See PersonNamesCheckerTest for an example test.
*/
class IntegrityCheckTest {


@Test
void testEntryTypeChecks() {
void bibTexAcceptsStandardEntryType() {
assertCorrect(withMode(createContext(StandardField.TITLE, "sometitle", StandardEntryType.Article), BibDatabaseMode.BIBTEX));
}

@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(){},.;!?<>%&$"));
}

Expand All @@ -86,20 +173,39 @@ 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"));
}

@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));
}

Expand Down Expand Up @@ -186,6 +292,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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move all these tests to TitleCheckerTest and just keep one subtitle tests here.

This test class here is only for an integration test (TitleChecker is integrated in the IntegrityCheck) - the "real" functionality is in org.jabref.logic.integrity.TitleChecker.

When you are on it, you could fix the capitalization in TitleCheckerTest:

grafik

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));
Expand All @@ -194,6 +311,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
Expand Down