diff --git a/api/pom.xml b/api/pom.xml index ccbfb3ff..a54a37e7 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -77,8 +77,9 @@ false Low ${project.basedir}/../spotbugs-exclude.xml - + 4.4.2.2 + 5.9.0 @@ -94,9 +95,14 @@ 1.0.0-M2 - junit - junit - 4.13.2 + org.junit.jupiter + junit-jupiter-api + ${junit.version} + + + org.junit.jupiter + junit-jupiter-params + ${junit.version} @@ -107,8 +113,19 @@ jakarta.activation-api - junit - junit + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.hamcrest + hamcrest + 2.2 test diff --git a/api/src/test/java/jakarta/mail/URLNameTest.java b/api/src/test/java/jakarta/mail/URLNameTest.java index 65f1c4c6..1da8e325 100644 --- a/api/src/test/java/jakarta/mail/URLNameTest.java +++ b/api/src/test/java/jakarta/mail/URLNameTest.java @@ -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. diff --git a/api/src/test/java/jakarta/mail/internet/AppleFileNamesTest.java b/api/src/test/java/jakarta/mail/internet/AppleFileNamesTest.java index 32dfdfc7..203efb29 100644 --- a/api/src/test/java/jakarta/mail/internet/AppleFileNamesTest.java +++ b/api/src/test/java/jakarta/mail/internet/AppleFileNamesTest.java @@ -16,8 +16,8 @@ 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 @@ -25,7 +25,7 @@ */ public class AppleFileNamesTest { - @BeforeClass + @BeforeAll public static void before() { System.out.println("AppleFileNames"); System.setProperty("mail.mime.applefilenames", "true"); @@ -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"); diff --git a/api/src/test/java/jakarta/mail/internet/ContentDispositionNoStrictTest.java b/api/src/test/java/jakarta/mail/internet/ContentDispositionNoStrictTest.java index 72f5f75b..243473c5 100644 --- a/api/src/test/java/jakarta/mail/internet/ContentDispositionNoStrictTest.java +++ b/api/src/test/java/jakarta/mail/internet/ContentDispositionNoStrictTest.java @@ -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"); } @@ -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"); } @@ -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"); } diff --git a/api/src/test/java/jakarta/mail/internet/ContentDispositionStrictTest.java b/api/src/test/java/jakarta/mail/internet/ContentDispositionStrictTest.java index a80ef848..65f97fe8 100644 --- a/api/src/test/java/jakarta/mail/internet/ContentDispositionStrictTest.java +++ b/api/src/test/java/jakarta/mail/internet/ContentDispositionStrictTest.java @@ -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"); } @@ -40,7 +39,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 c51ee82d..5fa77e09 100644 --- a/api/src/test/java/jakarta/mail/internet/ContentTypeTest.java +++ b/api/src/test/java/jakarta/mail/internet/ContentTypeTest.java @@ -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. diff --git a/api/src/test/java/jakarta/mail/internet/FoldTest.java b/api/src/test/java/jakarta/mail/internet/FoldTest.java index 21601449..4bd7b013 100644 --- a/api/src/test/java/jakarta/mail/internet/FoldTest.java +++ b/api/src/test/java/jakarta/mail/internet/FoldTest.java @@ -18,13 +18,12 @@ 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. @@ -32,26 +31,14 @@ * @author Bill Shannon */ -@RunWith(Parameterized.class) public class FoldTest { - private String direction; - private String orig; - private String expect; + private static List testData; - private static List testData; - - public FoldTest(String direction, String orig, String expect) { - this.direction = direction; - this.orig = orig; - this.expect = expect; - } - - @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(); } /** @@ -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)); } } } @@ -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); } } } diff --git a/api/src/test/java/jakarta/mail/internet/HeaderTokenizerTest.java b/api/src/test/java/jakarta/mail/internet/HeaderTokenizerTest.java index 51199387..cfc83800 100644 --- a/api/src/test/java/jakarta/mail/internet/HeaderTokenizerTest.java +++ b/api/src/test/java/jakarta/mail/internet/HeaderTokenizerTest.java @@ -18,15 +18,12 @@ import java.io.*; import java.util.*; -import jakarta.mail.*; -import jakarta.mail.internet.HeaderTokenizer; -import jakarta.mail.internet.ParseException; +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.api.Assertions; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** * Test MIME HeaderTokenizer. @@ -34,12 +31,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 @@ -47,26 +39,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 { @@ -104,7 +90,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 = @@ -115,7 +101,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); @@ -166,12 +152,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 @@ -194,7 +180,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); @@ -214,8 +200,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) { @@ -236,10 +222,10 @@ else if (!junit) 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())) { @@ -256,8 +242,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 c93b3000..7841922b 100644 --- a/api/src/test/java/jakarta/mail/internet/InternetAddressExtraTest.java +++ b/api/src/test/java/jakarta/mail/internet/InternetAddressExtraTest.java @@ -19,9 +19,9 @@ import jakarta.mail.internet.InternetAddress; import jakarta.mail.internet.AddressException; -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. diff --git a/api/src/test/java/jakarta/mail/internet/InternetAddressFoldTest.java b/api/src/test/java/jakarta/mail/internet/InternetAddressFoldTest.java index 32abf477..bc74f440 100644 --- a/api/src/test/java/jakarta/mail/internet/InternetAddressFoldTest.java +++ b/api/src/test/java/jakarta/mail/internet/InternetAddressFoldTest.java @@ -18,13 +18,12 @@ import java.io.*; import java.util.*; -import jakarta.mail.internet.InternetAddress; +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 InternetAddress folding. @@ -32,24 +31,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(); } /** @@ -77,7 +66,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)); } } @@ -94,8 +83,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 00de92d2..5a30a30a 100644 --- a/api/src/test/java/jakarta/mail/internet/InternetAddressTest.java +++ b/api/src/test/java/jakarta/mail/internet/InternetAddressTest.java @@ -18,15 +18,12 @@ import java.io.*; import java.util.*; -import jakarta.mail.*; -import jakarta.mail.internet.InternetAddress; -import jakarta.mail.internet.AddressException; +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 Internet address parsing. @@ -34,14 +31,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 @@ -50,24 +40,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; + return testData.stream(); } public static void main(String argv[]) throws Exception { @@ -176,9 +156,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); @@ -232,8 +212,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); } @@ -261,9 +243,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++; } } @@ -277,9 +258,8 @@ public static void test(String header, String value, String expect[], !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++; } } @@ -311,9 +291,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++) { @@ -323,9 +302,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(); @@ -335,9 +313,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++; } } @@ -346,7 +323,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++; } @@ -361,7 +338,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 7feb8c21..b8712435 100644 --- a/api/src/test/java/jakarta/mail/internet/MailDateFormatTest.java +++ b/api/src/test/java/jakarta/mail/internet/MailDateFormatTest.java @@ -32,12 +32,13 @@ import java.util.Locale; 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 org.junit.Test; +import static org.hamcrest.MatcherAssert.assertThat; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +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 @@ -242,7 +243,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"); } } @@ -384,48 +385,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 b32df334..80ff66cb 100644 --- a/api/src/test/java/jakarta/mail/internet/NewsAddressTest.java +++ b/api/src/test/java/jakarta/mail/internet/NewsAddressTest.java @@ -16,8 +16,8 @@ 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 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 1a74f9fb..78658f13 100644 --- a/api/src/test/java/jakarta/mail/internet/NonAsciiFileNamesTest.java +++ b/api/src/test/java/jakarta/mail/internet/NonAsciiFileNamesTest.java @@ -16,9 +16,8 @@ package jakarta.mail.internet; -import org.junit.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import org.junit.jupiter.api.*; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test that non-ASCII file names are encoded by default. @@ -27,7 +26,7 @@ public class NonAsciiFileNamesTest { private static String charset; - @BeforeClass + @BeforeAll public static void before() { System.out.println("NonAsciiFileNames"); charset = System.getProperty("mail.mime.charset"); @@ -45,9 +44,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"); } /** @@ -63,12 +62,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 611309f6..e52dd1a9 100644 --- a/api/src/test/java/jakarta/mail/internet/ParameterListTest.java +++ b/api/src/test/java/jakarta/mail/internet/ParameterListTest.java @@ -16,16 +16,16 @@ package jakarta.mail.internet; -import org.junit.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import org.junit.jupiter.api.*; +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"); @@ -39,7 +39,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 72539af4..0d08f04a 100644 --- a/api/src/test/java/jakarta/mail/internet/WindowsFileNamesTest.java +++ b/api/src/test/java/jakarta/mail/internet/WindowsFileNamesTest.java @@ -16,8 +16,8 @@ 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.windowsfilenames" System property @@ -25,7 +25,7 @@ */ public class WindowsFileNamesTest { - @BeforeClass + @BeforeAll public static void before() { System.out.println("WindowsFileNames"); System.setProperty("mail.mime.windowsfilenames", "true"); @@ -34,10 +34,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 29e1bd09..e7e6ac67 100644 --- a/api/src/test/java/jakarta/mail/search/SearchTermSerializationTest.java +++ b/api/src/test/java/jakarta/mail/search/SearchTermSerializationTest.java @@ -20,11 +20,10 @@ import java.util.Date; import jakarta.mail.*; -import jakarta.mail.search.*; import jakarta.mail.internet.*; -import org.junit.Test; -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.Test; +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 a23fae04..ae93a2b3 100644 --- a/api/src/test/java/jakarta/mail/util/FactoryFinderTest.java +++ b/api/src/test/java/jakarta/mail/util/FactoryFinderTest.java @@ -16,13 +16,13 @@ package jakarta.mail.util; -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; import java.util.ServiceConfigurationError; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class FactoryFinderTest { 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;