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 Jan 8, 2024
1 parent dbb0aa1 commit efb6320
Show file tree
Hide file tree
Showing 21 changed files with 214 additions and 245 deletions.
21 changes: 14 additions & 7 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@
<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.7.3.4</spotbugs.version>

<!-- version identifier in jakarta.mail.Version -->
<mail.version>${project.version}</mail.version>
<junit.version>5.10.1</junit.version>
</properties>

<dependencyManagement>
Expand All @@ -97,9 +98,9 @@
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand All @@ -110,8 +111,14 @@
<artifactId>jakarta.activation-api</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -137,7 +144,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
<version>3.2.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
6 changes: 3 additions & 3 deletions api/src/test/java/jakarta/mail/HeaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

package jakarta.mail;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.Date;

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

public class HeaderTest {

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 @@ -16,11 +16,11 @@

package jakarta.mail;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.net.URL;

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

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

package jakarta.mail.internet;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
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 @@ -37,10 +37,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,19 +16,19 @@

package jakarta.mail.internet;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
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
* Test the property that controls ContentDisposition non-strict mode
*/
public class ContentDispositionNoStrictTest {

@BeforeClass
@BeforeAll
public static void before() {
System.setProperty("mail.mime.contentdisposition.strict", "false");
}
Expand All @@ -37,7 +37,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 @@ -47,13 +47,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,18 +16,18 @@

package jakarta.mail.internet;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

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

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

@BeforeClass
@BeforeAll
public static void before() {
System.setProperty("mail.mime.contentdisposition.strict", "true");
}
Expand All @@ -42,7 +42,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,10 +16,10 @@

package jakarta.mail.internet;

import org.junit.Test;
import org.junit.jupiter.api.Test;

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

/**
* Test the ContentType class.
Expand Down
48 changes: 20 additions & 28 deletions api/src/test/java/jakarta/mail/internet/FoldTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,36 @@

package jakarta.mail.internet;

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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;


import static org.junit.jupiter.params.provider.Arguments.arguments;

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

@RunWith(Parameterized.class)
public class FoldTest {
private String direction;
private String orig;
private String expect;

private static List<Object[]> testData;

public FoldTest(String direction, String orig, String expect) {
this.direction = direction;
this.orig = orig;
this.expect = expect;
}
private static List<Arguments> testData;

@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 @@ -72,13 +63,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(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(line, orig, expect));
}
}
}
Expand All @@ -96,18 +87,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 efb6320

Please sign in to comment.