Skip to content

Commit d5c69cc

Browse files
committed
Parameterize tests in logic.formatter.bibtexfields
1 parent 44830a8 commit d5c69cc

File tree

4 files changed

+62
-60
lines changed

4 files changed

+62
-60
lines changed

jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveHyphenatedNewlinesFormatterTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import org.junit.jupiter.api.BeforeEach;
44
import org.junit.jupiter.api.Test;
5+
import org.junit.jupiter.params.ParameterizedTest;
6+
import org.junit.jupiter.params.provider.ValueSource;
57

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

@@ -14,11 +16,10 @@ void setUp() {
1416
formatter = new RemoveHyphenatedNewlinesFormatter();
1517
}
1618

17-
@Test
18-
void removeHyphensBeforeNewlines() {
19-
assertEquals("water", formatter.format("wa-\nter"));
20-
assertEquals("water", formatter.format("wa-\r\nter"));
21-
assertEquals("water", formatter.format("wa-\rter"));
19+
@ParameterizedTest
20+
@ValueSource(strings = {"wa-\nter", "wa-\r\nter", "wa-\rter"})
21+
void removeHyphensBeforeNewlines(String expression) {
22+
assertEquals("water", formatter.format(expression));
2223
}
2324

2425
@Test
Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package org.jabref.logic.formatter.bibtexfields;
22

33
import org.junit.jupiter.api.BeforeEach;
4-
import org.junit.jupiter.api.Test;
4+
import org.junit.jupiter.params.ParameterizedTest;
5+
import org.junit.jupiter.params.provider.ValueSource;
56

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

@@ -14,45 +15,39 @@ void setUp() {
1415
formatter = new TrimWhitespaceFormatter();
1516
}
1617

17-
@Test
18-
void removeHorizontalTabulations() {
19-
assertEquals("whitespace", formatter.format("\twhitespace"));
20-
assertEquals("whitespace", formatter.format("whitespace\t"));
21-
assertEquals("whitespace", formatter.format("\twhitespace\t\t"));
22-
}
23-
24-
@Test
25-
void removeLineFeeds() {
26-
assertEquals("whitespace", formatter.format("\nwhitespace"));
27-
assertEquals("whitespace", formatter.format("whitespace\n"));
28-
assertEquals("whitespace", formatter.format("\nwhitespace\n\n"));
29-
}
30-
31-
@Test
32-
void removeFormFeeds() {
33-
assertEquals("whitespace", formatter.format("\fwhitespace"));
34-
assertEquals("whitespace", formatter.format("whitespace\f"));
35-
assertEquals("whitespace", formatter.format("\fwhitespace\f\f"));
36-
}
37-
38-
@Test
39-
void removeCarriageReturnFeeds() {
40-
assertEquals("whitespace", formatter.format("\rwhitespace"));
41-
assertEquals("whitespace", formatter.format("whitespace\r"));
42-
assertEquals("whitespace", formatter.format("\rwhitespace\r\r"));
43-
}
44-
45-
@Test
46-
void removeSeparatorSpaces() {
47-
assertEquals("whitespace", formatter.format(" whitespace"));
48-
assertEquals("whitespace", formatter.format("whitespace "));
49-
assertEquals("whitespace", formatter.format(" whitespace "));
50-
}
51-
52-
@Test
53-
void removeMixedWhitespaceChars() {
54-
assertEquals("whitespace", formatter.format(" \r\t\fwhitespace"));
55-
assertEquals("whitespace", formatter.format("whitespace \n \r"));
56-
assertEquals("whitespace", formatter.format(" \f\t whitespace \r \n"));
18+
@ParameterizedTest
19+
@ValueSource(strings = {
20+
// remove horizontal tabulation
21+
"\twhitespace",
22+
"whitespace\t",
23+
"\twhitespace\t\t",
24+
25+
// remove line feeds
26+
"\nwhitespace",
27+
"whitespace\n",
28+
"\nwhitespace\n\n",
29+
30+
// remove form feeds
31+
"\fwhitespace",
32+
"whitespace\f",
33+
"\fwhitespace\f\f",
34+
35+
// remove carriage returns
36+
"\rwhitespace",
37+
"whitespace\r",
38+
"\rwhitespace\r\r",
39+
40+
// remove spaces
41+
" whitespace",
42+
"whitespace ",
43+
" whitespace ",
44+
45+
// remove combinations
46+
" \r\t\fwhitespace",
47+
"whitespace \n \r",
48+
" \f\t whitespace \r \n",
49+
})
50+
void removeBlankCharacters(String expression) {
51+
assertEquals("whitespace", formatter.format(expression));
5752
}
5853
}

jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeConverterTest.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import org.junit.jupiter.api.BeforeEach;
44
import org.junit.jupiter.api.Test;
5+
import org.junit.jupiter.params.ParameterizedTest;
6+
import org.junit.jupiter.params.provider.CsvSource;
57

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

@@ -22,16 +24,18 @@ void basic() {
2224
assertEquals("aaa", formatter.format("aaa"));
2325
}
2426

25-
@Test
26-
void unicodeCombiningAccents() {
27-
assertEquals("{\\\"{a}}", formatter.format("a\u0308"));
28-
assertEquals("{\\\"{a}}b", formatter.format("a\u0308b"));
29-
}
30-
31-
@Test
32-
void unicode() {
33-
assertEquals("{\\\"{a}}", formatter.format("ä"));
34-
assertEquals("{{$\\Epsilon$}}", formatter.format("\u0395"));
27+
@ParameterizedTest
28+
@CsvSource({
29+
// combining accents
30+
"{\\\"{a}}, a\u0308",
31+
"{\\\"{a}}b, a\u0308b",
32+
33+
// plain unicode letters
34+
"{\\\"{a}}, ä",
35+
"{{$\\Epsilon$}}, \u0395"
36+
})
37+
void unicode(String expected, String text) {
38+
assertEquals(expected, formatter.format(text));
3539
}
3640

3741
@Test

jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/UnitsToLatexFormatterTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import org.junit.jupiter.api.BeforeEach;
44
import org.junit.jupiter.api.Test;
5+
import org.junit.jupiter.params.ParameterizedTest;
6+
import org.junit.jupiter.params.provider.CsvSource;
57

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

@@ -17,10 +19,10 @@ void setUp() {
1719
formatter = new UnitsToLatexFormatter();
1820
}
1921

20-
@Test
21-
void test() {
22-
assertEquals("1~{A}", formatter.format("1 A"));
23-
assertEquals("1\\mbox{-}{mA}", formatter.format("1-mA"));
22+
@ParameterizedTest
23+
@CsvSource({"1~{A}, 1 A", "1\\mbox{-}{mA}, 1-mA"})
24+
void test(String expected, String text) {
25+
assertEquals(expected, formatter.format(text));
2426
}
2527

2628
@Test

0 commit comments

Comments
 (0)