-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Changes from 2 commits
b9c73fd
b37a921
fe9546d
02e8f67
b204b6b
0595351
3a4f9d7
c9320d4
ed2e7ea
dc72c05
3933821
ca9f2f4
207b28f
1544c73
16129ca
870ce0d
8529050
193d420
08afd12
4eae95a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(){},.;!?<>%&$")); | ||
} | ||
|
||
|
@@ -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)); | ||
} | ||
|
||
|
@@ -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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would move all these tests to This test class here is only for an integration test (TitleChecker is integrated in the IntegrityCheck) - the "real" functionality is in When you are on it, you could fix the capitalization in TitleCheckerTest: |
||
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 +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 | ||
|
There was a problem hiding this comment.
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: