diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/connector/DefaultConnection.java b/acme4j-client/src/main/java/org/shredzone/acme4j/connector/DefaultConnection.java index 50f645ea..57735fbf 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/connector/DefaultConnection.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/connector/DefaultConnection.java @@ -189,7 +189,7 @@ public class DefaultConnection implements Connection { } JSON result = JSON.parse(in); - LOG.debug("Result JSON: {}", result.toString()); + LOG.debug("Result JSON: {}", result); return result; } catch (IOException ex) { throw new AcmeNetworkException(ex); diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/exception/AcmeUserActionRequiredException.java b/acme4j-client/src/main/java/org/shredzone/acme4j/exception/AcmeUserActionRequiredException.java index 2235645a..55b2eec1 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/exception/AcmeUserActionRequiredException.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/exception/AcmeUserActionRequiredException.java @@ -67,7 +67,7 @@ public class AcmeUserActionRequiredException extends AcmeServerException { try { return instance.toURL(); } catch (MalformedURLException ex) { - throw new AcmeProtocolException("Bad instance URL: " + instance.toString(), ex); + throw new AcmeProtocolException("Bad instance URL: " + instance, ex); } } diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/AccountBuilderTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/AccountBuilderTest.java index 9b5361c3..26851397 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/AccountBuilderTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/AccountBuilderTest.java @@ -26,7 +26,7 @@ import java.security.KeyPair; import javax.crypto.SecretKey; import org.jose4j.jwx.CompactSerializer; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.shredzone.acme4j.connector.Resource; import org.shredzone.acme4j.provider.TestableConnectionProvider; diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/AccountTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/AccountTest.java index b23edecd..380d534c 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/AccountTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/AccountTest.java @@ -17,7 +17,8 @@ import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; import static org.shredzone.acme4j.toolbox.TestUtils.getJSON; import static org.shredzone.acme4j.toolbox.TestUtils.url; import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs; @@ -34,7 +35,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.jose4j.jws.JsonWebSignature; import org.jose4j.jwx.CompactSerializer; import org.jose4j.lang.JoseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.Account.EditableAccount; import org.shredzone.acme4j.challenge.Dns01Challenge; import org.shredzone.acme4j.challenge.Http01Challenge; @@ -255,13 +256,11 @@ public class AccountTest { Account account = new Account(login); - try { - account.preAuthorizeDomain("example.org"); - fail("preauthorization was accepted"); - } catch (AcmeServerException ex) { - assertThat(ex.getType(), is(problemType)); - assertThat(ex.getMessage(), is(problemDetail)); - } + AcmeServerException ex = assertThrows(AcmeServerException.class, () -> + account.preAuthorizeDomain("example.org") + ); + assertThat(ex.getType(), is(problemType)); + assertThat(ex.getMessage(), is(problemDetail)); provider.close(); } @@ -278,27 +277,9 @@ public class AccountTest { Login login = provider.createLogin(); Account account = login.getAccount(); - try { - account.preAuthorizeDomain(null); - fail("null domain was accepted"); - } catch (NullPointerException ex) { - // expected - } - - try { - account.preAuthorizeDomain(""); - fail("empty domain string was accepted"); - } catch (IllegalArgumentException ex) { - // expected - } - - try { - account.preAuthorizeDomain("example.com"); - fail("preauthorization was accepted"); - } catch (AcmeException ex) { - // expected - assertThat(ex.getMessage(), is("Server does not offer newAuthz")); - } + assertThrows(NullPointerException.class, () -> account.preAuthorizeDomain(null)); + assertThrows(IllegalArgumentException.class, () -> account.preAuthorizeDomain("")); + assertThrows(AcmeException.class, () -> account.preAuthorizeDomain("example.com")); provider.close(); } @@ -342,7 +323,7 @@ public class AccountTest { expectedPayload.append("}}"); assertThat(decodedPayload, sameJSONAs(expectedPayload.toString())); } catch (JoseException ex) { - fail("decoding inner payload failed"); + fail(ex); } return HttpURLConnection.HTTP_OK; @@ -370,15 +351,17 @@ public class AccountTest { /** * Test that the same account key is not accepted for change. */ - @Test(expected = IllegalArgumentException.class) + @Test public void testChangeSameKey() throws Exception { - TestableConnectionProvider provider = new TestableConnectionProvider(); - Login login = provider.createLogin(); + assertThrows(IllegalArgumentException.class, () -> { + TestableConnectionProvider provider = new TestableConnectionProvider(); + Login login = provider.createLogin(); - Account account = new Account(login); - account.changeKey(login.getKeyPair()); + Account account = new Account(login); + account.changeKey(login.getKeyPair()); - provider.close(); + provider.close(); + }); } /** diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/AcmeJsonResourceTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/AcmeJsonResourceTest.java index 4278a07d..3feea301 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/AcmeJsonResourceTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/AcmeJsonResourceTest.java @@ -20,7 +20,7 @@ import static org.shredzone.acme4j.toolbox.TestUtils.url; import java.net.URL; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.exception.AcmeException; import org.shredzone.acme4j.toolbox.JSON; import org.shredzone.acme4j.toolbox.TestUtils; diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/AcmeResourceTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/AcmeResourceTest.java index 23e985c2..efadc99a 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/AcmeResourceTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/AcmeResourceTest.java @@ -15,8 +15,7 @@ package org.shredzone.acme4j; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -25,7 +24,7 @@ import java.io.ObjectOutputStream; import java.net.URL; import java.nio.charset.StandardCharsets; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.toolbox.TestUtils; /** @@ -97,16 +96,18 @@ public class AcmeResourceTest { /** * Test if a rebind attempt fails. */ - @Test(expected = IllegalStateException.class) + @Test public void testRebind() throws Exception { - Login login = TestUtils.login(); - URL location = new URL("http://example.com/acme/resource"); + assertThrows(IllegalStateException.class, () -> { + Login login = TestUtils.login(); + URL location = new URL("http://example.com/acme/resource"); - AcmeResource resource = new DummyResource(login, location); - assertThat(resource.getLogin(), is(login)); + AcmeResource resource = new DummyResource(login, location); + assertThat(resource.getLogin(), is(login)); - Login login2 = TestUtils.login(); - resource.rebind(login2); // fails to rebind to another login + Login login2 = TestUtils.login(); + resource.rebind(login2); // fails to rebind to another login + }); } /** diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/AuthorizationTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/AuthorizationTest.java index 0f331c46..09673108 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/AuthorizationTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/AuthorizationTest.java @@ -15,8 +15,7 @@ package org.shredzone.acme4j; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.shredzone.acme4j.toolbox.AcmeUtils.parseTimestamp; import static org.shredzone.acme4j.toolbox.TestUtils.getJSON; import static org.shredzone.acme4j.toolbox.TestUtils.url; @@ -28,7 +27,7 @@ import java.time.Duration; import java.time.Instant; import java.util.concurrent.atomic.AtomicBoolean; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.challenge.Challenge; import org.shredzone.acme4j.challenge.Dns01Challenge; import org.shredzone.acme4j.challenge.Http01Challenge; @@ -105,10 +104,12 @@ public class AuthorizationTest { * Test that {@link Authorization#findChallenge(String)} fails on duplicate * challenges. */ - @Test(expected = AcmeProtocolException.class) + @Test public void testFailDuplicateChallenges() throws IOException { - Authorization authorization = createChallengeAuthorization(); - authorization.findChallenge(DUPLICATE_TYPE); + assertThrows(AcmeProtocolException.class, () -> { + Authorization authorization = createChallengeAuthorization(); + authorization.findChallenge(DUPLICATE_TYPE); + }); } /** diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/CertificateTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/CertificateTest.java index ee843cef..c87ed5f7 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/CertificateTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/CertificateTest.java @@ -33,7 +33,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.connector.Resource; import org.shredzone.acme4j.exception.AcmeException; import org.shredzone.acme4j.provider.TestableConnectionProvider; diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/IdentifierTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/IdentifierTest.java index 3126fdf0..666a5bbb 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/IdentifierTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/IdentifierTest.java @@ -15,14 +15,13 @@ package org.shredzone.acme4j; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.exception.AcmeProtocolException; import org.shredzone.acme4j.toolbox.JSONBuilder; @@ -74,9 +73,11 @@ public class IdentifierTest { assertThat(id2.getDomain(), is("xn--xml-qla7ae5k.com")); } - @Test(expected = AcmeProtocolException.class) + @Test public void testNoDns() { - new Identifier("foo", "example.com").getDomain(); + assertThrows(AcmeProtocolException.class, () -> + new Identifier("foo", "example.com").getDomain() + ); } @Test @@ -97,9 +98,11 @@ public class IdentifierTest { assertThat(id3.getIP().getHostAddress(), is("192.168.2.99")); } - @Test(expected = AcmeProtocolException.class) + @Test public void testNoIp() { - new Identifier("foo", "example.com").getIP(); + assertThrows(AcmeProtocolException.class, () -> + new Identifier("foo", "example.com").getIP() + ); } @Test diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/LoginTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/LoginTest.java index 9c49050c..9d0e72fa 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/LoginTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/LoginTest.java @@ -15,8 +15,7 @@ package org.shredzone.acme4j; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.*; import static org.shredzone.acme4j.toolbox.TestUtils.getJSON; import static org.shredzone.acme4j.toolbox.TestUtils.url; @@ -26,7 +25,7 @@ import java.net.HttpURLConnection; import java.net.URL; import java.security.KeyPair; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; import org.shredzone.acme4j.challenge.Challenge; import org.shredzone.acme4j.challenge.Dns01Challenge; diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/OrderBuilderTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/OrderBuilderTest.java index d13484e0..ee88f5f1 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/OrderBuilderTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/OrderBuilderTest.java @@ -15,8 +15,7 @@ package org.shredzone.acme4j; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.shredzone.acme4j.toolbox.AcmeUtils.parseTimestamp; import static org.shredzone.acme4j.toolbox.TestUtils.getJSON; import static org.shredzone.acme4j.toolbox.TestUtils.url; @@ -29,9 +28,10 @@ import java.time.Duration; import java.time.Instant; import java.util.Arrays; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.connector.Resource; import org.shredzone.acme4j.exception.AcmeException; +import org.shredzone.acme4j.exception.AcmeProtocolException; import org.shredzone.acme4j.provider.TestableConnectionProvider; import org.shredzone.acme4j.toolbox.JSON; import org.shredzone.acme4j.toolbox.JSONBuilder; @@ -179,20 +179,22 @@ public class OrderBuilderTest { /** * Test that an auto-renewal {@link Order} cannot be created if unsupported by the CA. */ - @Test(expected = AcmeException.class) + @Test public void testAutoRenewOrderCertificateFails() throws Exception { - TestableConnectionProvider provider = new TestableConnectionProvider(); - provider.putTestResource(Resource.NEW_ORDER, resourceUrl); + assertThrows(AcmeException.class, () -> { + TestableConnectionProvider provider = new TestableConnectionProvider(); + provider.putTestResource(Resource.NEW_ORDER, resourceUrl); - Login login = provider.createLogin(); + Login login = provider.createLogin(); - Account account = new Account(login); - account.newOrder() - .domain("example.org") - .autoRenewal() - .create(); + Account account = new Account(login); + account.newOrder() + .domain("example.org") + .autoRenewal() + .create(); - provider.close(); + provider.close(); + }); } /** @@ -207,35 +209,35 @@ public class OrderBuilderTest { Account account = new Account(login); - assertThrows("accepted notBefore", IllegalArgumentException.class, () -> { + assertThrows(IllegalArgumentException.class, () -> { OrderBuilder ob = account.newOrder().autoRenewal(); ob.notBefore(someInstant); - }); + }, "accepted notBefore"); - assertThrows("accepted notAfter", IllegalArgumentException.class, () -> { + assertThrows(IllegalArgumentException.class, () -> { OrderBuilder ob = account.newOrder().autoRenewal(); ob.notAfter(someInstant); - }); + }, "accepted notAfter"); - assertThrows("accepted autoRenewal", IllegalArgumentException.class, () -> { + assertThrows(IllegalArgumentException.class, () -> { OrderBuilder ob = account.newOrder().notBefore(someInstant); ob.autoRenewal(); - }); + }, "accepted autoRenewal"); - assertThrows("accepted autoRenewalStart", IllegalArgumentException.class, () -> { + assertThrows(IllegalArgumentException.class, () -> { OrderBuilder ob = account.newOrder().notBefore(someInstant); ob.autoRenewalStart(someInstant); - }); + }, "accepted autoRenewalStart"); - assertThrows("accepted autoRenewalEnd", IllegalArgumentException.class, () -> { + assertThrows(IllegalArgumentException.class, () -> { OrderBuilder ob = account.newOrder().notBefore(someInstant); ob.autoRenewalEnd(someInstant); - }); + }, "accepted autoRenewalEnd"); - assertThrows("accepted autoRenewalLifetime", IllegalArgumentException.class, () -> { + assertThrows(IllegalArgumentException.class, () -> { OrderBuilder ob = account.newOrder().notBefore(someInstant); ob.autoRenewalLifetime(Duration.ofDays(7)); - }); + }, "accepted autoRenewalLifetime"); provider.close(); } diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/OrderTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/OrderTest.java index 578cac11..e3cb389f 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/OrderTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/OrderTest.java @@ -27,7 +27,7 @@ import java.time.Duration; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.provider.TestableConnectionProvider; import org.shredzone.acme4j.toolbox.JSON; import org.shredzone.acme4j.toolbox.JSONBuilder; diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/ProblemTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/ProblemTest.java index c82e0cc6..9df383bd 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/ProblemTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/ProblemTest.java @@ -23,7 +23,7 @@ import java.net.URI; import java.net.URL; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.toolbox.JSON; import org.shredzone.acme4j.toolbox.JSONBuilder; import org.shredzone.acme4j.toolbox.TestUtils; diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/SessionTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/SessionTest.java index 05f23cba..76d183d0 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/SessionTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/SessionTest.java @@ -15,8 +15,7 @@ package org.shredzone.acme4j; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.*; import static org.shredzone.acme4j.toolbox.TestUtils.*; @@ -27,7 +26,7 @@ import java.security.KeyPair; import java.time.Duration; import java.time.ZonedDateTime; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; import org.shredzone.acme4j.connector.Resource; import org.shredzone.acme4j.exception.AcmeException; @@ -61,10 +60,12 @@ public class SessionTest { assertThat(session3, not(nullValue())); assertThat(session3.getServerUri(), is(serverUri)); - assertThrows("Bad URI in constructor", IllegalArgumentException.class, - () -> new Session("#*aBaDuRi*#")); - assertThrows("Unsupported URI", IllegalArgumentException.class, - () -> new Session(URI.create("acme://invalid"), new GenericAcmeProvider())); + assertThrows(IllegalArgumentException.class, + () -> new Session("#*aBaDuRi*#"), + "Bad URI in constructor"); + assertThrows(IllegalArgumentException.class, + () -> new Session(URI.create("acme://invalid"), new GenericAcmeProvider()), + "Unsupported URI"); } /** diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/StatusTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/StatusTest.java index 204535f6..8d6754dc 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/StatusTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/StatusTest.java @@ -16,8 +16,7 @@ package org.shredzone.acme4j; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import org.junit.Test; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.Test; /** * Unit tests for {@link Status} enumeration. diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/ChallengeTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/ChallengeTest.java index 9fa7f2d0..1e8a8628 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/ChallengeTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/ChallengeTest.java @@ -16,8 +16,7 @@ package org.shredzone.acme4j.challenge; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.shredzone.acme4j.toolbox.AcmeUtils.parseTimestamp; import static org.shredzone.acme4j.toolbox.TestUtils.getJSON; import static org.shredzone.acme4j.toolbox.TestUtils.url; @@ -29,7 +28,7 @@ import java.net.URL; import java.time.Duration; import java.time.Instant; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.Login; import org.shredzone.acme4j.Problem; import org.shredzone.acme4j.Status; @@ -85,9 +84,11 @@ public class ChallengeTest { /** * Test that an exception is thrown on challenge type mismatch. */ - @Test(expected = AcmeProtocolException.class) + @Test public void testNotAcceptable() { - new Http01Challenge(TestUtils.login(), getJSON("dnsChallenge")); + assertThrows(AcmeProtocolException.class, () -> + new Http01Challenge(TestUtils.login(), getJSON("dnsChallenge")) + ); } /** @@ -197,9 +198,11 @@ public class ChallengeTest { /** * Test that unmarshalling something different like a challenge fails. */ - @Test(expected = AcmeProtocolException.class) + @Test public void testBadUnmarshall() { - new Challenge(TestUtils.login(), getJSON("updateAccountResponse")); + assertThrows(AcmeProtocolException.class, () -> + new Challenge(TestUtils.login(), getJSON("updateAccountResponse")) + ); } } diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/DnsChallengeTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/DnsChallengeTest.java index 2cf8a201..f02552e5 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/DnsChallengeTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/DnsChallengeTest.java @@ -18,7 +18,7 @@ import static org.hamcrest.Matchers.is; import static org.shredzone.acme4j.toolbox.TestUtils.getJSON; import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.Login; import org.shredzone.acme4j.Status; import org.shredzone.acme4j.toolbox.JSONBuilder; diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/HttpChallengeTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/HttpChallengeTest.java index 633e3a56..1d82170f 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/HttpChallengeTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/HttpChallengeTest.java @@ -15,10 +15,11 @@ package org.shredzone.acme4j.challenge; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.shredzone.acme4j.toolbox.TestUtils.getJSON; import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.Login; import org.shredzone.acme4j.Status; import org.shredzone.acme4j.exception.AcmeProtocolException; @@ -57,10 +58,12 @@ public class HttpChallengeTest { /** * Test that an exception is thrown if there is no token. */ - @Test(expected = AcmeProtocolException.class) + @Test public void testNoTokenSet() { - Http01Challenge challenge = new Http01Challenge(login, getJSON("httpNoTokenChallenge")); - challenge.getToken(); + assertThrows(AcmeProtocolException.class, () -> { + Http01Challenge challenge = new Http01Challenge(login, getJSON("httpNoTokenChallenge")); + challenge.getToken(); + }); } } diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/TlsAlpn01ChallengeTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/TlsAlpn01ChallengeTest.java index f08fe6ea..845aa273 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/TlsAlpn01ChallengeTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/TlsAlpn01ChallengeTest.java @@ -18,7 +18,7 @@ import static org.hamcrest.Matchers.is; import static org.shredzone.acme4j.toolbox.TestUtils.getJSON; import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.Login; import org.shredzone.acme4j.Status; import org.shredzone.acme4j.toolbox.AcmeUtils; diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/TokenChallengeTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/TokenChallengeTest.java index 06ca70bd..ed19d3c4 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/TokenChallengeTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/TokenChallengeTest.java @@ -13,12 +13,11 @@ */ package org.shredzone.acme4j.challenge; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.Login; import org.shredzone.acme4j.exception.AcmeProtocolException; import org.shredzone.acme4j.provider.TestableConnectionProvider; diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/connector/DefaultConnectionTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/connector/DefaultConnectionTest.java index 63cfaa88..7c435651 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/connector/DefaultConnectionTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/connector/DefaultConnectionTest.java @@ -18,8 +18,8 @@ import static java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME; import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.any; import static org.mockito.Mockito.*; import static org.shredzone.acme4j.toolbox.TestUtils.url; @@ -51,8 +51,8 @@ import java.util.Optional; import org.jose4j.jws.JsonWebSignature; import org.jose4j.jwx.CompactSerializer; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; import org.shredzone.acme4j.Login; import org.shredzone.acme4j.Session; @@ -85,7 +85,7 @@ public class DefaultConnectionTest { private Login login; private KeyPair keyPair; - @Before + @BeforeEach public void setup() throws AcmeException, IOException { mockUrlConnection = mock(HttpURLConnection.class); @@ -390,8 +390,6 @@ public class DefaultConnectionTest { try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) { conn.conn = mockUrlConnection; conn.handleRetryAfter("no header"); - } catch (AcmeRetryAfterException ex) { - fail("an AcmeRetryAfterException was thrown"); } verify(mockUrlConnection, atLeastOnce()).getHeaderField("Retry-After"); @@ -407,8 +405,6 @@ public class DefaultConnectionTest { try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) { conn.conn = mockUrlConnection; conn.handleRetryAfter("http ok"); - } catch (AcmeRetryAfterException ex) { - fail("an AcmeRetryAfterException was thrown"); } } @@ -725,22 +721,15 @@ public class DefaultConnectionTest { @Override public void resetNonce(Session session) { assertThat(session, is(sameInstance(DefaultConnectionTest.this.session))); - if (session.getNonce() == null) { - session.setNonce(nonce1); - } else { - fail("unknown nonce"); - } + assertThat(session.getNonce(), nullValue()); + session.setNonce(nonce1); } @Override public String getNonce() { assertThat(session, is(sameInstance(DefaultConnectionTest.this.session))); - if (session.getNonce() == nonce1) { - return nonce2; - } else { - fail("unknown nonce"); - return null; - } + assertThat(session.getNonce(), is(nonce1)); + return nonce2; } }) { JSONBuilder cb = new JSONBuilder(); @@ -800,22 +789,15 @@ public class DefaultConnectionTest { @Override public void resetNonce(Session session) { assertThat(session, is(sameInstance(DefaultConnectionTest.this.session))); - if (session.getNonce() == null) { - session.setNonce(nonce1); - } else { - fail("unknown nonce"); - } + assertThat(session.getNonce(), nullValue()); + session.setNonce(nonce1); } @Override public String getNonce() { assertThat(session, is(sameInstance(DefaultConnectionTest.this.session))); - if (session.getNonce() == nonce1) { - return nonce2; - } else { - fail("unknown nonce"); - return null; - } + assertThat(session.getNonce(), is(nonce1)); + return nonce2; } }) { conn.sendSignedPostAsGetRequest(requestUrl, login); @@ -873,22 +855,15 @@ public class DefaultConnectionTest { @Override public void resetNonce(Session session) { assertThat(session, is(sameInstance(DefaultConnectionTest.this.session))); - if (session.getNonce() == null) { - session.setNonce(nonce1); - } else { - fail("unknown nonce"); - } + assertThat(session.getNonce(), nullValue()); + session.setNonce(nonce1); } @Override public String getNonce() { assertThat(session, is(sameInstance(DefaultConnectionTest.this.session))); - if (session.getNonce() == nonce1) { - return nonce2; - } else { - fail("unknown nonce"); - return null; - } + assertThat(session.getNonce(), is(nonce1)); + return nonce2; } }) { conn.sendCertificateRequest(requestUrl, login); @@ -924,22 +899,15 @@ public class DefaultConnectionTest { @Override public void resetNonce(Session session) { assertThat(session, is(sameInstance(DefaultConnectionTest.this.session))); - if (session.getNonce() == null) { - session.setNonce(nonce1); - } else { - fail("unknown nonce"); - } + assertThat(session.getNonce(), nullValue()); + session.setNonce(nonce1); } @Override public String getNonce() { assertThat(session, is(sameInstance(DefaultConnectionTest.this.session))); - if (session.getNonce() == nonce1) { - return nonce2; - } else { - fail("unknown nonce"); - return null; - } + assertThat(session.getNonce(), is(nonce1)); + return nonce2; } }) { JSONBuilder cb = new JSONBuilder(); @@ -989,17 +957,19 @@ public class DefaultConnectionTest { /** * Test signed POST requests if there is no nonce. */ - @Test(expected = AcmeException.class) + @Test public void testSendSignedRequestNoNonce() throws Exception { when(mockHttpConnection.openConnection(eq(new URL("https://example.com/acme/new-nonce")), any())) .thenReturn(mockUrlConnection); when(mockUrlConnection.getResponseCode()) .thenReturn(HttpURLConnection.HTTP_NOT_FOUND); - try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) { - JSONBuilder cb = new JSONBuilder(); - conn.sendSignedRequest(requestUrl, cb, DefaultConnectionTest.this.session, DefaultConnectionTest.this.keyPair); - } + assertThrows(AcmeException.class, () -> { + try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) { + JSONBuilder cb = new JSONBuilder(); + conn.sendSignedRequest(requestUrl, cb, DefaultConnectionTest.this.session, DefaultConnectionTest.this.keyPair); + } + }); } /** @@ -1061,7 +1031,7 @@ public class DefaultConnectionTest { /** * Test that a bad certificate throws an exception. */ - @Test(expected = AcmeProtocolException.class) + @Test public void testReadBadCertificate() throws Exception { // Build a broken certificate chain PEM file byte[] brokenPem; @@ -1079,10 +1049,12 @@ public class DefaultConnectionTest { when(mockUrlConnection.getHeaderField("Content-Type")).thenReturn("application/pem-certificate-chain"); when(mockUrlConnection.getInputStream()).thenReturn(new ByteArrayInputStream(brokenPem)); - try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) { - conn.conn = mockUrlConnection; - conn.readCertificates(); - } + assertThrows(AcmeProtocolException.class, () -> { + try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) { + conn.conn = mockUrlConnection; + conn.readCertificates(); + } + }); } /** diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/connector/HttpConnectorTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/connector/HttpConnectorTest.java index 952dc71c..72ab8582 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/connector/HttpConnectorTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/connector/HttpConnectorTest.java @@ -23,8 +23,8 @@ import java.net.HttpURLConnection; import java.net.URL; import java.time.Duration; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; /** * Unit tests for {@link HttpConnector}. @@ -59,7 +59,7 @@ public class HttpConnectorTest { * builds. */ @Test - @Category(HttpURLConnection.class) + @Tag("requires-network") public void testOpenConnection() throws IOException { NetworkSettings settings = new NetworkSettings(); HttpConnector connector = new HttpConnector(); diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/connector/NetworkSettingsTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/connector/NetworkSettingsTest.java index 4b2de347..19e738c1 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/connector/NetworkSettingsTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/connector/NetworkSettingsTest.java @@ -15,14 +15,13 @@ package org.shredzone.acme4j.connector; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.net.InetSocketAddress; import java.net.Proxy; import java.time.Duration; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit tests for {@link NetworkSettings}. @@ -52,14 +51,18 @@ public class NetworkSettingsTest { public void testInvalidTimeouts() { NetworkSettings settings = new NetworkSettings(); - assertThrows("timeout accepted null", IllegalArgumentException.class, - () -> settings.setTimeout(null)); - assertThrows("timeout accepted zero duration", IllegalArgumentException.class, - () -> settings.setTimeout(Duration.ZERO)); - assertThrows("timeout accepted negative duration", IllegalArgumentException.class, - () -> settings.setTimeout(Duration.ofSeconds(20).negated())); - assertThrows("timeout accepted out of range value", IllegalArgumentException.class, - () -> settings.setTimeout(Duration.ofMillis(Integer.MAX_VALUE + 1L))); + assertThrows(IllegalArgumentException.class, + () -> settings.setTimeout(null), + "timeout accepted null"); + assertThrows(IllegalArgumentException.class, + () -> settings.setTimeout(Duration.ZERO), + "timeout accepted zero duration"); + assertThrows(IllegalArgumentException.class, + () -> settings.setTimeout(Duration.ofSeconds(20).negated()), + "timeout accepted negative duration"); + assertThrows(IllegalArgumentException.class, + () -> settings.setTimeout(Duration.ofMillis(Integer.MAX_VALUE + 1L)), + "timeout accepted out of range value"); } } diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/connector/ResourceIteratorTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/connector/ResourceIteratorTest.java index ad00bfeb..0b7bc7e1 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/connector/ResourceIteratorTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/connector/ResourceIteratorTest.java @@ -15,6 +15,7 @@ package org.shredzone.acme4j.connector; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.shredzone.acme4j.toolbox.TestUtils.url; import java.io.IOException; @@ -27,8 +28,8 @@ import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.Authorization; import org.shredzone.acme4j.Login; import org.shredzone.acme4j.provider.TestableConnectionProvider; @@ -47,7 +48,7 @@ public class ResourceIteratorTest { private final List resourceURLs = new ArrayList<>(PAGES * RESOURCES_PER_PAGE); private final List pageURLs = new ArrayList<>(PAGES); - @Before + @BeforeEach public void setup() { resourceURLs.clear(); for (int ix = 0; ix < RESOURCES_PER_PAGE * PAGES; ix++) { @@ -63,13 +64,15 @@ public class ResourceIteratorTest { /** * Test if the {@link ResourceIterator} handles a {@code null} start URL. */ - @Test(expected = NoSuchElementException.class) + @Test public void nullTest() throws IOException { - Iterator it = createIterator(null); + assertThrows(NoSuchElementException.class, () -> { + Iterator it = createIterator(null); - assertThat(it, not(nullValue())); - assertThat(it.hasNext(), is(false)); - it.next(); // throws NoSuchElementException + assertThat(it, not(nullValue())); + assertThat(it.hasNext(), is(false)); + it.next(); // throws NoSuchElementException + }); } /** @@ -114,11 +117,13 @@ public class ResourceIteratorTest { /** * Test that {@link Iterator#remove()} fails. */ - @Test(expected = UnsupportedOperationException.class) + @Test public void removeTest() throws IOException { - Iterator it = createIterator(pageURLs.get(0)); - it.next(); - it.remove(); // throws UnsupportedOperationException + assertThrows(UnsupportedOperationException.class, () -> { + Iterator it = createIterator(pageURLs.get(0)); + it.next(); + it.remove(); // throws UnsupportedOperationException + }); } /** diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/connector/ResourceTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/connector/ResourceTest.java index c47328fe..6d49990f 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/connector/ResourceTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/connector/ResourceTest.java @@ -16,7 +16,7 @@ package org.shredzone.acme4j.connector; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit test for {@link Resource}. diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/connector/SessionProviderTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/connector/SessionProviderTest.java index 68190827..3e216033 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/connector/SessionProviderTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/connector/SessionProviderTest.java @@ -15,12 +15,13 @@ package org.shredzone.acme4j.connector; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.net.URI; import java.net.URL; import java.util.ServiceLoader; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.Login; import org.shredzone.acme4j.Session; import org.shredzone.acme4j.challenge.Challenge; @@ -38,9 +39,11 @@ public class SessionProviderTest { * There are no testing providers accepting {@code acme://example.org}. Test that * connecting to this URI will result in an {@link IllegalArgumentException}. */ - @Test(expected = IllegalArgumentException.class) + @Test public void testNone() throws Exception { - new Session(new URI("acme://example.org")).provider(); + assertThrows(IllegalArgumentException.class, () -> + new Session(new URI("acme://example.org")).provider() + ); } /** @@ -63,9 +66,11 @@ public class SessionProviderTest { * There are two testing providers accepting {@code acme://example.net}. Test that * connecting to this URI will result in an {@link IllegalArgumentException}. */ - @Test(expected = IllegalArgumentException.class) + @Test public void testDuplicate() throws Exception { - new Session(new URI("acme://example.net")).provider(); + assertThrows(IllegalArgumentException.class, () -> + new Session(new URI("acme://example.net")).provider() + ); } public static class Provider1 implements AcmeProvider { diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/connector/TrimmingInputStreamTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/connector/TrimmingInputStreamTest.java index 8d88e181..e21cc0e6 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/connector/TrimmingInputStreamTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/connector/TrimmingInputStreamTest.java @@ -21,7 +21,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit tests for {@link TrimmingInputStream}. diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeExceptionTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeExceptionTest.java index 85910055..b25f4d68 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeExceptionTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeExceptionTest.java @@ -19,7 +19,7 @@ import static org.hamcrest.Matchers.nullValue; import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit tests for {@link AcmeException}. @@ -48,7 +48,7 @@ public class AcmeExceptionTest { AcmeException ex = new AcmeException(message, cause); assertThat(ex.getMessage(), is(message)); - assertThat(ex.getCause(), is((Throwable) cause)); + assertThat(ex.getCause(), is(cause)); } } diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeLazyLoadingExceptionTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeLazyLoadingExceptionTest.java index e2fcf455..3862de22 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeLazyLoadingExceptionTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeLazyLoadingExceptionTest.java @@ -19,7 +19,7 @@ import static org.mockito.Mockito.mock; import java.net.URL; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.AcmeResource; import org.shredzone.acme4j.Login; import org.shredzone.acme4j.toolbox.TestUtils; diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeNetworkExceptionTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeNetworkExceptionTest.java index c58ea9af..8981747a 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeNetworkExceptionTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeNetworkExceptionTest.java @@ -19,7 +19,7 @@ import static org.hamcrest.Matchers.notNullValue; import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit tests for {@link AcmeNetworkException}. diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeProtocolExceptionTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeProtocolExceptionTest.java index 3c89cb64..d812bdf8 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeProtocolExceptionTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeProtocolExceptionTest.java @@ -16,7 +16,7 @@ package org.shredzone.acme4j.exception; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit tests for {@link AcmeProtocolException}. diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeRateLimitedExceptionTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeRateLimitedExceptionTest.java index 31b0d531..c6ac7438 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeRateLimitedExceptionTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeRateLimitedExceptionTest.java @@ -25,7 +25,7 @@ import java.time.Instant; import java.util.Arrays; import java.util.Collection; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.Problem; /** diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeRetryAfterExceptionTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeRetryAfterExceptionTest.java index 67c39758..52bf702e 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeRetryAfterExceptionTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeRetryAfterExceptionTest.java @@ -15,11 +15,12 @@ package org.shredzone.acme4j.exception; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.time.Duration; import java.time.Instant; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit tests for {@link AcmeRetryAfterException}. @@ -43,9 +44,11 @@ public class AcmeRetryAfterExceptionTest { /** * Test that date is required. */ - @Test(expected = NullPointerException.class) - public void testRequiredAcmeRetryAfterException() throws AcmeException { - throw new AcmeRetryAfterException("null-test", null); + @Test + public void testRequiredAcmeRetryAfterException() { + assertThrows(NullPointerException.class, () -> { + throw new AcmeRetryAfterException("null-test", null); + }); } } diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeUserActionRequiredExceptionTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeUserActionRequiredExceptionTest.java index bde92479..fd737a0e 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeUserActionRequiredExceptionTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeUserActionRequiredExceptionTest.java @@ -22,7 +22,7 @@ import java.net.MalformedURLException; import java.net.URI; import java.net.URL; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.Problem; /** diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/provider/AbstractAcmeProviderTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/provider/AbstractAcmeProviderTest.java index 28bd8d13..a3da9b8d 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/provider/AbstractAcmeProviderTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/provider/AbstractAcmeProviderTest.java @@ -15,8 +15,7 @@ package org.shredzone.acme4j.provider; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.any; import static org.mockito.Mockito.*; import static org.shredzone.acme4j.toolbox.TestUtils.getJSON; @@ -31,7 +30,7 @@ import java.time.temporal.ChronoUnit; import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.Login; import org.shredzone.acme4j.Session; import org.shredzone.acme4j.challenge.Challenge; diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/provider/GenericAcmeProviderTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/provider/GenericAcmeProviderTest.java index bf01a64c..e42825c8 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/provider/GenericAcmeProviderTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/provider/GenericAcmeProviderTest.java @@ -20,7 +20,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.connector.Connection; import org.shredzone.acme4j.connector.DefaultConnection; diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/provider/letsencrypt/LetsEncryptAcmeProviderTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/provider/letsencrypt/LetsEncryptAcmeProviderTest.java index a7914bfd..c92d6ed6 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/provider/letsencrypt/LetsEncryptAcmeProviderTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/provider/letsencrypt/LetsEncryptAcmeProviderTest.java @@ -15,14 +15,13 @@ package org.shredzone.acme4j.provider.letsencrypt; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.shredzone.acme4j.toolbox.TestUtils.url; import java.net.URI; import java.net.URISyntaxException; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit tests for {@link LetsEncryptAcmeProvider}. diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/provider/pebble/PebbleAcmeProviderTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/provider/pebble/PebbleAcmeProviderTest.java index 0e4258d8..49b5236c 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/provider/pebble/PebbleAcmeProviderTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/provider/pebble/PebbleAcmeProviderTest.java @@ -15,14 +15,13 @@ package org.shredzone.acme4j.provider.pebble; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.shredzone.acme4j.toolbox.TestUtils.url; import java.net.URI; import java.net.URISyntaxException; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit tests for {@link PebbleAcmeProvider}. diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/toolbox/AcmeUtilsTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/toolbox/AcmeUtilsTest.java index 7fb74061..d1721a7d 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/toolbox/AcmeUtilsTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/toolbox/AcmeUtilsTest.java @@ -16,8 +16,7 @@ package org.shredzone.acme4j.toolbox; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.shredzone.acme4j.toolbox.AcmeUtils.*; import java.io.ByteArrayOutputStream; @@ -40,17 +39,16 @@ import java.util.List; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.exception.AcmeProtocolException; -import org.shredzone.acme4j.toolbox.AcmeUtils.*; /** * Unit tests for {@link AcmeUtils}. */ public class AcmeUtilsTest { - @BeforeClass + @BeforeAll public static void setup() { Security.addProvider(new BouncyCastleProvider()); } @@ -173,14 +171,18 @@ public class AcmeUtilsTest { */ @Test public void testInvalid() { - assertThrows("accepted empty string", IllegalArgumentException.class, - () -> parseTimestamp("")); - assertThrows("accepted nonsense string", IllegalArgumentException.class, - () -> parseTimestamp("abc")); - assertThrows("accepted date only string", IllegalArgumentException.class, - () -> parseTimestamp("2015-12-27")); - assertThrows("accepted string without time", IllegalArgumentException.class, - () -> parseTimestamp("2015-12-27T")); + assertThrows(IllegalArgumentException.class, + () -> parseTimestamp(""), + "accepted empty string"); + assertThrows(IllegalArgumentException.class, + () -> parseTimestamp("abc"), + "accepted nonsense string"); + assertThrows(IllegalArgumentException.class, + () -> parseTimestamp("2015-12-27"), + "accepted date only string"); + assertThrows(IllegalArgumentException.class, + () -> parseTimestamp("2015-12-27T"), + "accepted string without time"); } /** @@ -252,12 +254,15 @@ public class AcmeUtilsTest { public void testValidateContact() { AcmeUtils.validateContact(URI.create("mailto:foo@example.com")); - assertThrows("multiple recipients are accepted", IllegalArgumentException.class, - () -> AcmeUtils.validateContact(URI.create("mailto:foo@example.com,bar@example.com"))); - assertThrows("hfields are accepted", IllegalArgumentException.class, - () -> AcmeUtils.validateContact(URI.create("mailto:foo@example.com?to=bar@example.com"))); - assertThrows("only hfields are accepted", IllegalArgumentException.class, - () -> AcmeUtils.validateContact(URI.create("mailto:?to=foo@example.com"))); + assertThrows(IllegalArgumentException.class, + () -> AcmeUtils.validateContact(URI.create("mailto:foo@example.com,bar@example.com")), + "multiple recipients are accepted"); + assertThrows(IllegalArgumentException.class, + () -> AcmeUtils.validateContact(URI.create("mailto:foo@example.com?to=bar@example.com")), + "hfields are accepted"); + assertThrows(IllegalArgumentException.class, + () -> AcmeUtils.validateContact(URI.create("mailto:?to=foo@example.com")), + "only hfields are accepted"); } /** diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/toolbox/JSONBuilderTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/toolbox/JSONBuilderTest.java index c4e1acb3..365bc763 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/toolbox/JSONBuilderTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/toolbox/JSONBuilderTest.java @@ -28,7 +28,7 @@ import java.util.Map; import org.jose4j.json.JsonUtil; import org.jose4j.lang.JoseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit test for {@link JSONBuilder}. diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/toolbox/JSONTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/toolbox/JSONTest.java index 8c830986..03ecc9dc 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/toolbox/JSONTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/toolbox/JSONTest.java @@ -16,8 +16,7 @@ package org.shredzone.acme4j.toolbox; import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.shredzone.acme4j.toolbox.TestUtils.url; import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs; @@ -40,7 +39,7 @@ import java.util.Map; import java.util.NoSuchElementException; import java.util.stream.Collectors; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.Problem; import org.shredzone.acme4j.Status; import org.shredzone.acme4j.exception.AcmeProtocolException; @@ -92,9 +91,11 @@ public class JSONTest { /** * Test that bad JSON fails. */ - @Test(expected = AcmeProtocolException.class) + @Test public void testParsersBadJSON() { - JSON.parse("This is no JSON."); + assertThrows(AcmeProtocolException.class, + () -> JSON.parse("This is no JSON.") + ); } /** @@ -246,30 +247,42 @@ public class JSONTest { assertThat(json.get("none").optional().isPresent(), is(false)); assertThat(json.get("none").map(Value::asString).isPresent(), is(false)); - assertThrows("asString", AcmeProtocolException.class, - () -> json.get("none").asString()); - assertThrows("asURI", AcmeProtocolException.class, - () -> json.get("none").asURI()); - assertThrows("asURL", AcmeProtocolException.class, - () -> json.get("none").asURL()); - assertThrows("asInstant", AcmeProtocolException.class, - () -> json.get("none").asInstant()); - assertThrows("asDuration", AcmeProtocolException.class, - () -> json.get("none").asDuration()); - assertThrows("asObject", AcmeProtocolException.class, - () -> json.get("none").asObject()); - assertThrows("asEncodedObject", AcmeProtocolException.class, - () -> json.get("none").asEncodedObject()); - assertThrows("asStatus", AcmeProtocolException.class, - () -> json.get("none").asStatus()); - assertThrows("asBinary", AcmeProtocolException.class, - () -> json.get("none").asBinary()); - assertThrows("asProblem", AcmeProtocolException.class, - () -> json.get("none").asProblem(BASE_URL)); - assertThrows("asInt", AcmeProtocolException.class, - () -> json.get("none").asInt()); - assertThrows("asBoolean", AcmeProtocolException.class, - () -> json.get("none").asBoolean()); + assertThrows(AcmeProtocolException.class, + () -> json.get("none").asString(), + "asString"); + assertThrows(AcmeProtocolException.class, + () -> json.get("none").asURI(), + "asURI"); + assertThrows(AcmeProtocolException.class, + () -> json.get("none").asURL(), + "asURL"); + assertThrows(AcmeProtocolException.class, + () -> json.get("none").asInstant(), + "asInstant"); + assertThrows(AcmeProtocolException.class, + () -> json.get("none").asDuration(), + "asDuration"); + assertThrows(AcmeProtocolException.class, + () -> json.get("none").asObject(), + "asObject"); + assertThrows(AcmeProtocolException.class, + () -> json.get("none").asEncodedObject(), + "asEncodedObject"); + assertThrows(AcmeProtocolException.class, + () -> json.get("none").asStatus(), + "asStatus"); + assertThrows(AcmeProtocolException.class, + () -> json.get("none").asBinary(), + "asBinary"); + assertThrows(AcmeProtocolException.class, + () -> json.get("none").asProblem(BASE_URL), + "asProblem"); + assertThrows(AcmeProtocolException.class, + () -> json.get("none").asInt(), + "asInt"); + assertThrows(AcmeProtocolException.class, + () -> json.get("none").asBoolean(), + "asBoolean"); } /** @@ -279,24 +292,33 @@ public class JSONTest { public void testWrongGetter() { JSON json = TestUtils.getJSON("datatypes"); - assertThrows("asObject", AcmeProtocolException.class, - () -> json.get("text").asObject()); - assertThrows("asEncodedObject", AcmeProtocolException.class, - () -> json.get("text").asEncodedObject()); - assertThrows("asArray", AcmeProtocolException.class, - () -> json.get("text").asArray()); - assertThrows("asInt", AcmeProtocolException.class, - () -> json.get("text").asInt()); - assertThrows("asURI", AcmeProtocolException.class, - () -> json.get("text").asURI()); - assertThrows("asURL", AcmeProtocolException.class, - () -> json.get("text").asURL()); - assertThrows("asInstant", AcmeProtocolException.class, - () -> json.get("text").asInstant()); - assertThrows("asDuration", AcmeProtocolException.class, - () -> json.get("text").asDuration()); - assertThrows("asProblem", AcmeProtocolException.class, - () -> json.get("text").asProblem(BASE_URL)); + assertThrows(AcmeProtocolException.class, + () -> json.get("text").asObject(), + "asObject"); + assertThrows(AcmeProtocolException.class, + () -> json.get("text").asEncodedObject(), + "asEncodedObject"); + assertThrows(AcmeProtocolException.class, + () -> json.get("text").asArray(), + "asArray"); + assertThrows(AcmeProtocolException.class, + () -> json.get("text").asInt(), + "asInt"); + assertThrows(AcmeProtocolException.class, + () -> json.get("text").asURI(), + "asURI"); + assertThrows(AcmeProtocolException.class, + () -> json.get("text").asURL(), + "asURL"); + assertThrows(AcmeProtocolException.class, + () -> json.get("text").asInstant(), + "asInstant"); + assertThrows(AcmeProtocolException.class, + () -> json.get("text").asDuration(), + "asDuration"); + assertThrows(AcmeProtocolException.class, + () -> json.get("text").asProblem(BASE_URL), + "asProblem"); } /** diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/toolbox/JoseUtilsTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/toolbox/JoseUtilsTest.java index 2a09ce50..74ac5289 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/toolbox/JoseUtilsTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/toolbox/JoseUtilsTest.java @@ -16,7 +16,7 @@ package org.shredzone.acme4j.toolbox; import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import static org.shredzone.acme4j.toolbox.TestUtils.url; import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs; @@ -33,7 +33,7 @@ import org.jose4j.jwk.PublicJsonWebKey; import org.jose4j.jws.JsonWebSignature; import org.jose4j.jwx.CompactSerializer; import org.jose4j.lang.JoseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit tests for {@link JoseUtils}. @@ -307,7 +307,7 @@ public class JoseUtilsTest { expectedPayload.append("}"); assertThat(decodedPayload, sameJSONAs(expectedPayload.toString())); } catch (JoseException ex) { - fail(ex.getMessage()); + fail(ex); } } diff --git a/acme4j-it/src/test/java/org/shredzone/acme4j/it/boulder/OrderHttpIT.java b/acme4j-it/src/test/java/org/shredzone/acme4j/it/boulder/OrderHttpIT.java index 0b44e763..633bb7ea 100644 --- a/acme4j-it/src/test/java/org/shredzone/acme4j/it/boulder/OrderHttpIT.java +++ b/acme4j-it/src/test/java/org/shredzone/acme4j/it/boulder/OrderHttpIT.java @@ -17,13 +17,12 @@ import static java.util.concurrent.TimeUnit.SECONDS; import static org.awaitility.Awaitility.await; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.fail; import java.net.URI; import java.security.KeyPair; import java.security.cert.X509Certificate; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.Account; import org.shredzone.acme4j.AccountBuilder; import org.shredzone.acme4j.Authorization; @@ -80,9 +79,7 @@ public class OrderHttpIT { .conditionEvaluationListener(cond -> updateAuth(auth)) .until(auth::getStatus, not(oneOf(Status.PENDING, Status.PROCESSING))); - if (auth.getStatus() != Status.VALID) { - fail("Authorization failed"); - } + assertThat(auth.getStatus(), is(Status.VALID)); client.httpRemoveToken(challenge.getToken()); } diff --git a/acme4j-it/src/test/java/org/shredzone/acme4j/it/pebble/AccountIT.java b/acme4j-it/src/test/java/org/shredzone/acme4j/it/pebble/AccountIT.java index 1c9f23fc..b9abaa82 100644 --- a/acme4j-it/src/test/java/org/shredzone/acme4j/it/pebble/AccountIT.java +++ b/acme4j-it/src/test/java/org/shredzone/acme4j/it/pebble/AccountIT.java @@ -16,14 +16,13 @@ package org.shredzone.acme4j.it.pebble; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.net.URI; import java.net.URL; import java.security.KeyPair; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.Account; import org.shredzone.acme4j.AccountBuilder; import org.shredzone.acme4j.Login; @@ -192,11 +191,11 @@ public class AccountIT extends PebbleITBase { KeyPair newKeyPair = createKeyPair(); acct.changeKey(newKeyPair); - assertThrows("Old account key is still accessible", AcmeServerException.class, () -> { + assertThrows(AcmeServerException.class, () -> { Session sessionOldKey = new Session(pebbleURI()); Account oldAccount = sessionOldKey.login(location, keyPair).getAccount(); oldAccount.update(); - }); + }, "Old account key is still accessible"); Session sessionNewKey = new Session(pebbleURI()); Account newAccount = sessionNewKey.login(location, newKeyPair).getAccount(); @@ -223,12 +222,12 @@ public class AccountIT extends PebbleITBase { assertThat(acct.getStatus(), is(Status.DEACTIVATED)); // Make sure account cannot be accessed any more... - AcmeUnauthorizedException ex = assertThrows("Account can still be accessed", - AcmeUnauthorizedException.class, () -> { + AcmeUnauthorizedException ex = assertThrows(AcmeUnauthorizedException.class, + () -> { Session session2 = new Session(pebbleURI()); Account acct2 = session2.login(location, keyPair).getAccount(); acct2.update(); - }); + }, "Account can still be accessed"); assertThat(ex.getMessage(), is("Account has been deactivated")); } diff --git a/acme4j-it/src/test/java/org/shredzone/acme4j/it/pebble/OrderIT.java b/acme4j-it/src/test/java/org/shredzone/acme4j/it/pebble/OrderIT.java index 93669f1e..2d057849 100644 --- a/acme4j-it/src/test/java/org/shredzone/acme4j/it/pebble/OrderIT.java +++ b/acme4j-it/src/test/java/org/shredzone/acme4j/it/pebble/OrderIT.java @@ -17,8 +17,7 @@ import static java.util.concurrent.TimeUnit.SECONDS; import static org.awaitility.Awaitility.await; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.net.URI; import java.security.KeyPair; @@ -27,7 +26,7 @@ import java.time.Duration; import java.time.Instant; import java.time.temporal.ChronoUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.Account; import org.shredzone.acme4j.AccountBuilder; import org.shredzone.acme4j.Authorization; @@ -43,7 +42,6 @@ import org.shredzone.acme4j.challenge.Http01Challenge; import org.shredzone.acme4j.challenge.TlsAlpn01Challenge; import org.shredzone.acme4j.exception.AcmeException; import org.shredzone.acme4j.exception.AcmeServerException; -import org.shredzone.acme4j.exception.AcmeUnauthorizedException; import org.shredzone.acme4j.it.BammBammClient; import org.shredzone.acme4j.util.CSRBuilder; @@ -186,9 +184,7 @@ public class OrderIT extends PebbleITBase { .conditionEvaluationListener(cond -> updateAuth(auth)) .until(auth::getStatus, not(oneOf(Status.PENDING, Status.PROCESSING))); - if (auth.getStatus() != Status.VALID) { - fail("Authorization failed"); - } + assertThat(auth.getStatus(), is(Status.VALID)); } CSRBuilder csr = new CSRBuilder(); @@ -204,9 +200,7 @@ public class OrderIT extends PebbleITBase { .conditionEvaluationListener(cond -> updateOrder(order)) .until(order::getStatus, not(oneOf(Status.PENDING, Status.PROCESSING, Status.READY))); - if (order.getStatus() != Status.VALID) { - fail("Order failed"); - } + assertThat(order.getStatus(), is(Status.VALID)); Certificate certificate = order.getCertificate(); X509Certificate cert = certificate.getCertificate(); @@ -224,16 +218,17 @@ public class OrderIT extends PebbleITBase { revoker.revoke(session, certificate, keyPair, domainKeyPair); // Make sure certificate is revoked - AcmeException ex = assertThrows("Could download revoked cert", AcmeException.class, () -> { + AcmeException ex = assertThrows(AcmeException.class, () -> { Login login2 = session.login(account.getLocation(), keyPair); Certificate cert2 = login2.bindCertificate(certificate.getLocation()); cert2.download(); - }); + }, "Could download revoked cert"); assertThat(ex.getMessage(), is("HTTP 404: Not Found")); // Try to revoke again - AcmeServerException ex2 = assertThrows("Could revoke again", AcmeServerException.class, - () -> certificate.revoke()); + AcmeServerException ex2 = assertThrows(AcmeServerException.class, + () -> certificate.revoke(), + "Could revoke again"); assertThat(ex2.getProblem().getType(), is(URI.create("urn:ietf:params:acme:error:alreadyRevoked"))); } diff --git a/acme4j-it/src/test/java/org/shredzone/acme4j/it/pebble/OrderWildcardIT.java b/acme4j-it/src/test/java/org/shredzone/acme4j/it/pebble/OrderWildcardIT.java index 43733393..abd6c8d8 100644 --- a/acme4j-it/src/test/java/org/shredzone/acme4j/it/pebble/OrderWildcardIT.java +++ b/acme4j-it/src/test/java/org/shredzone/acme4j/it/pebble/OrderWildcardIT.java @@ -18,7 +18,6 @@ import static java.util.stream.Collectors.toList; import static org.awaitility.Awaitility.await; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.fail; import java.security.KeyPair; import java.security.cert.X509Certificate; @@ -28,7 +27,7 @@ import java.time.temporal.ChronoUnit; import java.util.List; import org.bouncycastle.asn1.x509.GeneralName; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.Account; import org.shredzone.acme4j.AccountBuilder; import org.shredzone.acme4j.Authorization; @@ -102,9 +101,7 @@ public class OrderWildcardIT extends PebbleITBase { .conditionEvaluationListener(cond -> updateAuth(auth)) .until(auth::getStatus, not(oneOf(Status.PENDING, Status.PROCESSING))); - if (auth.getStatus() != Status.VALID) { - fail("Authorization failed"); - } + assertThat(auth.getStatus(), is(Status.VALID)); } CSRBuilder csr = new CSRBuilder(); diff --git a/acme4j-it/src/test/java/org/shredzone/acme4j/it/pebble/PebbleITBase.java b/acme4j-it/src/test/java/org/shredzone/acme4j/it/pebble/PebbleITBase.java index 30f99888..0da8a17b 100644 --- a/acme4j-it/src/test/java/org/shredzone/acme4j/it/pebble/PebbleITBase.java +++ b/acme4j-it/src/test/java/org/shredzone/acme4j/it/pebble/PebbleITBase.java @@ -22,7 +22,7 @@ import java.security.KeyPair; import java.util.ArrayList; import java.util.List; -import org.junit.After; +import org.junit.jupiter.api.AfterEach; import org.shredzone.acme4j.Authorization; import org.shredzone.acme4j.Order; import org.shredzone.acme4j.exception.AcmeException; @@ -51,7 +51,7 @@ public abstract class PebbleITBase { private final List cleanup = new ArrayList<>(); - @After + @AfterEach public void performCleanup() throws Exception { for (CleanupCallback callback : cleanup) { callback.cleanup(); diff --git a/acme4j-it/src/test/java/org/shredzone/acme4j/it/pebble/SessionIT.java b/acme4j-it/src/test/java/org/shredzone/acme4j/it/pebble/SessionIT.java index 1baef4dd..e67c8304 100644 --- a/acme4j-it/src/test/java/org/shredzone/acme4j/it/pebble/SessionIT.java +++ b/acme4j-it/src/test/java/org/shredzone/acme4j/it/pebble/SessionIT.java @@ -19,7 +19,7 @@ import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs; import java.net.URI; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.Metadata; import org.shredzone.acme4j.Session; import org.shredzone.acme4j.connector.Resource; diff --git a/acme4j-smime/src/main/java/org/shredzone/acme4j/smime/email/ResponseBodyGenerator.java b/acme4j-smime/src/main/java/org/shredzone/acme4j/smime/email/ResponseBodyGenerator.java index 414f8082..d86c9f68 100644 --- a/acme4j-smime/src/main/java/org/shredzone/acme4j/smime/email/ResponseBodyGenerator.java +++ b/acme4j-smime/src/main/java/org/shredzone/acme4j/smime/email/ResponseBodyGenerator.java @@ -40,7 +40,7 @@ public interface ResponseBodyGenerator { /** * The content-type of the response body: {@value #RESPONSE_BODY_TYPE} */ - public static final String RESPONSE_BODY_TYPE = "text/plain"; + String RESPONSE_BODY_TYPE = "text/plain"; /** * Sets the content of the {@link Message}. diff --git a/acme4j-smime/src/test/java/org/shredzone/acme4j/smime/EmailIdentifierTest.java b/acme4j-smime/src/test/java/org/shredzone/acme4j/smime/EmailIdentifierTest.java index b71e46e0..0257e1b2 100644 --- a/acme4j-smime/src/test/java/org/shredzone/acme4j/smime/EmailIdentifierTest.java +++ b/acme4j-smime/src/test/java/org/shredzone/acme4j/smime/EmailIdentifierTest.java @@ -18,7 +18,7 @@ import static org.hamcrest.Matchers.is; import jakarta.mail.internet.AddressException; import jakarta.mail.internet.InternetAddress; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests of {@link EmailIdentifier}. diff --git a/acme4j-smime/src/test/java/org/shredzone/acme4j/smime/challenge/EmailReply00ChallengeTest.java b/acme4j-smime/src/test/java/org/shredzone/acme4j/smime/challenge/EmailReply00ChallengeTest.java index 3997af12..5e93d656 100644 --- a/acme4j-smime/src/test/java/org/shredzone/acme4j/smime/challenge/EmailReply00ChallengeTest.java +++ b/acme4j-smime/src/test/java/org/shredzone/acme4j/smime/challenge/EmailReply00ChallengeTest.java @@ -15,11 +15,12 @@ package org.shredzone.acme4j.smime.challenge; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.net.URI; import java.net.URL; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.Status; import org.shredzone.acme4j.challenge.Challenge; import org.shredzone.acme4j.provider.AbstractAcmeProvider; @@ -63,10 +64,12 @@ public class EmailReply00ChallengeTest extends SMIMETests { /** * Test that {@link EmailReply00Challenge#getAuthorization()} is not implemented. */ - @Test(expected = UnsupportedOperationException.class) + @Test public void testInvalidGetAuthorization() { - EmailReply00Challenge challenge = new EmailReply00Challenge(mockLogin(), getJSON("emailReplyChallenge")); - challenge.getAuthorization(); + assertThrows(UnsupportedOperationException.class, () -> { + EmailReply00Challenge challenge = new EmailReply00Challenge(mockLogin(), getJSON("emailReplyChallenge")); + challenge.getAuthorization(); + }); } /** diff --git a/acme4j-smime/src/test/java/org/shredzone/acme4j/smime/csr/SMIMECSRBuilderTest.java b/acme4j-smime/src/test/java/org/shredzone/acme4j/smime/csr/SMIMECSRBuilderTest.java index dbeeae52..767a09ad 100644 --- a/acme4j-smime/src/test/java/org/shredzone/acme4j/smime/csr/SMIMECSRBuilderTest.java +++ b/acme4j-smime/src/test/java/org/shredzone/acme4j/smime/csr/SMIMECSRBuilderTest.java @@ -16,7 +16,7 @@ package org.shredzone.acme4j.smime.csr; import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -47,9 +47,8 @@ import org.bouncycastle.pkcs.PKCS10CertificationRequest; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Matchers; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.util.KeyPairUtils; /** @@ -60,7 +59,7 @@ public class SMIMECSRBuilderTest { private static KeyPair testKey; private static KeyPair testEcKey; - @BeforeClass + @BeforeAll public static void setup() { Security.addProvider(new BouncyCastleProvider()); @@ -241,10 +240,12 @@ public class SMIMECSRBuilderTest { /** * Make sure an exception is thrown when nothing is set. */ - @Test(expected = IllegalStateException.class) + @Test public void testNoEmail() throws IOException { - SMIMECSRBuilder builder = new SMIMECSRBuilder(); - builder.sign(testKey); + assertThrows(IllegalStateException.class, () -> { + SMIMECSRBuilder builder = new SMIMECSRBuilder(); + builder.sign(testKey); + }); } /** @@ -254,13 +255,13 @@ public class SMIMECSRBuilderTest { public void testNoSign() throws IOException { SMIMECSRBuilder builder = new SMIMECSRBuilder(); - assertThrows("getCSR", IllegalStateException.class, builder::getCSR); - assertThrows("getEncoded", IllegalStateException.class, builder::getEncoded); - assertThrows("write", IllegalStateException.class,() -> { + assertThrows(IllegalStateException.class, builder::getCSR, "getCSR"); + assertThrows(IllegalStateException.class, builder::getEncoded, "getEncoded"); + assertThrows(IllegalStateException.class, () -> { try (StringWriter w = new StringWriter()) { builder.write(w); } - }); + },"write"); } /** diff --git a/acme4j-smime/src/test/java/org/shredzone/acme4j/smime/email/EmailProcessorTest.java b/acme4j-smime/src/test/java/org/shredzone/acme4j/smime/email/EmailProcessorTest.java index 37cd5d59..698fbcfe 100644 --- a/acme4j-smime/src/test/java/org/shredzone/acme4j/smime/email/EmailProcessorTest.java +++ b/acme4j-smime/src/test/java/org/shredzone/acme4j/smime/email/EmailProcessorTest.java @@ -16,6 +16,7 @@ package org.shredzone.acme4j.smime.email; import static jakarta.mail.Message.RecipientType.TO; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; import java.util.Optional; @@ -23,7 +24,7 @@ import java.util.Optional; import jakarta.mail.Message; import jakarta.mail.MessagingException; import jakarta.mail.internet.InternetAddress; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.Identifier; import org.shredzone.acme4j.exception.AcmeProtocolException; import org.shredzone.acme4j.smime.EmailIdentifier; @@ -35,10 +36,10 @@ import org.shredzone.acme4j.smime.challenge.EmailReply00Challenge; */ public class EmailProcessorTest extends SMIMETests { - private InternetAddress expectedFrom = email("acme-generator@example.org"); - private InternetAddress expectedTo = email("alexey@example.com"); - private InternetAddress expectedReplyTo = email("acme-validator@example.org"); - private Message message = mockMessage("challenge"); + private final InternetAddress expectedFrom = email("acme-generator@example.org"); + private final InternetAddress expectedTo = email("alexey@example.com"); + private final InternetAddress expectedReplyTo = email("acme-validator@example.org"); + private final Message message = mockMessage("challenge"); @Test public void testEmailParser() throws MessagingException { @@ -55,46 +56,60 @@ public class EmailProcessorTest extends SMIMETests { assertThat(processor.getReplyTo(), contains(email("acme-validator@example.org"))); } - @Test(expected = AcmeProtocolException.class) + @Test public void textExpectedFromFails() { - EmailProcessor processor = new EmailProcessor(message); - processor.expectedFrom(expectedTo); + assertThrows(AcmeProtocolException.class, () -> { + EmailProcessor processor = new EmailProcessor(message); + processor.expectedFrom(expectedTo); + }); } - @Test(expected = AcmeProtocolException.class) + @Test public void textExpectedToFails() { - EmailProcessor processor = new EmailProcessor(message); - processor.expectedTo(expectedFrom); + assertThrows(AcmeProtocolException.class, () -> { + EmailProcessor processor = new EmailProcessor(message); + processor.expectedTo(expectedFrom); + }); } - @Test(expected = AcmeProtocolException.class) + @Test public void textExpectedIdentifierFails1() { - EmailProcessor processor = new EmailProcessor(message); - processor.expectedIdentifier(EmailIdentifier.email(expectedFrom)); + assertThrows(AcmeProtocolException.class, () -> { + EmailProcessor processor = new EmailProcessor(message); + processor.expectedIdentifier(EmailIdentifier.email(expectedFrom)); + }); } - @Test(expected = AcmeProtocolException.class) + @Test public void textExpectedIdentifierFails2() { - EmailProcessor processor = new EmailProcessor(message); - processor.expectedIdentifier(Identifier.ip("192.168.0.1")); + assertThrows(AcmeProtocolException.class, () -> { + EmailProcessor processor = new EmailProcessor(message); + processor.expectedIdentifier(Identifier.ip("192.168.0.1")); + }); } - @Test(expected = IllegalStateException.class) + @Test public void textNoChallengeFails1() { - EmailProcessor processor = new EmailProcessor(message); - processor.getToken(); + assertThrows(IllegalStateException.class, () -> { + EmailProcessor processor = new EmailProcessor(message); + processor.getToken(); + }); } - @Test(expected = IllegalStateException.class) + @Test public void textNoChallengeFails2() { - EmailProcessor processor = new EmailProcessor(message); - processor.getAuthorization(); + assertThrows(IllegalStateException.class, () -> { + EmailProcessor processor = new EmailProcessor(message); + processor.getAuthorization(); + }); } - @Test(expected = IllegalStateException.class) + @Test public void textNoChallengeFails3() { - EmailProcessor processor = new EmailProcessor(message); - processor.respond(); + assertThrows(IllegalStateException.class, () -> { + EmailProcessor processor = new EmailProcessor(message); + processor.respond(); + }); } @Test @@ -108,11 +123,13 @@ public class EmailProcessorTest extends SMIMETests { assertThat(processor.respond(), is(notNullValue())); } - @Test(expected = AcmeProtocolException.class) + @Test public void testChallengeMismatch() { - EmailReply00Challenge challenge = mockChallenge("emailReplyChallengeMismatch"); - EmailProcessor processor = new EmailProcessor(message); - processor.withChallenge(challenge); + assertThrows(AcmeProtocolException.class, () -> { + EmailReply00Challenge challenge = mockChallenge("emailReplyChallengeMismatch"); + EmailProcessor processor = new EmailProcessor(message); + processor.withChallenge(challenge); + }); } @Test diff --git a/acme4j-utils/src/test/java/org/shredzone/acme4j/util/CSRBuilderTest.java b/acme4j-utils/src/test/java/org/shredzone/acme4j/util/CSRBuilderTest.java index df548843..afb5ab50 100644 --- a/acme4j-utils/src/test/java/org/shredzone/acme4j/util/CSRBuilderTest.java +++ b/acme4j-utils/src/test/java/org/shredzone/acme4j/util/CSRBuilderTest.java @@ -15,8 +15,7 @@ package org.shredzone.acme4j.util; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -24,6 +23,7 @@ import java.io.StringReader; import java.io.StringWriter; import java.net.InetAddress; import java.net.UnknownHostException; +import java.nio.charset.StandardCharsets; import java.security.KeyPair; import java.security.Security; import java.util.Arrays; @@ -45,8 +45,8 @@ import org.bouncycastle.openssl.PEMParser; import org.bouncycastle.pkcs.PKCS10CertificationRequest; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.Identifier; /** @@ -57,7 +57,7 @@ public class CSRBuilderTest { private static KeyPair testKey; private static KeyPair testEcKey; - @BeforeClass + @BeforeAll public static void setup() { Security.addProvider(new BouncyCastleProvider()); @@ -230,25 +230,29 @@ public class CSRBuilderTest { builder.write(baos); pemBytes = baos.toByteArray(); } - assertThat(new String(pemBytes, "utf-8"), is(equalTo(pem))); + assertThat(new String(pemBytes, StandardCharsets.UTF_8), is(equalTo(pem))); } /** * Make sure an exception is thrown when no domain is set. */ - @Test(expected = IllegalStateException.class) + @Test public void testNoDomain() throws IOException { - CSRBuilder builder = new CSRBuilder(); - builder.sign(testKey); + assertThrows(IllegalStateException.class, () -> { + CSRBuilder builder = new CSRBuilder(); + builder.sign(testKey); + }); } /** * Make sure an exception is thrown when an unknown identifier type is used. */ - @Test(expected = IllegalArgumentException.class) + @Test public void testUnknownType() { - CSRBuilder builder = new CSRBuilder(); - builder.addIdentifier(new Identifier("UnKnOwN", "123")); + assertThrows(IllegalArgumentException.class, () -> { + CSRBuilder builder = new CSRBuilder(); + builder.addIdentifier(new Identifier("UnKnOwN", "123")); + }); } /** @@ -258,13 +262,13 @@ public class CSRBuilderTest { public void testNoSign() throws IOException { CSRBuilder builder = new CSRBuilder(); - assertThrows("getCSR()", IllegalStateException.class, builder::getCSR); - assertThrows("getEncoded()", IllegalStateException.class, builder::getEncoded); - assertThrows("write()", IllegalStateException.class, () -> { + assertThrows(IllegalStateException.class, builder::getCSR, "getCSR()"); + assertThrows(IllegalStateException.class, builder::getEncoded, "getEncoded()"); + assertThrows(IllegalStateException.class, () -> { try (StringWriter w = new StringWriter()) { builder.write(w); - }; - }); + } + }, "write()"); } /** diff --git a/acme4j-utils/src/test/java/org/shredzone/acme4j/util/CertificateUtilsTest.java b/acme4j-utils/src/test/java/org/shredzone/acme4j/util/CertificateUtilsTest.java index 095cbf9b..a26e5998 100644 --- a/acme4j-utils/src/test/java/org/shredzone/acme4j/util/CertificateUtilsTest.java +++ b/acme4j-utils/src/test/java/org/shredzone/acme4j/util/CertificateUtilsTest.java @@ -42,7 +42,7 @@ import org.bouncycastle.asn1.BERTags; import org.bouncycastle.asn1.DEROctetString; import org.bouncycastle.asn1.x509.GeneralName; import org.bouncycastle.pkcs.PKCS10CertificationRequest; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.shredzone.acme4j.Identifier; import org.shredzone.acme4j.challenge.TlsAlpn01Challenge; import org.shredzone.acme4j.toolbox.AcmeUtils; diff --git a/acme4j-utils/src/test/java/org/shredzone/acme4j/util/KeyPairUtilsTest.java b/acme4j-utils/src/test/java/org/shredzone/acme4j/util/KeyPairUtilsTest.java index ff14b144..b54be903 100644 --- a/acme4j-utils/src/test/java/org/shredzone/acme4j/util/KeyPairUtilsTest.java +++ b/acme4j-utils/src/test/java/org/shredzone/acme4j/util/KeyPairUtilsTest.java @@ -27,8 +27,8 @@ import java.security.interfaces.ECPublicKey; import java.security.interfaces.RSAPublicKey; import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; /** * Unit tests for {@link KeyPairUtils}. @@ -37,7 +37,7 @@ public class KeyPairUtilsTest { private static final int KEY_SIZE = 2048; private static final String EC_CURVE = "secp256r1"; - @BeforeClass + @BeforeAll public static void setup() { Security.addProvider(new BouncyCastleProvider()); } diff --git a/pom.xml b/pom.xml index fb110c32..4dc136f7 100644 --- a/pom.xml +++ b/pom.xml @@ -119,7 +119,7 @@ classes 10 - java.net.HttpURLConnection + requires-network @@ -203,9 +203,9 @@ - junit - junit - 4.13.2 + org.junit.jupiter + junit-jupiter-api + 5.8.2 test