-
-
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 6 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 |
---|---|---|
@@ -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 ⊕")); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")); | ||
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. Please use See the name "AbbreviationCheckerTest"? It tests the class "AbbreviationChecker". This class is instantiated in line 25. Also applies for the other checks you added. Could you please rework? 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. @koppor I changed every class that has a checkValue method. But some of them like ASCIICharacterChecker.java has a different method(public List check(BibEntry entry)). Do you want me to change those tests too? If yes can you suggest me something? Because it is like IntegrityCheck.java and you haven't made any comments on my test class. 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.
|
||
} | ||
} | ||
|
||
@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")); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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#")); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, "{")); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 – ‱")); | ||
} | ||
|
||
|
||
} |
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.
Even not conform with current JabRef classes, please use defined camel case - see https://google.github.io/styleguide/javaguide.html#s5.3-camel-case for details.