Skip to content

Commit efb4848

Browse files
authored
Refactoring existing unit tests (#7687)
1 parent 65874f5 commit efb4848

File tree

9 files changed

+208
-230
lines changed

9 files changed

+208
-230
lines changed

src/test/java/org/jabref/logic/formatter/casechanger/CapitalizeFormatterTest.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,13 @@ public void setUp() {
1919
formatter = new CapitalizeFormatter();
2020
}
2121

22-
@Test
23-
public void test() {
24-
assertEquals("Upper Each First", formatter.format("upper each First"));
25-
assertEquals("Upper Each First {NOT} {this}", formatter.format("upper each first {NOT} {this}"));
26-
assertEquals("Upper Each First {N}ot {t}his", formatter.format("upper each first {N}OT {t}his"));
27-
}
28-
2922
@Test
3023
public void formatExample() {
3124
assertEquals("I Have {a} Dream", formatter.format(formatter.getExampleInput()));
3225
}
3326

3427
@ParameterizedTest(name = "input={0}, formattedStr={1}")
35-
@CsvSource({
28+
@CsvSource(value = {
3629
"{}, {}", // {}
3730
"{upper, {upper", // unmatched braces
3831
"upper, Upper", // single word lower case
@@ -41,13 +34,15 @@ public void formatExample() {
4134
"upper each first, Upper Each First", // multiple words lower case
4235
"Upper Each First, Upper Each First", // multiple words correct
4336
"UPPER EACH FIRST, Upper Each First", // multiple words upper case
37+
"upper each First, Upper Each First", // multiple words in lower and upper case
4438
"{u}pp{e}r, {u}pp{e}r", // single word lower case with {}
4539
"{U}pp{e}r, {U}pp{e}r", // single word correct with {}
4640
"{U}PP{E}R, {U}pp{E}r", // single word upper case with {}
4741
"upper each {NOT} first, Upper Each {NOT} First", // multiple words lower case with {}
4842
"Upper {E}ach {NOT} First, Upper {E}ach {NOT} First", // multiple words correct with {}
4943
"UPPER {E}ACH {NOT} FIRST, Upper {E}ach {NOT} First", // multiple words upper case with {}
50-
44+
"upper each first {NOT} {this}, Upper Each First {NOT} {this}", // multiple words in lower and upper case with {}
45+
"upper each first {N}OT {t}his, Upper Each First {N}ot {t}his", // multiple words in lower and upper case with {} part 2
5146
})
5247
public void testInputs(String input, String expectedResult) {
5348
String formattedStr = formatter.format(input);
Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package org.jabref.logic.formatter.minifier;
22

3+
import java.util.stream.Stream;
4+
35
import org.junit.jupiter.api.BeforeEach;
4-
import org.junit.jupiter.api.Test;
6+
import org.junit.jupiter.params.ParameterizedTest;
7+
import org.junit.jupiter.params.provider.Arguments;
8+
import org.junit.jupiter.params.provider.MethodSource;
59

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

@@ -17,21 +21,20 @@ public void setUp() {
1721
formatter = new MinifyNameListFormatter();
1822
}
1923

20-
@Test
21-
public void minifyAuthorNames() {
22-
expectCorrect("Simon Harrer", "Simon Harrer");
23-
expectCorrect("Simon Harrer and others", "Simon Harrer and others");
24-
expectCorrect("Simon Harrer and Jörg Lenhard", "Simon Harrer and Jörg Lenhard");
25-
expectCorrect("Simon Harrer and Jörg Lenhard and Guido Wirtz", "Simon Harrer and others");
26-
expectCorrect("Simon Harrer and Jörg Lenhard and Guido Wirtz and others", "Simon Harrer and others");
27-
}
28-
29-
@Test
30-
public void formatExample() {
31-
expectCorrect(formatter.getExampleInput(), "Stefan Kolb and others");
24+
@ParameterizedTest
25+
@MethodSource("provideAuthorNames")
26+
void minifyAuthorNames(String expectedAuthorNames, String originalAuthorNames) {
27+
assertEquals(expectedAuthorNames, formatter.format(originalAuthorNames));
3228
}
3329

34-
private void expectCorrect(String input, String expected) {
35-
assertEquals(expected, formatter.format(input));
30+
private static Stream<Arguments> provideAuthorNames() {
31+
return Stream.of(
32+
Arguments.of("Simon Harrer", "Simon Harrer"),
33+
Arguments.of("Simon Harrer and others", "Simon Harrer and others"),
34+
Arguments.of("Simon Harrer and Jörg Lenhard", "Simon Harrer and Jörg Lenhard"),
35+
Arguments.of("Simon Harrer and others", "Simon Harrer and Jörg Lenhard and Guido Wirtz"),
36+
Arguments.of("Simon Harrer and others", "Simon Harrer and Jörg Lenhard and Guido Wirtz and others"),
37+
Arguments.of("Stefan Kolb and others", new MinifyNameListFormatter().getExampleInput())
38+
);
3639
}
3740
}

src/test/java/org/jabref/logic/layout/format/AuthorsTest.java

Lines changed: 46 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -10,151 +10,134 @@
1010

1111
public class AuthorsTest {
1212

13+
private ParamLayoutFormatter authorsLayoutFormatter = new Authors();
14+
1315
@Test
1416
public void testStandardUsage() {
15-
ParamLayoutFormatter a = new Authors();
1617
assertEquals("B. C. Bruce, C. Manson and J. Jumper",
17-
a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper"));
18+
authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper"));
1819
}
1920

2021
@Test
2122
public void testStandardUsageOne() {
22-
ParamLayoutFormatter a = new Authors();
23-
a.setArgument("fullname, LastFirst, Comma, Comma");
24-
assertEquals("Bruce, Bob Croydon, Jumper, Jolly", a.format("Bob Croydon Bruce and Jolly Jumper"));
23+
authorsLayoutFormatter.setArgument("fullname, LastFirst, Comma, Comma");
24+
assertEquals("Bruce, Bob Croydon, Jumper, Jolly", authorsLayoutFormatter.format("Bob Croydon Bruce and Jolly Jumper"));
2525
}
2626

2727
@Test
2828
public void testStandardUsageTwo() {
29-
ParamLayoutFormatter a = new Authors();
30-
a.setArgument("initials");
31-
assertEquals("B. C. Bruce and J. Jumper", a.format("Bob Croydon Bruce and Jolly Jumper"));
29+
authorsLayoutFormatter.setArgument("initials");
30+
assertEquals("B. C. Bruce and J. Jumper", authorsLayoutFormatter.format("Bob Croydon Bruce and Jolly Jumper"));
3231
}
3332

3433
@Test
3534
public void testStandardUsageThree() {
36-
ParamLayoutFormatter a = new Authors();
37-
a.setArgument("fullname, LastFirst, Comma");
35+
authorsLayoutFormatter.setArgument("fullname, LastFirst, Comma");
3836
assertEquals("Bruce, Bob Croydon, Manson, Charles and Jumper, Jolly",
39-
a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper"));
37+
authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper"));
4038
}
4139

4240
@Test
4341
public void testStandardUsageFour() {
44-
ParamLayoutFormatter a = new Authors();
45-
a.setArgument("fullname, LastFirst, Comma, 2");
42+
authorsLayoutFormatter.setArgument("fullname, LastFirst, Comma, 2");
4643
assertEquals("Bruce, Bob Croydon et al.",
47-
a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper"));
44+
authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper"));
4845
}
4946

5047
@Test
5148
public void testStandardUsageFive() {
52-
ParamLayoutFormatter a = new Authors();
53-
a.setArgument("fullname, LastFirst, Comma, 3");
49+
authorsLayoutFormatter.setArgument("fullname, LastFirst, Comma, 3");
5450
assertEquals("Bruce, Bob Croydon et al.",
55-
a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles"));
51+
authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles"));
5652
}
5753

5854
@Test
5955
public void testStandardUsageSix() {
60-
ParamLayoutFormatter a = new Authors();
61-
a.setArgument("fullname, LastFirst, Comma, 3, 2");
56+
authorsLayoutFormatter.setArgument("fullname, LastFirst, Comma, 3, 2");
6257
assertEquals("Bruce, Bob Croydon, Manson, Charles et al.",
63-
a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles"));
58+
authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles"));
6459
}
6560

6661
@Test
6762
public void testSpecialEtAl() {
68-
ParamLayoutFormatter a = new Authors();
69-
a.setArgument("fullname, LastFirst, Comma, 3, etal= and a few more");
63+
authorsLayoutFormatter.setArgument("fullname, LastFirst, Comma, 3, etal= and a few more");
7064
assertEquals("Bruce, Bob Croydon and a few more",
71-
a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles"));
65+
authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles"));
7266
}
7367

7468
@Test
7569
public void testStandardUsageNull() {
76-
ParamLayoutFormatter a = new Authors();
77-
assertEquals("", a.format(null));
70+
assertEquals("", authorsLayoutFormatter.format(null));
7871
}
7972

8073
@Test
8174
public void testStandardOxford() {
82-
ParamLayoutFormatter a = new Authors();
83-
a.setArgument("Oxford");
75+
authorsLayoutFormatter.setArgument("Oxford");
8476
assertEquals("B. C. Bruce, C. Manson, and J. Jumper",
85-
a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper"));
77+
authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper"));
8678
}
8779

8880
@Test
8981
public void testStandardOxfordFullName() {
90-
ParamLayoutFormatter a = new Authors();
91-
a.setArgument("FullName,Oxford");
82+
authorsLayoutFormatter.setArgument("FullName,Oxford");
9283
assertEquals("Bob Croydon Bruce, Charles Manson, and Jolly Jumper",
93-
a.format("Bruce, Bob Croydon and Charles Manson and Jolly Jumper"));
84+
authorsLayoutFormatter.format("Bruce, Bob Croydon and Charles Manson and Jolly Jumper"));
9485
}
9586

9687
@Test
9788
public void testStandardCommaFullName() {
98-
ParamLayoutFormatter a = new Authors();
99-
a.setArgument("FullName,Comma,Comma");
89+
authorsLayoutFormatter.setArgument("FullName,Comma,Comma");
10090
assertEquals("Bob Croydon Bruce, Charles Manson, Jolly Jumper",
101-
a.format("Bruce, Bob Croydon and Charles Manson and Jolly Jumper"));
91+
authorsLayoutFormatter.format("Bruce, Bob Croydon and Charles Manson and Jolly Jumper"));
10292
}
10393

10494
@Test
10595
public void testStandardAmpFullName() {
106-
ParamLayoutFormatter a = new Authors();
107-
a.setArgument("FullName,Amp");
96+
authorsLayoutFormatter.setArgument("FullName,Amp");
10897
assertEquals("Bob Croydon Bruce, Charles Manson & Jolly Jumper",
109-
a.format("Bruce, Bob Croydon and Charles Manson and Jolly Jumper"));
98+
authorsLayoutFormatter.format("Bruce, Bob Croydon and Charles Manson and Jolly Jumper"));
11099
}
111100

112101
@Test
113102
public void testLastName() {
114-
ParamLayoutFormatter a = new Authors();
115-
a.setArgument("LastName");
103+
authorsLayoutFormatter.setArgument("LastName");
116104
assertEquals("Bruce, von Manson and Jumper",
117-
a.format("Bruce, Bob Croydon and Charles von Manson and Jolly Jumper"));
105+
authorsLayoutFormatter.format("Bruce, Bob Croydon and Charles von Manson and Jolly Jumper"));
118106
}
119107

120108
@Test
121109
public void testMiddleInitial() {
122-
ParamLayoutFormatter a = new Authors();
123-
a.setArgument("MiddleInitial");
110+
authorsLayoutFormatter.setArgument("MiddleInitial");
124111
assertEquals("Bob C. Bruce, Charles K. von Manson and Jolly Jumper",
125-
a.format("Bruce, Bob Croydon and Charles Kermit von Manson and Jumper, Jolly"));
112+
authorsLayoutFormatter.format("Bruce, Bob Croydon and Charles Kermit von Manson and Jumper, Jolly"));
126113
}
127114

128115
@Test
129116
public void testNoPeriod() {
130-
ParamLayoutFormatter a = new Authors();
131-
a.setArgument("NoPeriod");
117+
authorsLayoutFormatter.setArgument("NoPeriod");
132118
assertEquals("B C Bruce, C K von Manson and J Jumper",
133-
a.format("Bruce, Bob Croydon and Charles Kermit von Manson and Jumper, Jolly"));
119+
authorsLayoutFormatter.format("Bruce, Bob Croydon and Charles Kermit von Manson and Jumper, Jolly"));
134120
}
135121

136122
@Test
137123
public void testEtAl() {
138-
ParamLayoutFormatter a = new Authors();
139-
a.setArgument("2,1");
124+
authorsLayoutFormatter.setArgument("2,1");
140125
assertEquals("B. C. Bruce et al.",
141-
a.format("Bruce, Bob Croydon and Charles Kermit von Manson and Jumper, Jolly"));
126+
authorsLayoutFormatter.format("Bruce, Bob Croydon and Charles Kermit von Manson and Jumper, Jolly"));
142127
}
143128

144129
@Test
145130
public void testEtAlNotEnoughAuthors() {
146-
ParamLayoutFormatter a = new Authors();
147-
a.setArgument("2,1");
131+
authorsLayoutFormatter.setArgument("2,1");
148132
assertEquals("B. C. Bruce and C. K. von Manson",
149-
a.format("Bruce, Bob Croydon and Charles Kermit von Manson"));
133+
authorsLayoutFormatter.format("Bruce, Bob Croydon and Charles Kermit von Manson"));
150134
}
151135

152136
@Test
153137
public void testEmptyEtAl() {
154-
ParamLayoutFormatter a = new Authors();
155-
a.setArgument("fullname, LastFirst, Comma, 3, etal=");
138+
authorsLayoutFormatter.setArgument("fullname, LastFirst, Comma, 3, etal=");
156139
assertEquals("Bruce, Bob Croydon",
157-
a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles"));
140+
authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles"));
158141
}
159142

160143
@ParameterizedTest(name = "arg={0}, formattedStr={1}")
@@ -164,9 +147,8 @@ public void testEmptyEtAl() {
164147
"LastFirstFirstFirst, 'Bruce, B. C., C. Manson, J. Jumper and C. Chuckles'" // LastFirstFirstFirst
165148
})
166149
public void testAuthorOrder(String arg, String expectedResult) {
167-
ParamLayoutFormatter a = new Authors();
168-
a.setArgument(arg);
169-
String formattedStr = a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles");
150+
authorsLayoutFormatter.setArgument(arg);
151+
String formattedStr = authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles");
170152
assertEquals(expectedResult, formattedStr);
171153
}
172154

@@ -180,9 +162,8 @@ public void testAuthorOrder(String arg, String expectedResult) {
180162
"InitialsNoSpace, 'B.C. Bruce, C. Manson, J. Jumper and C. Chuckles'" // InitialsNoSpace
181163
})
182164
public void testAuthorABRV(String arg, String expectedResult) {
183-
ParamLayoutFormatter a = new Authors();
184-
a.setArgument(arg);
185-
String formattedStr = a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles");
165+
authorsLayoutFormatter.setArgument(arg);
166+
String formattedStr = authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles");
186167
assertEquals(expectedResult, formattedStr);
187168
}
188169

@@ -194,9 +175,8 @@ public void testAuthorABRV(String arg, String expectedResult) {
194175
"NoPeriod, 'B C Bruce, C Manson, J Jumper and C Chuckles'" // NoPeriod
195176
})
196177
public void testAuthorPUNC(String arg, String expectedResult) {
197-
ParamLayoutFormatter a = new Authors();
198-
a.setArgument(arg);
199-
String formattedStr = a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles");
178+
authorsLayoutFormatter.setArgument(arg);
179+
String formattedStr = authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles");
200180
assertEquals(expectedResult, formattedStr);
201181
}
202182

@@ -217,9 +197,8 @@ public void testAuthorPUNC(String arg, String expectedResult) {
217197
"'Comma, Semicolon', 'B. C. Bruce, C. Manson, J. Jumper; C. Chuckles'", // Comma Semicolon
218198
})
219199
public void testAuthorSEPARATORS(String arg, String expectedResult) {
220-
ParamLayoutFormatter a = new Authors();
221-
a.setArgument(arg);
222-
String formattedStr = a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles");
200+
authorsLayoutFormatter.setArgument(arg);
201+
String formattedStr = authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles");
223202
assertEquals(expectedResult, formattedStr);
224203
}
225204
}
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
package org.jabref.logic.layout.format;
22

3+
import java.util.stream.Stream;
4+
35
import org.jabref.logic.layout.LayoutFormatter;
46

5-
import org.junit.jupiter.api.Test;
7+
import org.junit.jupiter.params.ParameterizedTest;
8+
import org.junit.jupiter.params.provider.Arguments;
9+
import org.junit.jupiter.params.provider.MethodSource;
610

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

913
public class DOICheckTest {
1014

11-
@Test
12-
public void testFormat() {
13-
LayoutFormatter lf = new DOICheck();
14-
15-
assertEquals("", lf.format(""));
16-
assertEquals(null, lf.format(null));
17-
18-
assertEquals("https://doi.org/10.1000/ISBN1-900512-44-0", lf.format("10.1000/ISBN1-900512-44-0"));
19-
assertEquals("https://doi.org/10.1000/ISBN1-900512-44-0",
20-
lf.format("http://dx.doi.org/10.1000/ISBN1-900512-44-0"));
21-
22-
assertEquals("https://doi.org/10.1000/ISBN1-900512-44-0",
23-
lf.format("http://doi.acm.org/10.1000/ISBN1-900512-44-0"));
15+
private LayoutFormatter layoutFormatter = new DOICheck();
2416

25-
assertEquals("https://doi.org/10.1145/354401.354407",
26-
lf.format("http://doi.acm.org/10.1145/354401.354407"));
27-
assertEquals("https://doi.org/10.1145/354401.354407", lf.format("10.1145/354401.354407"));
28-
29-
// Works even when having a / at the front
30-
assertEquals("https://doi.org/10.1145/354401.354407", lf.format("/10.1145/354401.354407"));
31-
32-
// Obviously a wrong doi, will not change anything.
33-
assertEquals("10", lf.format("10"));
17+
@ParameterizedTest
18+
@MethodSource("provideDOI")
19+
void formatDOI(String formattedDOI, String originalDOI) {
20+
assertEquals(formattedDOI, layoutFormatter.format(originalDOI));
21+
}
3422

35-
// Obviously a wrong doi, will not change anything.
36-
assertEquals("1", lf.format("1"));
23+
private static Stream<Arguments> provideDOI() {
24+
return Stream.of(
25+
Arguments.of("", ""),
26+
Arguments.of(null, null),
27+
Arguments.of("https://doi.org/10.1000/ISBN1-900512-44-0", "10.1000/ISBN1-900512-44-0"),
28+
Arguments.of("https://doi.org/10.1000/ISBN1-900512-44-0", "http://dx.doi.org/10.1000/ISBN1-900512-44-0"),
29+
Arguments.of("https://doi.org/10.1000/ISBN1-900512-44-0", "http://doi.acm.org/10.1000/ISBN1-900512-44-0"),
30+
Arguments.of("https://doi.org/10.1145/354401.354407", "http://doi.acm.org/10.1145/354401.354407"),
31+
Arguments.of("https://doi.org/10.1145/354401.354407", "10.1145/354401.354407"),
32+
Arguments.of("https://doi.org/10.1145/354401.354407", "/10.1145/354401.354407"),
33+
Arguments.of("10", "10"),
34+
Arguments.of("1", "1")
35+
36+
);
3737
}
3838
}

0 commit comments

Comments
 (0)