From fbe8d06332997e9ae1c85f638f18aad28d674c34 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 23 Mar 2020 13:13:57 +0000 Subject: [PATCH] Upgrade JUnit 4.13 to 5.6.1 (#86) * Upgrade JUnit 4.13 to 5.6.1 * Test build with JDK 13 * Revert "Test build with JDK 13" This reverts commit a5f0acfb91d17373fca943f19ecf4b32ab8ca02a. --- pom.xml | 16 ++++-- .../wiser/assertions/AbstractWiserTest.java | 8 +-- .../kemitix/wiser/assertions/Issue1Test.java | 2 +- .../kemitix/wiser/assertions/Issue6Test.java | 3 +- .../wiser/assertions/WiserAssertionsTest.java | 50 +++++++++++++------ 5 files changed, 54 insertions(+), 25 deletions(-) diff --git a/pom.xml b/pom.xml index 5232e37..ac5e85a 100644 --- a/pom.xml +++ b/pom.xml @@ -34,6 +34,9 @@ + 1.8 + ${java.version} + ${java.version} 2.16 2.1.2 0.9.0 @@ -42,7 +45,7 @@ 1.4.7 3.1.7 - 4.13 + 5.6.1 3.3.3 3.1.1 5.2.4.RELEASE @@ -52,6 +55,7 @@ 1 2.1.0 4.0.1 + 3.15.0 @@ -71,8 +75,8 @@ ${subethasmtp.version} - junit - junit + org.junit.jupiter + junit-jupiter ${junit.version} test @@ -82,6 +86,12 @@ ${mockito-core.version} test + + org.assertj + assertj-core + ${assertj.version} + test + org.codemonkey.simplejavamail simple-java-mail diff --git a/src/test/java/net/kemitix/wiser/assertions/AbstractWiserTest.java b/src/test/java/net/kemitix/wiser/assertions/AbstractWiserTest.java index 2eb8437..8f385b1 100644 --- a/src/test/java/net/kemitix/wiser/assertions/AbstractWiserTest.java +++ b/src/test/java/net/kemitix/wiser/assertions/AbstractWiserTest.java @@ -1,7 +1,7 @@ package net.kemitix.wiser.assertions; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.subethamail.wiser.Wiser; import java.io.IOException; @@ -17,7 +17,7 @@ abstract class AbstractWiserTest { private Wiser wiser; - @Before + @BeforeEach public void setUp() throws IOException { port = findFreePort(); wiser = new Wiser(port); @@ -31,7 +31,7 @@ abstract class AbstractWiserTest { } } - @After + @AfterEach public void tearDown() { wiser.stop(); } diff --git a/src/test/java/net/kemitix/wiser/assertions/Issue1Test.java b/src/test/java/net/kemitix/wiser/assertions/Issue1Test.java index d8d1fe7..46d6d31 100644 --- a/src/test/java/net/kemitix/wiser/assertions/Issue1Test.java +++ b/src/test/java/net/kemitix/wiser/assertions/Issue1Test.java @@ -2,7 +2,7 @@ package net.kemitix.wiser.assertions; import org.codemonkey.simplejavamail.Mailer; import org.codemonkey.simplejavamail.email.Email; -import org.junit.Test; +import org.junit.jupiter.api.Test; import javax.mail.Message; diff --git a/src/test/java/net/kemitix/wiser/assertions/Issue6Test.java b/src/test/java/net/kemitix/wiser/assertions/Issue6Test.java index 2ec4535..1753142 100644 --- a/src/test/java/net/kemitix/wiser/assertions/Issue6Test.java +++ b/src/test/java/net/kemitix/wiser/assertions/Issue6Test.java @@ -1,7 +1,6 @@ package net.kemitix.wiser.assertions; -import org.junit.Test; - +import org.junit.jupiter.api.Test; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSenderImpl; diff --git a/src/test/java/net/kemitix/wiser/assertions/WiserAssertionsTest.java b/src/test/java/net/kemitix/wiser/assertions/WiserAssertionsTest.java index 9eb2645..0b6f039 100644 --- a/src/test/java/net/kemitix/wiser/assertions/WiserAssertionsTest.java +++ b/src/test/java/net/kemitix/wiser/assertions/WiserAssertionsTest.java @@ -1,9 +1,10 @@ package net.kemitix.wiser.assertions; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.subethamail.wiser.Wiser; -import static org.junit.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import java.io.IOException; import java.util.logging.Level; @@ -75,14 +76,17 @@ public class WiserAssertionsTest extends AbstractWiserTest { * Test {@link WiserAssertions#withContent(java.lang.String)} where the * content of the email does not match. */ - @Test(expected = AssertionError.class) + @Test public void testContentNotMatches() { //given final String body = "message body"; //when sendMimeMultipartMessage("from", "to", "subject", body); //then - assertReceivedMessage().withContent("Other body"); + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> + assertReceivedMessage() + .withContent("Other body")); } /** @@ -103,14 +107,17 @@ public class WiserAssertionsTest extends AbstractWiserTest { * Test {@link WiserAssertions#withContentContains(String)} where the * content of the email does not match. */ - @Test(expected = AssertionError.class) + @Test public void testContentContainsNotMatches() { //given final String body = "message body"; //when sendMimeMultipartMessage("from", "to", "subject", body); //then - assertReceivedMessage().withContentContains("agebo"); + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> + assertReceivedMessage() + .withContentContains("agebo")); } /** @@ -133,14 +140,17 @@ public class WiserAssertionsTest extends AbstractWiserTest { * Test {@link WiserAssertions#from(java.lang.String)} can detect when mail * is not sent from a user. */ - @Test(expected = AssertionError.class) + @Test public void testFromNotMatches() { //given final String from = "bob@a.com"; //when sendMimeMultipartMessage(from, "to", "subject", "body"); //then - assertReceivedMessage().from("lisa@c.com"); + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> + assertReceivedMessage() + .from("lisa@c.com")); } /** @@ -149,7 +159,8 @@ public class WiserAssertionsTest extends AbstractWiserTest { */ @Test public void testInstantiate() { - assertNotNull(assertReceivedMessage()); + assertThat(assertReceivedMessage()) + .isNotNull(); } /** @@ -171,14 +182,17 @@ public class WiserAssertionsTest extends AbstractWiserTest { * Test {@link WiserAssertions#withSubjectContains(java.lang.String)} where * the subject does not contain the expected fragment. */ - @Test(expected = AssertionError.class) + @Test public void testSubjectContainsNotMatches() { //given final String fragment = "foo"; //when sendMimeMultipartMessage("from", "to", "subject tail", "body"); //then - assertReceivedMessage().withSubjectContains(fragment); + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> + assertReceivedMessage() + .withSubjectContains(fragment)); } /** @@ -199,14 +213,17 @@ public class WiserAssertionsTest extends AbstractWiserTest { * Test {@link WiserAssertions#withSubject(java.lang.String)} where the * message does not have the subject expected. */ - @Test(expected = AssertionError.class) + @Test public void testSubjectNotMatches() { //given final String subject = "message subject"; //when sendMimeMultipartMessage("from", "to", subject, "body"); //then - assertReceivedMessage().withSubject("other subject"); + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> + assertReceivedMessage() + .withSubject("other subject")); } /** @@ -228,14 +245,17 @@ public class WiserAssertionsTest extends AbstractWiserTest { * is not sent from a user. * */ - @Test(expected = AssertionError.class) + @Test public void testToNotMatches() { //given final String to = "carl@b.com"; //when sendMimeMultipartMessage("from", to, "subject", "body"); //then - assertReceivedMessage().to("bob@a.com"); + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> + assertReceivedMessage() + .to("bob@a.com")); } }