diff --git a/api/pom.xml b/api/pom.xml index 371ae689..91ae8a1a 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -77,11 +77,12 @@ false Low ${project.basedir}/../spotbugs-exclude.xml - + 4.7.3.4 ${project.version} + 5.10.1 @@ -97,9 +98,9 @@ 2.0.1 - junit - junit - 4.13.2 + org.junit.jupiter + junit-jupiter + ${junit.version} @@ -110,8 +111,14 @@ jakarta.activation-api - junit - junit + org.junit.jupiter + junit-jupiter + test + + + org.hamcrest + hamcrest + 2.2 test @@ -137,7 +144,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.0.0 + 3.2.3 org.apache.maven.plugins diff --git a/api/src/test/java/jakarta/mail/HeaderTest.java b/api/src/test/java/jakarta/mail/HeaderTest.java index aefb08ec..5b7ee87a 100644 --- a/api/src/test/java/jakarta/mail/HeaderTest.java +++ b/api/src/test/java/jakarta/mail/HeaderTest.java @@ -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 { diff --git a/api/src/test/java/jakarta/mail/URLNameTest.java b/api/src/test/java/jakarta/mail/URLNameTest.java index bde6214d..ed3a6b63 100644 --- a/api/src/test/java/jakarta/mail/URLNameTest.java +++ b/api/src/test/java/jakarta/mail/URLNameTest.java @@ -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. diff --git a/api/src/test/java/jakarta/mail/internet/AppleFileNamesTest.java b/api/src/test/java/jakarta/mail/internet/AppleFileNamesTest.java index 93e887cd..93dd3985 100644 --- a/api/src/test/java/jakarta/mail/internet/AppleFileNamesTest.java +++ b/api/src/test/java/jakarta/mail/internet/AppleFileNamesTest.java @@ -16,11 +16,11 @@ 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 @@ -28,7 +28,7 @@ */ public class AppleFileNamesTest { - @BeforeClass + @BeforeAll public static void before() { System.out.println("AppleFileNames"); System.setProperty("mail.mime.applefilenames", "true"); @@ -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"); diff --git a/api/src/test/java/jakarta/mail/internet/ContentDispositionNoStrictTest.java b/api/src/test/java/jakarta/mail/internet/ContentDispositionNoStrictTest.java index 8e63539a..192903d3 100644 --- a/api/src/test/java/jakarta/mail/internet/ContentDispositionNoStrictTest.java +++ b/api/src/test/java/jakarta/mail/internet/ContentDispositionNoStrictTest.java @@ -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"); } @@ -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"); } @@ -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"); } diff --git a/api/src/test/java/jakarta/mail/internet/ContentDispositionStrictTest.java b/api/src/test/java/jakarta/mail/internet/ContentDispositionStrictTest.java index 80f931d8..09354c0c 100644 --- a/api/src/test/java/jakarta/mail/internet/ContentDispositionStrictTest.java +++ b/api/src/test/java/jakarta/mail/internet/ContentDispositionStrictTest.java @@ -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"); } @@ -42,7 +42,7 @@ public void testDecode() throws Exception { } } - @AfterClass + @AfterAll public static void after() { System.clearProperty("mail.mime.contentdisposition.strict"); } diff --git a/api/src/test/java/jakarta/mail/internet/ContentTypeTest.java b/api/src/test/java/jakarta/mail/internet/ContentTypeTest.java index 463b14de..d287bf9b 100644 --- a/api/src/test/java/jakarta/mail/internet/ContentTypeTest.java +++ b/api/src/test/java/jakarta/mail/internet/ContentTypeTest.java @@ -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. diff --git a/api/src/test/java/jakarta/mail/internet/FoldTest.java b/api/src/test/java/jakarta/mail/internet/FoldTest.java index c42a8883..e847b330 100644 --- a/api/src/test/java/jakarta/mail/internet/FoldTest.java +++ b/api/src/test/java/jakarta/mail/internet/FoldTest.java @@ -16,18 +16,20 @@ 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. @@ -35,26 +37,15 @@ * @author Bill Shannon */ -@RunWith(Parameterized.class) public class FoldTest { - private String direction; - private String orig; - private String expect; - private static List testData; - - public FoldTest(String direction, String orig, String expect) { - this.direction = direction; - this.orig = orig; - this.expect = expect; - } + private static List testData; - @Parameters - public static Collection data() throws IOException { + public static Stream data() throws IOException { testData = new ArrayList<>(); parse(new BufferedReader(new InputStreamReader( FoldTest.class.getResourceAsStream("folddata")))); - return testData; + return testData.stream(); } /** @@ -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)); } } } @@ -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); } } } diff --git a/api/src/test/java/jakarta/mail/internet/HeaderTokenizerTest.java b/api/src/test/java/jakarta/mail/internet/HeaderTokenizerTest.java index 276e91e5..a14de548 100644 --- a/api/src/test/java/jakarta/mail/internet/HeaderTokenizerTest.java +++ b/api/src/test/java/jakarta/mail/internet/HeaderTokenizerTest.java @@ -16,20 +16,19 @@ 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.io.PrintStream; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Vector; +import java.util.stream.Stream; /** * Test MIME HeaderTokenizer. @@ -37,12 +36,7 @@ * @author Bill Shannon */ -@RunWith(Parameterized.class) public class HeaderTokenizerTest { - private String header; - private String value; - private String[] expect; - static boolean gen_test_input = false; // output good for input to -p static boolean parse_mail = false; // parse input in mail format static boolean return_comments = false; // return comments as tokens @@ -50,26 +44,20 @@ public class HeaderTokenizerTest { static int errors = 0; // number of errors detected static boolean junit; - static List testData; - - public HeaderTokenizerTest(String heder, String value, String[] expect) { - this.header = header; - this.value = value; - this.expect = expect; - } + static List testData; - @Parameters - public static Collection data() throws IOException { + public static Stream data() throws IOException { junit = true; testData = new ArrayList<>(); parse(new BufferedReader(new InputStreamReader( InternetAddressTest.class.getResourceAsStream("tokenlist")))); - return testData; + return testData.stream(); } - @Test - public void test() { - test(header, value, expect); + @ParameterizedTest + @MethodSource("data") + public void test(String header, String value, String[] expect) { + testInternal(header, value, expect); } public static void main(String[] argv) throws Exception { @@ -107,7 +95,7 @@ public static void main(String[] argv) throws Exception { sb.append(argv[i]); sb.append(" "); } - test("To", sb.toString(), null); + testInternal("To", sb.toString(), null); } else { // read from stdin BufferedReader in = @@ -118,7 +106,7 @@ public static void main(String[] argv) throws Exception { parse(in); else { while ((s = in.readLine()) != null) - test("To", s, null); + testInternal("To", s, null); } } System.exit(errors); @@ -169,12 +157,12 @@ public static void parse(BufferedReader in) throws IOException { i = header.indexOf(':'); try { if (junit) - testData.add(new Object[]{ + testData.add(Arguments.of( header.substring(0, i), header.substring(i + 2), - expect}); + expect)); else - test(header.substring(0, i), header.substring(i + 2), + testInternal(header.substring(0, i), header.substring(i + 2), expect); } catch (StringIndexOutOfBoundsException e) { // ignore @@ -197,7 +185,7 @@ public static void parse(BufferedReader in) throws IOException { /** * Test the header's value to see if we can tokenize it as expected. */ - public static void test(String header, String value, String[] expect) { + public static void testInternal(String header, String value, String expect[]) { PrintStream out = System.out; if (gen_test_input) out.println(header + ": " + value); @@ -217,8 +205,8 @@ else if (!junit) out.println("Expect: " + toklist.size()); else { if (junit) { - Assert.assertEquals("Number of tokens", - expect.length, toklist.size()); + Assertions.assertEquals(expect.length, toklist.size(), + "Number of tokens"); } else { out.println("Got " + toklist.size() + " tokens:"); if (expect != null && toklist.size() != expect.length) { @@ -234,15 +222,15 @@ else if (!junit) "\t" + tok.getValue()); else { if (!junit) - out.println("\t[" + (i + 1) + "] " + type(tok.getType()) + + out.println("\t[" + (i+1) + "] " + type(tok.getType()) + "\t" + tok.getValue()); if (expect != null && i < expect.length) { HeaderTokenizer.Token t = makeToken(expect[i]); if (junit) { - Assert.assertEquals("Token type", - t.getType(), tok.getType()); - Assert.assertEquals("Token value", - t.getValue(), tok.getValue()); + Assertions.assertEquals(t.getType(), tok.getType(), + "Token type"); + Assertions.assertEquals(t.getValue(), tok.getValue(), + "Token value"); } else { if (t.getType() != tok.getType() || !t.getValue().equals(tok.getValue())) { @@ -259,8 +247,8 @@ else if (!junit) out.println("Expect: Exception " + e); else { if (junit) { - Assert.assertTrue("Expected exception", - expect.length == 1 && expect[0].equals("Exception")); + Assertions.assertTrue(expect.length == 1 && expect[0].equals("Exception"), + "Expected exception"); } else { out.println("Got Exception: " + e); if (expect != null && diff --git a/api/src/test/java/jakarta/mail/internet/InternetAddressExtraTest.java b/api/src/test/java/jakarta/mail/internet/InternetAddressExtraTest.java index 7466607c..cb0c88a9 100644 --- a/api/src/test/java/jakarta/mail/internet/InternetAddressExtraTest.java +++ b/api/src/test/java/jakarta/mail/internet/InternetAddressExtraTest.java @@ -16,12 +16,12 @@ package jakarta.mail.internet; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; /** - * Test Internet address parsing that can't be tested using paramterized test. + * Test Internet address parsing that can't be tested using parameterized test. * * @author Bill Shannon */ diff --git a/api/src/test/java/jakarta/mail/internet/InternetAddressFoldTest.java b/api/src/test/java/jakarta/mail/internet/InternetAddressFoldTest.java index 9bf94a00..ea233364 100644 --- a/api/src/test/java/jakarta/mail/internet/InternetAddressFoldTest.java +++ b/api/src/test/java/jakarta/mail/internet/InternetAddressFoldTest.java @@ -16,18 +16,17 @@ 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; /** * Test InternetAddress folding. @@ -35,24 +34,14 @@ * @author Bill Shannon */ -@RunWith(Parameterized.class) public class InternetAddressFoldTest { - private InternetAddress[] orig; - private String expect; + private static List testData; - private static List testData; - - public InternetAddressFoldTest(InternetAddress[] orig, String expect) { - this.orig = orig; - this.expect = expect; - } - - @Parameters - public static Collection data() throws Exception { + public static Stream data() throws Exception { testData = new ArrayList<>(); parse(new BufferedReader(new InputStreamReader( InternetAddressFoldTest.class.getResourceAsStream("addrfolddata")))); - return testData; + return testData.stream(); } /** @@ -80,7 +69,7 @@ private static void parse(BufferedReader in) throws Exception { if (!e.equals("EXPECT")) throw new IOException("TEST DATA FORMAT ERROR, MISSING EXPECT"); String expect = readString(in); - testData.add(new Object[]{orig, expect}); + testData.add(Arguments.of(orig, expect)); } } @@ -97,8 +86,9 @@ private static String readString(BufferedReader in) throws IOException { return sb.toString(); } - @Test - public void testFold() { - Assert.assertEquals("Fold", expect, InternetAddress.toString(orig, 0)); + @ParameterizedTest + @MethodSource("data") + public void testFold(InternetAddress[] orig, String expect) { + Assertions.assertEquals(expect, InternetAddress.toString(orig, 0), "Fold"); } } diff --git a/api/src/test/java/jakarta/mail/internet/InternetAddressTest.java b/api/src/test/java/jakarta/mail/internet/InternetAddressTest.java index 069cd363..aafc60b0 100644 --- a/api/src/test/java/jakarta/mail/internet/InternetAddressTest.java +++ b/api/src/test/java/jakarta/mail/internet/InternetAddressTest.java @@ -16,19 +16,18 @@ 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.io.PrintStream; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; /** * Test Internet address parsing. @@ -36,14 +35,7 @@ * @author Bill Shannon */ -@RunWith(Parameterized.class) public class InternetAddressTest { - private String headerName; - private String headerValue; - private String[] expected; - private boolean doStrict; - private boolean doParseHeader; - static boolean strict = false; // enforce strict RFC822 syntax static boolean gen_test_input = false; // output good for input to -p static boolean parse_mail = false; // parse input in mail format @@ -52,24 +44,14 @@ public class InternetAddressTest { static int errors = 0; // number of errors detected static boolean junit; - static List testData; - - public InternetAddressTest(String headerName, String headerValue, - String[] expected, boolean doStrict, boolean doParseHeader) { - this.headerName = headerName; - this.headerValue = headerValue; - this.expected = expected; - this.doStrict = doStrict; - this.doParseHeader = doParseHeader; - } + static List testData; - @Parameters - public static Collection data() throws IOException { + public static Stream data() throws IOException { junit = true; testData = new ArrayList<>(); parse(new BufferedReader(new InputStreamReader( - InternetAddressTest.class.getResourceAsStream("addrlist")))); - return testData; + InternetAddressTest.class.getResourceAsStream("addrlist")))); + return testData.stream(); } public static void main(String[] argv) throws Exception { @@ -178,9 +160,9 @@ public static void parse(BufferedReader in) throws IOException { i = header.indexOf(':'); try { if (junit) - testData.add(new Object[]{ + testData.add(Arguments.of( header.substring(0, i), header.substring(i + 2), - expect, doStrict, doParseHeader}); + expect, doStrict, doParseHeader)); else test(header.substring(0, i), header.substring(i + 2), expect, doStrict, doParseHeader); @@ -234,8 +216,10 @@ private static String readLine(BufferedReader in) throws IOException { return sb.toString(); } - @Test - public void testAddress() { + @ParameterizedTest + @MethodSource("data") + public void testAddress(String headerName, String headerValue, + String[] expected, boolean doStrict, boolean doParseHeader) { test(headerName, headerValue, expected, doStrict, doParseHeader); } @@ -263,9 +247,8 @@ public static void test(String header, String value, String[] expect, if (expect != null && al.length != expect.length) { pr("Expected " + expect.length + " addresses"); if (junit) - Assert.assertEquals("For " + value + - " number of addresses", - al.length, expect.length); + Assertions.assertEquals(expect.length, al.length, + "For " + value + " number of addresses"); errors++; } } @@ -273,15 +256,14 @@ public static void test(String header, String value, String[] expect, if (gen_test_input) pr("\t" + al[i].getAddress()); // XXX - escape newlines else { - pr("\t[" + (i + 1) + "] " + al[i].getAddress() + + pr("\t[" + (i+1) + "] " + al[i].getAddress() + "\t\tPersonal: " + n(al[i].getPersonal())); if (expect != null && i < expect.length && !expect[i].equals(al[i].getAddress())) { pr("\tExpected:\t" + expect[i]); if (junit) - Assert.assertEquals("For " + value + - " address[" + i + "]", - expect[i], al[i].getAddress()); + Assertions.assertEquals(expect[i], al[i].getAddress(), + "For " + value + " address[" + i + "]"); errors++; } } @@ -313,9 +295,8 @@ public static void test(String header, String value, String[] expect, pr("Expected length " + al.length + ", got " + al2.length); if (junit) - Assert.assertEquals("For " + value + - " toString number of addresses", - al.length, al2.length); + Assertions.assertEquals(al.length, al2.length, + "For " + value + " toString number of addresses" ); errors++; } else { for (int i = 0; i < al.length; i++) { @@ -325,9 +306,8 @@ public static void test(String header, String value, String[] expect, al[i].getAddress() + ", got " + al2[i].getAddress()); if (junit) - Assert.assertEquals("For " + value + - " toString " + ta + " address[" + i + "]", - al[i].getAddress(), al2[i].getAddress()); + Assertions.assertEquals(al[i].getAddress(), al2[i].getAddress(), + "For " + value + " toString " + ta + " address[" + i + "]"); errors++; } String p1 = al[i].getPersonal(); @@ -337,9 +317,8 @@ public static void test(String header, String value, String[] expect, pr("Expected personal " + n(p1) + ", got " + n(p2)); if (junit) - Assert.assertEquals("For " + value + - " toString " + ta + " personal[" + i + "]", - p1, p2); + Assertions.assertEquals(p1, p2, + "For " + value + " toString " + ta + " personal[" + i + "]"); errors++; } } @@ -348,7 +327,7 @@ public static void test(String header, String value, String[] expect, pr("toString FAILED!!!"); pr("Got Exception: " + e2); if (junit) - Assert.fail("For " + value + + Assertions.fail("For " + value + " toString got Exception: " + e2); errors++; } @@ -363,7 +342,7 @@ public static void test(String header, String value, String[] expect, for (int i = 0; i < expect.length; i++) pr("\tExpected:\t" + expect[i]); if (junit) - Assert.fail("For " + value + " expected " + + Assertions.fail("For " + value + " expected " + expect.length + "addresses, got Exception: " + e); errors++; } diff --git a/api/src/test/java/jakarta/mail/internet/MailDateFormatTest.java b/api/src/test/java/jakarta/mail/internet/MailDateFormatTest.java index baaeb768..29642bd7 100644 --- a/api/src/test/java/jakarta/mail/internet/MailDateFormatTest.java +++ b/api/src/test/java/jakarta/mail/internet/MailDateFormatTest.java @@ -16,7 +16,7 @@ package jakarta.mail.internet; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.text.DateFormat; import java.text.DateFormatSymbols; @@ -32,11 +32,12 @@ import java.util.TimeZone; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Test MailDateFormat: formatting and parsing of dates as specified by @@ -241,7 +242,7 @@ public void mustFailOrSkipCfws() { Date date = getStrict().parse(input); assertThatDate(date, "Thu, 1 Jan 2015 00:00:00 +0000 (UTC)"); } catch (ParseException ignored) { - assertTrue("Not supporting CFWS is allowed", true); + assertTrue(true, "Not supporting CFWS is allowed"); } } @@ -383,48 +384,58 @@ public void strictMustRejectZoneOffsetMinutesGreaterThan60() { * Unsupported methods. When possible, the test also demonstrates * why invoking the method must be prohibited. */ - @Test(expected = UnsupportedOperationException.class) + @Test public void mustProhibitSetCalendar() { - getDefault().setCalendar(Calendar.getInstance()); + assertThrows(UnsupportedOperationException.class, + () -> getDefault().setCalendar(Calendar.getInstance())); } - @Test(expected = UnsupportedOperationException.class) + @Test public void mustProhibitSetNumberFormat() { - getDefault().setNumberFormat(NumberFormat.getInstance()); + assertThrows(UnsupportedOperationException.class, + () -> getDefault().setNumberFormat(NumberFormat.getInstance())); } - @Test(expected = UnsupportedOperationException.class) + @Test public void mustProhibitApplyLocalizedPattern() { - SimpleDateFormat fmt = getStrict(); - fmt.applyLocalizedPattern("yyyy"); - Date date = mustPass(fmt, "1 Jan 2015 00:00:00 +0000"); - assertThat(fmt.format(date), is("2015")); + assertThrows(UnsupportedOperationException.class, () -> { + SimpleDateFormat fmt = getStrict(); + fmt.applyLocalizedPattern("yyyy"); + Date date = mustPass(fmt, "1 Jan 2015 00:00:00 +0000"); + assertThat(fmt.format(date), is("2015")); + }); } - @Test(expected = UnsupportedOperationException.class) + @Test public void mustProhibitApplyPattern() { - SimpleDateFormat fmt = getStrict(); - fmt.applyPattern("yyyy"); - Date date = mustPass(fmt, "1 Jan 2015 00:00:00 +0000"); - assertThat(fmt.format(date), is("2015")); + assertThrows(UnsupportedOperationException.class, () -> { + SimpleDateFormat fmt = getStrict(); + fmt.applyPattern("yyyy"); + Date date = mustPass(fmt, "1 Jan 2015 00:00:00 +0000"); + assertThat(fmt.format(date), is("2015")); + }); } - @Test(expected = UnsupportedOperationException.class) + @Test public void mustProhibitGet2DigitYearStart() { - getDefault().get2DigitYearStart(); + assertThrows(UnsupportedOperationException.class, + () -> getDefault().get2DigitYearStart()); } - @Test(expected = UnsupportedOperationException.class) + @Test public void mustProhibitSet2DigitYearStart() { - getDefault().set2DigitYearStart(new Date()); + assertThrows(UnsupportedOperationException.class, + () -> getDefault().set2DigitYearStart(new Date())); } - @Test(expected = UnsupportedOperationException.class) + @Test public void mustProhibitSetDateFormatSymbols() { - SimpleDateFormat fmt = getStrict(); - fmt.setDateFormatSymbols(new DateFormatSymbols(Locale.FRENCH)); - Date date = mustPass(fmt, "1 Jan 2015 00:00:00 +0000"); - assertThatDate(date, "jeu., 1 janv. 2015 00:00:00 +0000 (UTC)"); + assertThrows(UnsupportedOperationException.class, () -> { + SimpleDateFormat fmt = getStrict(); + fmt.setDateFormatSymbols(new DateFormatSymbols(Locale.FRENCH)); + Date date = mustPass(fmt, "1 Jan 2015 00:00:00 +0000"); + assertThatDate(date, "jeu., 1 janv. 2015 00:00:00 +0000 (UTC)"); + }); } /* diff --git a/api/src/test/java/jakarta/mail/internet/NewsAddressTest.java b/api/src/test/java/jakarta/mail/internet/NewsAddressTest.java index 7732d565..803537e7 100644 --- a/api/src/test/java/jakarta/mail/internet/NewsAddressTest.java +++ b/api/src/test/java/jakarta/mail/internet/NewsAddressTest.java @@ -16,9 +16,9 @@ package jakarta.mail.internet; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Test the NewsAddress class. diff --git a/api/src/test/java/jakarta/mail/internet/NonAsciiFileNamesTest.java b/api/src/test/java/jakarta/mail/internet/NonAsciiFileNamesTest.java index d84517b2..8937b00d 100644 --- a/api/src/test/java/jakarta/mail/internet/NonAsciiFileNamesTest.java +++ b/api/src/test/java/jakarta/mail/internet/NonAsciiFileNamesTest.java @@ -16,11 +16,11 @@ 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.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test that non-ASCII file names are encoded by default. @@ -29,7 +29,7 @@ public class NonAsciiFileNamesTest { private static String charset; - @BeforeClass + @BeforeAll public static void before() { System.out.println("NonAsciiFileNames"); charset = System.getProperty("mail.mime.charset"); @@ -47,9 +47,9 @@ public void testNonAsciiFileName() throws Exception { MimeBodyPart.updateHeaders(mbp); String s = mbp.getHeader("Content-Disposition", null); - assertTrue("Content-Disposition filename", s.indexOf("filename*") >= 0); + assertTrue(s.indexOf("filename*") >= 0, "Content-Disposition filename"); s = mbp.getHeader("Content-Type", null); - assertTrue("Content-Type name", s.indexOf("name*") >= 0); + assertTrue(s.indexOf("name*") >= 0, "Content-Type name"); } /** @@ -65,12 +65,12 @@ public void testNonAsciiFileNameWithContentType() throws Exception { MimeBodyPart.updateHeaders(mbp); String s = mbp.getHeader("Content-Disposition", null); - assertTrue("Content-Disposition filename", s.indexOf("filename*") >= 0); + assertTrue(s.indexOf("filename*") >= 0, "Content-Disposition filename"); s = mbp.getHeader("Content-Type", null); - assertTrue("Content-Type name", s.indexOf("name*") >= 0); + assertTrue(s.indexOf("name*") >= 0, "Content-Type name"); } - @AfterClass + @AfterAll public static void after() { if (charset == null) System.clearProperty("mail.mime.charset"); diff --git a/api/src/test/java/jakarta/mail/internet/ParameterListTest.java b/api/src/test/java/jakarta/mail/internet/ParameterListTest.java index 9f7ad0d2..2e1c2803 100644 --- a/api/src/test/java/jakarta/mail/internet/ParameterListTest.java +++ b/api/src/test/java/jakarta/mail/internet/ParameterListTest.java @@ -16,18 +16,18 @@ package jakarta.mail.internet; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * XXX - add more tests */ public class ParameterListTest { - @BeforeClass + @BeforeAll public static void before() { System.out.println("ParameterListTests"); System.clearProperty("mail.mime.windowsfilenames"); @@ -41,7 +41,7 @@ public static void before() { public void testBackslash() throws Exception { System.clearProperty("mail.mime.windowsfilenames"); ParameterList pl = new ParameterList("; filename=\"\\a\\b\\c.txt\""); - assertEquals(pl.get("filename"), "abc.txt"); + assertEquals("abc.txt", pl.get("filename")); } /** diff --git a/api/src/test/java/jakarta/mail/internet/WindowsFileNamesTest.java b/api/src/test/java/jakarta/mail/internet/WindowsFileNamesTest.java index 7f900d7f..fcd1b495 100644 --- a/api/src/test/java/jakarta/mail/internet/WindowsFileNamesTest.java +++ b/api/src/test/java/jakarta/mail/internet/WindowsFileNamesTest.java @@ -16,11 +16,11 @@ 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.windowsfilenames" System property @@ -28,7 +28,7 @@ */ public class WindowsFileNamesTest { - @BeforeClass + @BeforeAll public static void before() { System.out.println("WindowsFileNames"); System.setProperty("mail.mime.windowsfilenames", "true"); @@ -37,10 +37,10 @@ public static void before() { @Test public void testProp() throws Exception { ParameterList pl = new ParameterList("; filename=\"\\a\\b\\c.txt\""); - assertEquals(pl.get("filename"), "\\a\\b\\c.txt"); + assertEquals("\\a\\b\\c.txt", pl.get("filename")); } - @AfterClass + @AfterAll public static void after() { // should be unnecessary System.clearProperty("mail.mime.windowsfilenames"); diff --git a/api/src/test/java/jakarta/mail/search/SearchTermSerializationTest.java b/api/src/test/java/jakarta/mail/search/SearchTermSerializationTest.java index c584cb68..1a8c02a4 100644 --- a/api/src/test/java/jakarta/mail/search/SearchTermSerializationTest.java +++ b/api/src/test/java/jakarta/mail/search/SearchTermSerializationTest.java @@ -20,7 +20,7 @@ import jakarta.mail.Message; import jakarta.mail.internet.MimeMessage; import jakarta.mail.internet.NewsAddress; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -29,7 +29,7 @@ import java.io.ObjectOutputStream; import java.util.Date; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * SearchTerm serialization test. diff --git a/api/src/test/java/jakarta/mail/util/FactoryFinderTest.java b/api/src/test/java/jakarta/mail/util/FactoryFinderTest.java index 6a3ec317..2b6d0279 100644 --- a/api/src/test/java/jakarta/mail/util/FactoryFinderTest.java +++ b/api/src/test/java/jakarta/mail/util/FactoryFinderTest.java @@ -16,11 +16,11 @@ package jakarta.mail.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; public class FactoryFinderTest { diff --git a/api/src/test/java/jakarta/mail/util/SharedFileInputStreamTest.java b/api/src/test/java/jakarta/mail/util/SharedFileInputStreamTest.java index a1f707bb..6bd044ae 100644 --- a/api/src/test/java/jakarta/mail/util/SharedFileInputStreamTest.java +++ b/api/src/test/java/jakarta/mail/util/SharedFileInputStreamTest.java @@ -16,13 +16,13 @@ package jakarta.mail.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; import java.io.InputStream; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; /** * Please note: diff --git a/api/src/test/java/module-info.java b/api/src/test/java/module-info.java index e3ca4441..56841863 100644 --- a/api/src/test/java/module-info.java +++ b/api/src/test/java/module-info.java @@ -18,7 +18,9 @@ requires java.logging; requires transitive jakarta.activation; - requires junit; + requires transitive org.junit.jupiter.api; + requires transitive org.junit.jupiter.params; + requires org.hamcrest; exports jakarta.mail; exports jakarta.mail.event;