Skip to content

Commit b15791b

Browse files
committed
JUnit bump 4 -> 5
1 parent fedabff commit b15791b

19 files changed

+198
-230
lines changed

api/pom.xml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@
7777
<spotbugs.skip>false</spotbugs.skip>
7878
<spotbugs.threshold>Low</spotbugs.threshold>
7979
<spotbugs.exclude>${project.basedir}/../spotbugs-exclude.xml</spotbugs.exclude>
80-
<!--Maven plugins version-->
80+
<!--Maven dependencies and plugins version-->
8181
<spotbugs.version>4.4.2.2</spotbugs.version>
82+
<junit.version>5.9.0</junit.version>
8283
</properties>
8384

8485
<dependencyManagement>
@@ -94,9 +95,14 @@
9495
<version>1.0.0-M2</version>
9596
</dependency>
9697
<dependency>
97-
<groupId>junit</groupId>
98-
<artifactId>junit</artifactId>
99-
<version>4.13.2</version>
98+
<groupId>org.junit.jupiter</groupId>
99+
<artifactId>junit-jupiter-api</artifactId>
100+
<version>${junit.version}</version>
101+
</dependency>
102+
<dependency>
103+
<groupId>org.junit.jupiter</groupId>
104+
<artifactId>junit-jupiter-params</artifactId>
105+
<version>${junit.version}</version>
100106
</dependency>
101107
</dependencies>
102108
</dependencyManagement>
@@ -107,8 +113,19 @@
107113
<artifactId>jakarta.activation-api</artifactId>
108114
</dependency>
109115
<dependency>
110-
<groupId>junit</groupId>
111-
<artifactId>junit</artifactId>
116+
<groupId>org.junit.jupiter</groupId>
117+
<artifactId>junit-jupiter-api</artifactId>
118+
<scope>test</scope>
119+
</dependency>
120+
<dependency>
121+
<groupId>org.junit.jupiter</groupId>
122+
<artifactId>junit-jupiter-params</artifactId>
123+
<scope>test</scope>
124+
</dependency>
125+
<dependency>
126+
<groupId>org.hamcrest</groupId>
127+
<artifactId>hamcrest</artifactId>
128+
<version>2.2</version>
112129
<scope>test</scope>
113130
</dependency>
114131
<dependency>

api/src/test/java/jakarta/mail/URLNameTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
import java.net.URL;
2020

21-
import org.junit.*;
22-
import static org.junit.Assert.assertEquals;
21+
import org.junit.jupiter.api.*;
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
2323

2424
/**
2525
* Test the URLName class.

api/src/test/java/jakarta/mail/internet/AppleFileNamesTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616

1717
package jakarta.mail.internet;
1818

19-
import org.junit.*;
20-
import static org.junit.Assert.assertEquals;
19+
import org.junit.jupiter.api.*;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
2121

2222
/**
2323
* Test that the "mail.mime.applefilenames" System property
2424
* causes the filename to be returned properly.
2525
*/
2626
public class AppleFileNamesTest {
2727

28-
@BeforeClass
28+
@BeforeAll
2929
public static void before() {
3030
System.out.println("AppleFileNames");
3131
System.setProperty("mail.mime.applefilenames", "true");
@@ -34,10 +34,10 @@ public static void before() {
3434
@Test
3535
public void testProp() throws Exception {
3636
ParameterList pl = new ParameterList("; filename=a b.txt");
37-
assertEquals(pl.get("filename"), "a b.txt");
37+
assertEquals("a b.txt", pl.get("filename"));
3838
}
3939

40-
@AfterClass
40+
@AfterAll
4141
public static void after() {
4242
// should be unnecessary
4343
System.clearProperty("mail.mime.applefilenames");

api/src/test/java/jakarta/mail/internet/ContentDispositionNoStrictTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616

1717
package jakarta.mail.internet;
1818

19-
import org.junit.*;
20-
import static org.junit.Assert.assertNull;
21-
import static org.junit.Assert.fail;
19+
import org.junit.jupiter.api.*;
20+
import static org.junit.jupiter.api.Assertions.assertNull;
21+
import static org.junit.jupiter.api.Assertions.fail;
2222

2323
/**
2424
* Test the property that contols ContentDisposition non-strict mode
2525
*/
2626
public class ContentDispositionNoStrictTest {
2727

28-
@BeforeClass
28+
@BeforeAll
2929
public static void before() {
3030
System.setProperty("mail.mime.contentdisposition.strict", "false");
3131
}
@@ -34,7 +34,7 @@ public static void before() {
3434
public void testDecode() throws Exception {
3535
try {
3636
ContentDisposition cd = new ContentDisposition("\"/non/standard/stuff/here.csv\"");
37-
assertNull("Content disposition must parse to null in non-strict mode", cd.getDisposition());
37+
assertNull(cd.getDisposition(), "Content disposition must parse to null in non-strict mode");
3838
} catch (ParseException px) {
3939
fail("Exception must not be thrown in non-strict mode");
4040
}
@@ -44,13 +44,13 @@ public void testDecode() throws Exception {
4444
public void testDecodeWithParams() throws Exception {
4545
try {
4646
ContentDisposition cd = new ContentDisposition(" ; size=12345");
47-
assertNull("Content disposition must parse to null in non-strict mode", cd.getDisposition());
47+
assertNull(cd.getDisposition(), "Content disposition must parse to null in non-strict mode");
4848
} catch (ParseException px) {
4949
fail("Exception must not be thrown in non-strict mode");
5050
}
5151
}
5252

53-
@AfterClass
53+
@AfterAll
5454
public static void after() {
5555
System.clearProperty("mail.mime.contentdisposition.strict");
5656
}

api/src/test/java/jakarta/mail/internet/ContentDispositionStrictTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@
1616

1717
package jakarta.mail.internet;
1818

19-
import org.junit.*;
20-
import static org.junit.Assert.assertNull;
21-
import static org.junit.Assert.fail;
19+
import org.junit.jupiter.api.*;
20+
import static org.junit.jupiter.api.Assertions.fail;
2221

2322
/**
2423
* Test the property that contols ContentDisposition non-strict mode
2524
*/
2625
public class ContentDispositionStrictTest {
2726

28-
@BeforeClass
27+
@BeforeAll
2928
public static void before() {
3029
System.setProperty("mail.mime.contentdisposition.strict", "true");
3130
}
@@ -40,7 +39,7 @@ public void testDecode() throws Exception {
4039
}
4140
}
4241

43-
@AfterClass
42+
@AfterAll
4443
public static void after() {
4544
System.clearProperty("mail.mime.contentdisposition.strict");
4645
}

api/src/test/java/jakarta/mail/internet/ContentTypeTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
package jakarta.mail.internet;
1818

19-
import org.junit.*;
20-
import static org.junit.Assert.assertTrue;
21-
import static org.junit.Assert.assertFalse;
19+
import org.junit.jupiter.api.*;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
21+
import static org.junit.jupiter.api.Assertions.assertFalse;
2222

2323
/**
2424
* Test the ContentType class.

api/src/test/java/jakarta/mail/internet/FoldTest.java

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,27 @@
1818

1919
import java.io.*;
2020
import java.util.*;
21-
import jakarta.mail.internet.MimeUtility;
21+
import java.util.stream.Stream;
2222

23-
import org.junit.Test;
24-
import org.junit.Assert;
25-
import org.junit.runner.RunWith;
26-
import org.junit.runners.Parameterized;
27-
import org.junit.runners.Parameterized.Parameters;
23+
import org.junit.jupiter.params.ParameterizedTest;
24+
import org.junit.jupiter.params.provider.Arguments;
25+
import org.junit.jupiter.params.provider.MethodSource;
26+
import org.junit.jupiter.api.Assertions;
2827

2928
/**
3029
* Test header folding.
3130
*
3231
* @author Bill Shannon
3332
*/
3433

35-
@RunWith(Parameterized.class)
3634
public class FoldTest {
37-
private String direction;
38-
private String orig;
39-
private String expect;
35+
private static List<Arguments> testData;
4036

41-
private static List<Object[]> testData;
42-
43-
public FoldTest(String direction, String orig, String expect) {
44-
this.direction = direction;
45-
this.orig = orig;
46-
this.expect = expect;
47-
}
48-
49-
@Parameters
50-
public static Collection<Object[]> data() throws IOException {
37+
public static Stream<Arguments> data() throws IOException {
5138
testData = new ArrayList<>();
5239
parse(new BufferedReader(new InputStreamReader(
5340
FoldTest.class.getResourceAsStream("folddata"))));
54-
return testData;
41+
return testData.stream();
5542
}
5643

5744
/**
@@ -69,13 +56,13 @@ private static void parse(BufferedReader in) throws IOException {
6956
continue;
7057
String orig = readString(in);
7158
if (line.equals("BOTH")) {
72-
testData.add(new Object[] { line, orig, null });
59+
testData.add(Arguments.of(line, orig, null));
7360
} else {
7461
String e = in.readLine();
7562
if (!e.equals("EXPECT"))
7663
throw new IOException("TEST DATA FORMAT ERROR");
7764
String expect = readString(in);
78-
testData.add(new Object[] { line, orig, expect });
65+
testData.add(Arguments.of(line, orig, expect));
7966
}
8067
}
8168
}
@@ -93,18 +80,19 @@ private static String readString(BufferedReader in) throws IOException {
9380
return sb.toString();
9481
}
9582

96-
@Test
97-
public void testFold() {
83+
@ParameterizedTest
84+
@MethodSource("data")
85+
public void testFold(String direction, String orig, String expect) {
9886
if (direction.equals("BOTH")) {
9987
String fs = MimeUtility.fold(0, orig);
10088
String us = MimeUtility.unfold(fs);
101-
Assert.assertEquals(orig, us);
89+
Assertions.assertEquals(orig, us);
10290
} else if (direction.equals("FOLD")) {
103-
Assert.assertEquals("Fold", expect, MimeUtility.fold(0, orig));
91+
Assertions.assertEquals(expect, MimeUtility.fold(0, orig), "Fold");
10492
} else if (direction.equals("UNFOLD")) {
105-
Assert.assertEquals("Unfold", expect, MimeUtility.unfold(orig));
93+
Assertions.assertEquals(expect, MimeUtility.unfold(orig), "Unfold");
10694
} else {
107-
Assert.fail("Unknown direction: " + direction);
95+
Assertions.fail("Unknown direction: " + direction);
10896
}
10997
}
11098
}

0 commit comments

Comments
 (0)