Skip to content

Commit

Permalink
JUnit bump 4 -> 5
Browse files Browse the repository at this point in the history
  • Loading branch information
bvfalcon committed Aug 8, 2022
1 parent fedabff commit b15791b
Show file tree
Hide file tree
Showing 19 changed files with 198 additions and 230 deletions.
29 changes: 23 additions & 6 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@
<spotbugs.skip>false</spotbugs.skip>
<spotbugs.threshold>Low</spotbugs.threshold>
<spotbugs.exclude>${project.basedir}/../spotbugs-exclude.xml</spotbugs.exclude>
<!--Maven plugins version-->
<!--Maven dependencies and plugins version-->
<spotbugs.version>4.4.2.2</spotbugs.version>
<junit.version>5.9.0</junit.version>
</properties>

<dependencyManagement>
Expand All @@ -94,9 +95,14 @@
<version>1.0.0-M2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand All @@ -107,8 +113,19 @@
<artifactId>jakarta.activation-api</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions api/src/test/java/jakarta/mail/URLNameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import java.net.URL;

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

/**
* Test the URLName class.
Expand Down
10 changes: 5 additions & 5 deletions api/src/test/java/jakarta/mail/internet/AppleFileNamesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@

package jakarta.mail.internet;

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

/**
* Test that the "mail.mime.applefilenames" System property
* causes the filename to be returned properly.
*/
public class AppleFileNamesTest {

@BeforeClass
@BeforeAll
public static void before() {
System.out.println("AppleFileNames");
System.setProperty("mail.mime.applefilenames", "true");
Expand All @@ -34,10 +34,10 @@ public static void before() {
@Test
public void testProp() throws Exception {
ParameterList pl = new ParameterList("; filename=a b.txt");
assertEquals(pl.get("filename"), "a b.txt");
assertEquals("a b.txt", pl.get("filename"));
}

@AfterClass
@AfterAll
public static void after() {
// should be unnecessary
System.clearProperty("mail.mime.applefilenames");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@

package jakarta.mail.internet;

import org.junit.*;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.fail;

/**
* Test the property that contols ContentDisposition non-strict mode
*/
public class ContentDispositionNoStrictTest {

@BeforeClass
@BeforeAll
public static void before() {
System.setProperty("mail.mime.contentdisposition.strict", "false");
}
Expand All @@ -34,7 +34,7 @@ public static void before() {
public void testDecode() throws Exception {
try {
ContentDisposition cd = new ContentDisposition("\"/non/standard/stuff/here.csv\"");
assertNull("Content disposition must parse to null in non-strict mode", cd.getDisposition());
assertNull(cd.getDisposition(), "Content disposition must parse to null in non-strict mode");
} catch (ParseException px) {
fail("Exception must not be thrown in non-strict mode");
}
Expand All @@ -44,13 +44,13 @@ public void testDecode() throws Exception {
public void testDecodeWithParams() throws Exception {
try {
ContentDisposition cd = new ContentDisposition(" ; size=12345");
assertNull("Content disposition must parse to null in non-strict mode", cd.getDisposition());
assertNull(cd.getDisposition(), "Content disposition must parse to null in non-strict mode");
} catch (ParseException px) {
fail("Exception must not be thrown in non-strict mode");
}
}

@AfterClass
@AfterAll
public static void after() {
System.clearProperty("mail.mime.contentdisposition.strict");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@

package jakarta.mail.internet;

import org.junit.*;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.fail;

/**
* Test the property that contols ContentDisposition non-strict mode
*/
public class ContentDispositionStrictTest {

@BeforeClass
@BeforeAll
public static void before() {
System.setProperty("mail.mime.contentdisposition.strict", "true");
}
Expand All @@ -40,7 +39,7 @@ public void testDecode() throws Exception {
}
}

@AfterClass
@AfterAll
public static void after() {
System.clearProperty("mail.mime.contentdisposition.strict");
}
Expand Down
6 changes: 3 additions & 3 deletions api/src/test/java/jakarta/mail/internet/ContentTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package jakarta.mail.internet;

import org.junit.*;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;

/**
* Test the ContentType class.
Expand Down
46 changes: 17 additions & 29 deletions api/src/test/java/jakarta/mail/internet/FoldTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,27 @@

import java.io.*;
import java.util.*;
import jakarta.mail.internet.MimeUtility;
import java.util.stream.Stream;

import org.junit.Test;
import org.junit.Assert;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.api.Assertions;

/**
* Test header folding.
*
* @author Bill Shannon
*/

@RunWith(Parameterized.class)
public class FoldTest {
private String direction;
private String orig;
private String expect;
private static List<Arguments> testData;

private static List<Object[]> testData;

public FoldTest(String direction, String orig, String expect) {
this.direction = direction;
this.orig = orig;
this.expect = expect;
}

@Parameters
public static Collection<Object[]> data() throws IOException {
public static Stream<Arguments> data() throws IOException {
testData = new ArrayList<>();
parse(new BufferedReader(new InputStreamReader(
FoldTest.class.getResourceAsStream("folddata"))));
return testData;
return testData.stream();
}

/**
Expand All @@ -69,13 +56,13 @@ private static void parse(BufferedReader in) throws IOException {
continue;
String orig = readString(in);
if (line.equals("BOTH")) {
testData.add(new Object[] { line, orig, null });
testData.add(Arguments.of(line, orig, null));
} else {
String e = in.readLine();
if (!e.equals("EXPECT"))
throw new IOException("TEST DATA FORMAT ERROR");
String expect = readString(in);
testData.add(new Object[] { line, orig, expect });
testData.add(Arguments.of(line, orig, expect));
}
}
}
Expand All @@ -93,18 +80,19 @@ private static String readString(BufferedReader in) throws IOException {
return sb.toString();
}

@Test
public void testFold() {
@ParameterizedTest
@MethodSource("data")
public void testFold(String direction, String orig, String expect) {
if (direction.equals("BOTH")) {
String fs = MimeUtility.fold(0, orig);
String us = MimeUtility.unfold(fs);
Assert.assertEquals(orig, us);
Assertions.assertEquals(orig, us);
} else if (direction.equals("FOLD")) {
Assert.assertEquals("Fold", expect, MimeUtility.fold(0, orig));
Assertions.assertEquals(expect, MimeUtility.fold(0, orig), "Fold");
} else if (direction.equals("UNFOLD")) {
Assert.assertEquals("Unfold", expect, MimeUtility.unfold(orig));
Assertions.assertEquals(expect, MimeUtility.unfold(orig), "Unfold");
} else {
Assert.fail("Unknown direction: " + direction);
Assertions.fail("Unknown direction: " + direction);
}
}
}
Loading

0 comments on commit b15791b

Please sign in to comment.