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
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.jabref.logic.integrity;

import java.util.Collections;
import java.util.List;

import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.StandardField;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class ASCIICharacterCheckerTest {

private final ASCIICharacterChecker checker = new ASCIICharacterChecker();
private final BibEntry entry = new BibEntry();

@Test
void fieldAcceptsAsciiCharacters() {
entry.setField(StandardField.TITLE, "Only ascii characters!'@12");
assertEquals(Collections.emptyList(), checker.check(entry));
}

@Test
void fieldDoesNotAcceptUmlauts() {
entry.setField(StandardField.MONTH, "Umlauts are nöt ällowed");
assertEquals(List.of(new IntegrityMessage("Non-ASCII encoded character found", entry, StandardField.MONTH)), checker.check(entry));
}

@Test
void fieldDoesNotAcceptUnicode() {
entry.setField(StandardField.AUTHOR, "Some unicode ⊕");
assertEquals(List.of(new IntegrityMessage("Non-ASCII encoded character found", entry, StandardField.AUTHOR)), checker.check(entry));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,15 @@ void checkValueDoesNotComplainAboutJournalNameThatHasSameAbbreviation() {
abbreviationRepository.addCustomAbbreviation(new Abbreviation("Journal", "Journal"));
assertEquals(Optional.empty(), checker.checkValue("Journal"));
}

@Test
void checkValueDoesNotComplainAboutJournalNameThatHasΝοAbbreviation() {
assertEquals(Optional.empty(), checker.checkValue("IEEE Software"));
}

@Test
void checkValueDoesNotComplainAboutJournalNameThatHasΝοInput() {
assertEquals(Optional.empty(), checker.checkValue(""));
}

}
47 changes: 47 additions & 0 deletions src/test/java/org/jabref/logic/integrity/BibStringCheckerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.jabref.logic.integrity;

import java.util.Collections;
import java.util.List;

import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.StandardField;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class BibStringCheckerTest {

private final BibStringChecker checker = new BibStringChecker();
private final BibEntry entry = new BibEntry();

@Test
void fieldAcceptsNoHashMarks() {
entry.setField(StandardField.TITLE, "Not a single hash mark");
assertEquals(Collections.emptyList(), checker.check(entry));
}

@Test
void monthAcceptsEvenNumberOfHashMarks() {
entry.setField(StandardField.MONTH, "#jan#");
assertEquals(Collections.emptyList(), checker.check(entry));
}

@Test
void authorAcceptsEvenNumberOfHashMarks() {
entry.setField(StandardField.AUTHOR, "#einstein# and #newton#");
assertEquals(Collections.emptyList(), checker.check(entry));
}

@Test
void monthDoesNotAcceptOddNumberOfHashMarks() {
entry.setField(StandardField.MONTH, "#jan");
assertEquals(List.of(new IntegrityMessage("odd number of unescaped '#'", entry, StandardField.MONTH)), checker.check(entry));
}

@Test
void authorDoesNotAcceptOddNumberOfHashMarks() {
entry.setField(StandardField.AUTHOR, "#einstein# #amp; #newton#");
assertEquals(List.of(new IntegrityMessage("odd number of unescaped '#'", entry, StandardField.AUTHOR)), checker.check(entry));
}
}
26 changes: 26 additions & 0 deletions src/test/java/org/jabref/logic/integrity/BibtexKeyCheckerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.jabref.logic.integrity;

import java.util.Collections;

import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.InternalField;
import org.jabref.model.entry.field.StandardField;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class BibtexKeyCheckerTest {

private final BibtexKeyChecker checker = new BibtexKeyChecker();
private final BibEntry entry = new BibEntry();

@Test
void bibTexAcceptsKeyFromAuthorAndYear() {
entry.setField(InternalField.KEY_FIELD, "Knuth2014");
entry.setField(StandardField.AUTHOR, "Knuth");
entry.setField(StandardField.YEAR, "2014");
assertEquals(Collections.emptyList(), checker.check(entry));
}

}
24 changes: 24 additions & 0 deletions src/test/java/org/jabref/logic/integrity/BooktitleCheckerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.jabref.logic.integrity;

import java.util.Optional;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

public class BooktitleCheckerTest {

private final BooktitleChecker checker = new BooktitleChecker();

@Test
void booktitleAcceptsIfItDoesNotEndWithConferenceOn() {
assertEquals(Optional.empty(), checker.checkValue("2014 Fourth International Conference on Digital Information and Communication Technology and it's Applications (DICTAP)"));
}

@Test
void booktitleDoesNotAcceptsIfItEndsWithConferenceOn() {
assertNotEquals(Optional.empty(), checker.checkValue("Digital Information and Communication Technology and it's Applications (DICTAP), 2014 Fourth International Conference on"));
}

}
44 changes: 44 additions & 0 deletions src/test/java/org/jabref/logic/integrity/BracketCheckerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.jabref.logic.integrity;

import java.util.Optional;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

public class BracketCheckerTest {

private final BracketChecker checker = new BracketChecker();

@Test
void fieldAcceptsNoBrackets() {
assertEquals(Optional.empty(), checker.checkValue("x"));
}

@Test
void fieldAcceptsEvenNumberOfBrackets() {
assertEquals(Optional.empty(), checker.checkValue("{x}"));
}

@Test
void fieldAcceptsExpectedBracket() {
assertEquals(Optional.empty(), checker.checkValue("{x}x{}x{{}}"));
}

@Test
void fieldDoesNotAcceptOddNumberOfBrackets() {
assertNotEquals(Optional.empty(), checker.checkValue("{x}x{}}x{{}}"));
}

@Test
void fieldDoesNotAcceptUnexpectedClosingBracket() {
assertNotEquals(Optional.empty(), checker.checkValue("}"));
}

@Test
void fieldDoesNotAcceptUnexpectedOpeningBracket() {
assertNotEquals(Optional.empty(), checker.checkValue("{"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.jabref.logic.integrity;

import java.util.Optional;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

public class DOIValidityCheckerTest {

private final DOIValidityChecker checker = new DOIValidityChecker();

@Test
void doiAcceptsValidInput() {
assertEquals(Optional.empty(), checker.checkValue("10.1023/A:1022883727209"));
}

@Test
void doiAcceptsValidInputWithNotOnlyNumbers() {
assertEquals(Optional.empty(), checker.checkValue("10.17487/rfc1436"));
}

@Test
void doiAcceptsValidInputNoMatterTheLengthOfTheDOIName() {
assertEquals(Optional.empty(), checker.checkValue("10.1002/(SICI)1097-4571(199205)43:4<284::AID-ASI3>3.0.CO;2-0"));
}

@Test
void doiDoesNotAcceptInvalidInput() {
assertNotEquals(Optional.empty(), checker.checkValue("asdf"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
60 changes: 59 additions & 1 deletion src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,39 @@
import java.util.Optional;

import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class EditionCheckerTest {

public BibDatabaseContext bibDatabaseContextEdition = new BibDatabaseContext();

private EditionChecker checker;
private EditionChecker checkerb;
private BibDatabaseContext bibtex;
private BibDatabaseContext biblatex;

@BeforeEach
void setUp() {
koppor marked this conversation as resolved.
Show resolved Hide resolved
bibtex = new BibDatabaseContext();
bibtex.setMode(BibDatabaseMode.BIBTEX);
biblatex = new BibDatabaseContext();
biblatex.setMode(BibDatabaseMode.BIBLATEX);
checker = new EditionChecker(bibtex, true);
checkerb = new EditionChecker(biblatex, true);
}

@Test
void isFirstCharacterANumber() {
boolean allowIntegerEdition = false;
var editionChecker = new EditionChecker(bibDatabaseContextEdition, allowIntegerEdition);
EditionChecker editionChecker = new EditionChecker(bibDatabaseContextEdition, allowIntegerEdition);
assertTrue(editionChecker.isFirstCharDigit("0HelloWorld"));
}

Expand All @@ -42,4 +60,44 @@ void editionCheckerDoesNotComplainIfAllowIntegerEditionIsEnabled() {
assertEquals(Optional.empty(), editionChecker.checkValue("2"));
}

@Test
void bibTexAcceptsOrdinalNumberInWordsWithCapitalFirstLetter() {
assertEquals(Optional.empty(), checker.checkValue("Second"));
}

@Test
void bibTexDoesNotAcceptOrdinalNumberInWordsWithNonCapitalFirstLetter() {
assertNotEquals(Optional.empty(), checker.checkValue("second"));
}

@Test
void bibTexAcceptsIntegerInputInEdition() {
assertEquals(Optional.empty(), checker.checkValue("2"));
}

@Test
void bibTexAcceptsOrdinalNumberInNumbers() {
assertEquals(Optional.empty(), checker.checkValue("2nd"));
}

@Test
void bibLaTexAcceptsEditionWithCapitalFirstLetter() {
assertEquals(Optional.empty(), checkerb.checkValue("Edition 2000"));
}

@Test
void bibLaTexAcceptsIntegerInputInEdition() {
assertEquals(Optional.empty(), checkerb.checkValue("2"));
}

@Test
void bibLaTexAcceptsEditionAsLiteralString() {
assertEquals(Optional.empty(), checkerb.checkValue("Third, revised and expanded edition"));
}

@Test
void bibLaTexDoesNotAcceptOrdinalNumberInNumbers() {
assertNotEquals(Optional.empty(), checkerb.checkValue("2nd"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.jabref.logic.integrity;

import java.util.Collections;
import java.util.List;

import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.StandardField;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class HTMLCharacterCheckerTest {

private final HTMLCharacterChecker checker = new HTMLCharacterChecker();
private final BibEntry entry = new BibEntry();

@Test
void titleAcceptsNonHTMLEncodedCharacters() {
entry.setField(StandardField.TITLE, "Not a single {HTML} character");
assertEquals(Collections.emptyList(), checker.check(entry));
}

@Test
void monthAcceptsNonHTMLEncodedCharacters() {
entry.setField(StandardField.MONTH, "#jan#");
assertEquals(Collections.emptyList(), checker.check(entry));
}

@Test
void authorAcceptsNonHTMLEncodedCharacters() {
entry.setField(StandardField.AUTHOR, "A. Einstein and I. Newton");
assertEquals(Collections.emptyList(), checker.check(entry));
}

@Test
void urlAcceptsNonHTMLEncodedCharacters() {
entry.setField(StandardField.URL, "http://www.thinkmind.org/index.php?view=article&amp;articleid=cloud_computing_2013_1_20_20130");
assertEquals(Collections.emptyList(), checker.check(entry));
}

@Test
void authorDoesNotAcceptHTMLEncodedCharacters() {
entry.setField(StandardField.AUTHOR, "Lenhard, J&#227;rg");
assertEquals(List.of(new IntegrityMessage("HTML encoded character found", entry, StandardField.AUTHOR)), checker.check(entry));
}

@Test
void journalDoesNotAcceptHTMLEncodedCharacters() {
entry.setField(StandardField.JOURNAL, "&Auml;rling Str&ouml;m for &#8211; &#x2031;");
assertEquals(List.of(new IntegrityMessage("HTML encoded character found", entry, StandardField.JOURNAL)), checker.check(entry));
}

}
Loading