Skip to content

Commit fdef92e

Browse files
Add simple Unit Tests for #6207 (#6240)
1 parent 4e220f6 commit fdef92e

24 files changed

+1158
-293
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.jabref.logic.integrity;
2+
3+
import java.util.Collections;
4+
import java.util.List;
5+
6+
import org.jabref.model.entry.BibEntry;
7+
import org.jabref.model.entry.field.StandardField;
8+
9+
import org.junit.jupiter.api.Test;
10+
11+
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
13+
public class ASCIICharacterCheckerTest {
14+
15+
private final ASCIICharacterChecker checker = new ASCIICharacterChecker();
16+
private final BibEntry entry = new BibEntry();
17+
18+
@Test
19+
void fieldAcceptsAsciiCharacters() {
20+
entry.setField(StandardField.TITLE, "Only ascii characters!'@12");
21+
assertEquals(Collections.emptyList(), checker.check(entry));
22+
}
23+
24+
@Test
25+
void fieldDoesNotAcceptUmlauts() {
26+
entry.setField(StandardField.MONTH, "Umlauts are nöt ällowed");
27+
assertEquals(List.of(new IntegrityMessage("Non-ASCII encoded character found", entry, StandardField.MONTH)), checker.check(entry));
28+
}
29+
30+
@Test
31+
void fieldDoesNotAcceptUnicode() {
32+
entry.setField(StandardField.AUTHOR, "Some unicode ⊕");
33+
assertEquals(List.of(new IntegrityMessage("Non-ASCII encoded character found", entry, StandardField.AUTHOR)), checker.check(entry));
34+
}
35+
36+
}

src/test/java/org/jabref/logic/integrity/AbbreviationCheckerTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,15 @@ void checkValueDoesNotComplainAboutJournalNameThatHasSameAbbreviation() {
3434
abbreviationRepository.addCustomAbbreviation(new Abbreviation("Journal", "Journal"));
3535
assertEquals(Optional.empty(), checker.checkValue("Journal"));
3636
}
37+
38+
@Test
39+
void checkValueDoesNotComplainAboutJournalNameThatHasΝοAbbreviation() {
40+
assertEquals(Optional.empty(), checker.checkValue("IEEE Software"));
41+
}
42+
43+
@Test
44+
void checkValueDoesNotComplainAboutJournalNameThatHasΝοInput() {
45+
assertEquals(Optional.empty(), checker.checkValue(""));
46+
}
47+
3748
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.jabref.logic.integrity;
2+
3+
import java.util.Collections;
4+
import java.util.List;
5+
6+
import org.jabref.model.entry.BibEntry;
7+
import org.jabref.model.entry.field.StandardField;
8+
9+
import org.junit.jupiter.api.Test;
10+
11+
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
13+
public class BibStringCheckerTest {
14+
15+
private final BibStringChecker checker = new BibStringChecker();
16+
private final BibEntry entry = new BibEntry();
17+
18+
@Test
19+
void fieldAcceptsNoHashMarks() {
20+
entry.setField(StandardField.TITLE, "Not a single hash mark");
21+
assertEquals(Collections.emptyList(), checker.check(entry));
22+
}
23+
24+
@Test
25+
void monthAcceptsEvenNumberOfHashMarks() {
26+
entry.setField(StandardField.MONTH, "#jan#");
27+
assertEquals(Collections.emptyList(), checker.check(entry));
28+
}
29+
30+
@Test
31+
void authorAcceptsEvenNumberOfHashMarks() {
32+
entry.setField(StandardField.AUTHOR, "#einstein# and #newton#");
33+
assertEquals(Collections.emptyList(), checker.check(entry));
34+
}
35+
36+
@Test
37+
void monthDoesNotAcceptOddNumberOfHashMarks() {
38+
entry.setField(StandardField.MONTH, "#jan");
39+
assertEquals(List.of(new IntegrityMessage("odd number of unescaped '#'", entry, StandardField.MONTH)), checker.check(entry));
40+
}
41+
42+
@Test
43+
void authorDoesNotAcceptOddNumberOfHashMarks() {
44+
entry.setField(StandardField.AUTHOR, "#einstein# #amp; #newton#");
45+
assertEquals(List.of(new IntegrityMessage("odd number of unescaped '#'", entry, StandardField.AUTHOR)), checker.check(entry));
46+
}
47+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.jabref.logic.integrity;
2+
3+
import java.util.Collections;
4+
5+
import org.jabref.model.entry.BibEntry;
6+
import org.jabref.model.entry.field.InternalField;
7+
import org.jabref.model.entry.field.StandardField;
8+
9+
import org.junit.jupiter.api.Test;
10+
11+
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
13+
public class BibtexKeyCheckerTest {
14+
15+
private final BibtexKeyChecker checker = new BibtexKeyChecker();
16+
private final BibEntry entry = new BibEntry();
17+
18+
@Test
19+
void bibTexAcceptsKeyFromAuthorAndYear() {
20+
entry.setField(InternalField.KEY_FIELD, "Knuth2014");
21+
entry.setField(StandardField.AUTHOR, "Knuth");
22+
entry.setField(StandardField.YEAR, "2014");
23+
assertEquals(Collections.emptyList(), checker.check(entry));
24+
}
25+
26+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.jabref.logic.integrity;
2+
3+
import java.util.Optional;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
9+
10+
public class BooktitleCheckerTest {
11+
12+
private final BooktitleChecker checker = new BooktitleChecker();
13+
14+
@Test
15+
void booktitleAcceptsIfItDoesNotEndWithConferenceOn() {
16+
assertEquals(Optional.empty(), checker.checkValue("2014 Fourth International Conference on Digital Information and Communication Technology and it's Applications (DICTAP)"));
17+
}
18+
19+
@Test
20+
void booktitleDoesNotAcceptsIfItEndsWithConferenceOn() {
21+
assertNotEquals(Optional.empty(), checker.checkValue("Digital Information and Communication Technology and it's Applications (DICTAP), 2014 Fourth International Conference on"));
22+
}
23+
24+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.jabref.logic.integrity;
2+
3+
import java.util.Optional;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
9+
10+
public class BracketCheckerTest {
11+
12+
private final BracketChecker checker = new BracketChecker();
13+
14+
@Test
15+
void fieldAcceptsNoBrackets() {
16+
assertEquals(Optional.empty(), checker.checkValue("x"));
17+
}
18+
19+
@Test
20+
void fieldAcceptsEvenNumberOfBrackets() {
21+
assertEquals(Optional.empty(), checker.checkValue("{x}"));
22+
}
23+
24+
@Test
25+
void fieldAcceptsExpectedBracket() {
26+
assertEquals(Optional.empty(), checker.checkValue("{x}x{}x{{}}"));
27+
}
28+
29+
@Test
30+
void fieldDoesNotAcceptOddNumberOfBrackets() {
31+
assertNotEquals(Optional.empty(), checker.checkValue("{x}x{}}x{{}}"));
32+
}
33+
34+
@Test
35+
void fieldDoesNotAcceptUnexpectedClosingBracket() {
36+
assertNotEquals(Optional.empty(), checker.checkValue("}"));
37+
}
38+
39+
@Test
40+
void fieldDoesNotAcceptUnexpectedOpeningBracket() {
41+
assertNotEquals(Optional.empty(), checker.checkValue("{"));
42+
}
43+
44+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.jabref.logic.integrity;
2+
3+
import java.util.Optional;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
9+
10+
public class DOIValidityCheckerTest {
11+
12+
private final DOIValidityChecker checker = new DOIValidityChecker();
13+
14+
@Test
15+
void doiAcceptsValidInput() {
16+
assertEquals(Optional.empty(), checker.checkValue("10.1023/A:1022883727209"));
17+
}
18+
19+
@Test
20+
void doiAcceptsValidInputWithNotOnlyNumbers() {
21+
assertEquals(Optional.empty(), checker.checkValue("10.17487/rfc1436"));
22+
}
23+
24+
@Test
25+
void doiAcceptsValidInputNoMatterTheLengthOfTheDOIName() {
26+
assertEquals(Optional.empty(), checker.checkValue("10.1002/(SICI)1097-4571(199205)43:4<284::AID-ASI3>3.0.CO;2-0"));
27+
}
28+
29+
@Test
30+
void doiDoesNotAcceptInvalidInput() {
31+
assertNotEquals(Optional.empty(), checker.checkValue("asdf"));
32+
}
33+
34+
}

src/test/java/org/jabref/logic/integrity/DateCheckerTest.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,13 @@
22

33
import java.util.Optional;
44

5-
import org.junit.jupiter.api.BeforeEach;
65
import org.junit.jupiter.api.Test;
76

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

109
class DateCheckerTest {
1110

12-
private DateChecker checker;
13-
14-
@BeforeEach
15-
void setUp() {
16-
checker = new DateChecker();
17-
}
11+
private final DateChecker checker = new DateChecker();
1812

1913
@Test
2014
void complainsAboutInvalidIsoLikeDate() {

src/test/java/org/jabref/logic/integrity/EditionCheckerTest.java

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,39 @@
33
import java.util.Optional;
44

55
import org.jabref.model.database.BibDatabaseContext;
6+
import org.jabref.model.database.BibDatabaseMode;
67

8+
import org.junit.jupiter.api.BeforeEach;
79
import org.junit.jupiter.api.Test;
810

911
import static org.junit.jupiter.api.Assertions.assertEquals;
1012
import static org.junit.jupiter.api.Assertions.assertFalse;
13+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
1114
import static org.junit.jupiter.api.Assertions.assertTrue;
1215

1316
public class EditionCheckerTest {
1417

1518
public BibDatabaseContext bibDatabaseContextEdition = new BibDatabaseContext();
1619

20+
private EditionChecker checker;
21+
private EditionChecker checkerb;
22+
private BibDatabaseContext bibtex;
23+
private BibDatabaseContext biblatex;
24+
25+
@BeforeEach
26+
void setUp() {
27+
bibtex = new BibDatabaseContext();
28+
bibtex.setMode(BibDatabaseMode.BIBTEX);
29+
biblatex = new BibDatabaseContext();
30+
biblatex.setMode(BibDatabaseMode.BIBLATEX);
31+
checker = new EditionChecker(bibtex, true);
32+
checkerb = new EditionChecker(biblatex, true);
33+
}
34+
1735
@Test
1836
void isFirstCharacterANumber() {
1937
boolean allowIntegerEdition = false;
20-
var editionChecker = new EditionChecker(bibDatabaseContextEdition, allowIntegerEdition);
38+
EditionChecker editionChecker = new EditionChecker(bibDatabaseContextEdition, allowIntegerEdition);
2139
assertTrue(editionChecker.isFirstCharDigit("0HelloWorld"));
2240
}
2341

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

63+
@Test
64+
void bibTexAcceptsOrdinalNumberInWordsWithCapitalFirstLetter() {
65+
assertEquals(Optional.empty(), checker.checkValue("Second"));
66+
}
67+
68+
@Test
69+
void bibTexDoesNotAcceptOrdinalNumberInWordsWithNonCapitalFirstLetter() {
70+
assertNotEquals(Optional.empty(), checker.checkValue("second"));
71+
}
72+
73+
@Test
74+
void bibTexAcceptsIntegerInputInEdition() {
75+
assertEquals(Optional.empty(), checker.checkValue("2"));
76+
}
77+
78+
@Test
79+
void bibTexAcceptsOrdinalNumberInNumbers() {
80+
assertEquals(Optional.empty(), checker.checkValue("2nd"));
81+
}
82+
83+
@Test
84+
void bibLaTexAcceptsEditionWithCapitalFirstLetter() {
85+
assertEquals(Optional.empty(), checkerb.checkValue("Edition 2000"));
86+
}
87+
88+
@Test
89+
void bibLaTexAcceptsIntegerInputInEdition() {
90+
assertEquals(Optional.empty(), checkerb.checkValue("2"));
91+
}
92+
93+
@Test
94+
void bibLaTexAcceptsEditionAsLiteralString() {
95+
assertEquals(Optional.empty(), checkerb.checkValue("Third, revised and expanded edition"));
96+
}
97+
98+
@Test
99+
void bibLaTexDoesNotAcceptOrdinalNumberInNumbers() {
100+
assertNotEquals(Optional.empty(), checkerb.checkValue("2nd"));
101+
}
102+
45103
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.jabref.logic.integrity;
2+
3+
import java.util.Collections;
4+
import java.util.List;
5+
6+
import org.jabref.model.entry.BibEntry;
7+
import org.jabref.model.entry.field.StandardField;
8+
9+
import org.junit.jupiter.api.Test;
10+
11+
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
13+
public class HTMLCharacterCheckerTest {
14+
15+
private final HTMLCharacterChecker checker = new HTMLCharacterChecker();
16+
private final BibEntry entry = new BibEntry();
17+
18+
@Test
19+
void titleAcceptsNonHTMLEncodedCharacters() {
20+
entry.setField(StandardField.TITLE, "Not a single {HTML} character");
21+
assertEquals(Collections.emptyList(), checker.check(entry));
22+
}
23+
24+
@Test
25+
void monthAcceptsNonHTMLEncodedCharacters() {
26+
entry.setField(StandardField.MONTH, "#jan#");
27+
assertEquals(Collections.emptyList(), checker.check(entry));
28+
}
29+
30+
@Test
31+
void authorAcceptsNonHTMLEncodedCharacters() {
32+
entry.setField(StandardField.AUTHOR, "A. Einstein and I. Newton");
33+
assertEquals(Collections.emptyList(), checker.check(entry));
34+
}
35+
36+
@Test
37+
void urlAcceptsNonHTMLEncodedCharacters() {
38+
entry.setField(StandardField.URL, "http://www.thinkmind.org/index.php?view=article&amp;articleid=cloud_computing_2013_1_20_20130");
39+
assertEquals(Collections.emptyList(), checker.check(entry));
40+
}
41+
42+
@Test
43+
void authorDoesNotAcceptHTMLEncodedCharacters() {
44+
entry.setField(StandardField.AUTHOR, "Lenhard, J&#227;rg");
45+
assertEquals(List.of(new IntegrityMessage("HTML encoded character found", entry, StandardField.AUTHOR)), checker.check(entry));
46+
}
47+
48+
@Test
49+
void journalDoesNotAcceptHTMLEncodedCharacters() {
50+
entry.setField(StandardField.JOURNAL, "&Auml;rling Str&ouml;m for &#8211; &#x2031;");
51+
assertEquals(List.of(new IntegrityMessage("HTML encoded character found", entry, StandardField.JOURNAL)), checker.check(entry));
52+
}
53+
54+
}

0 commit comments

Comments
 (0)