Upgrade all tests to JUnit 5

pull/129/head
Richard Körber 2022-05-14 12:24:21 +02:00
parent edf2018433
commit f3c7e8a46c
No known key found for this signature in database
GPG Key ID: AAB9FD19C78AA3E0
57 changed files with 435 additions and 416 deletions

View File

@ -189,7 +189,7 @@ public class DefaultConnection implements Connection {
} }
JSON result = JSON.parse(in); JSON result = JSON.parse(in);
LOG.debug("Result JSON: {}", result.toString()); LOG.debug("Result JSON: {}", result);
return result; return result;
} catch (IOException ex) { } catch (IOException ex) {
throw new AcmeNetworkException(ex); throw new AcmeNetworkException(ex);

View File

@ -67,7 +67,7 @@ public class AcmeUserActionRequiredException extends AcmeServerException {
try { try {
return instance.toURL(); return instance.toURL();
} catch (MalformedURLException ex) { } catch (MalformedURLException ex) {
throw new AcmeProtocolException("Bad instance URL: " + instance.toString(), ex); throw new AcmeProtocolException("Bad instance URL: " + instance, ex);
} }
} }

View File

@ -26,7 +26,7 @@ import java.security.KeyPair;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
import org.jose4j.jwx.CompactSerializer; import org.jose4j.jwx.CompactSerializer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.shredzone.acme4j.connector.Resource; import org.shredzone.acme4j.connector.Resource;
import org.shredzone.acme4j.provider.TestableConnectionProvider; import org.shredzone.acme4j.provider.TestableConnectionProvider;

View File

@ -17,7 +17,8 @@ import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; 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.getJSON;
import static org.shredzone.acme4j.toolbox.TestUtils.url; import static org.shredzone.acme4j.toolbox.TestUtils.url;
import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs; 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.jws.JsonWebSignature;
import org.jose4j.jwx.CompactSerializer; import org.jose4j.jwx.CompactSerializer;
import org.jose4j.lang.JoseException; 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.Account.EditableAccount;
import org.shredzone.acme4j.challenge.Dns01Challenge; import org.shredzone.acme4j.challenge.Dns01Challenge;
import org.shredzone.acme4j.challenge.Http01Challenge; import org.shredzone.acme4j.challenge.Http01Challenge;
@ -255,13 +256,11 @@ public class AccountTest {
Account account = new Account(login); Account account = new Account(login);
try { AcmeServerException ex = assertThrows(AcmeServerException.class, () ->
account.preAuthorizeDomain("example.org"); account.preAuthorizeDomain("example.org")
fail("preauthorization was accepted"); );
} catch (AcmeServerException ex) {
assertThat(ex.getType(), is(problemType)); assertThat(ex.getType(), is(problemType));
assertThat(ex.getMessage(), is(problemDetail)); assertThat(ex.getMessage(), is(problemDetail));
}
provider.close(); provider.close();
} }
@ -278,27 +277,9 @@ public class AccountTest {
Login login = provider.createLogin(); Login login = provider.createLogin();
Account account = login.getAccount(); Account account = login.getAccount();
try { assertThrows(NullPointerException.class, () -> account.preAuthorizeDomain(null));
account.preAuthorizeDomain(null); assertThrows(IllegalArgumentException.class, () -> account.preAuthorizeDomain(""));
fail("null domain was accepted"); assertThrows(AcmeException.class, () -> account.preAuthorizeDomain("example.com"));
} 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"));
}
provider.close(); provider.close();
} }
@ -342,7 +323,7 @@ public class AccountTest {
expectedPayload.append("}}"); expectedPayload.append("}}");
assertThat(decodedPayload, sameJSONAs(expectedPayload.toString())); assertThat(decodedPayload, sameJSONAs(expectedPayload.toString()));
} catch (JoseException ex) { } catch (JoseException ex) {
fail("decoding inner payload failed"); fail(ex);
} }
return HttpURLConnection.HTTP_OK; return HttpURLConnection.HTTP_OK;
@ -370,8 +351,9 @@ public class AccountTest {
/** /**
* Test that the same account key is not accepted for change. * Test that the same account key is not accepted for change.
*/ */
@Test(expected = IllegalArgumentException.class) @Test
public void testChangeSameKey() throws Exception { public void testChangeSameKey() throws Exception {
assertThrows(IllegalArgumentException.class, () -> {
TestableConnectionProvider provider = new TestableConnectionProvider(); TestableConnectionProvider provider = new TestableConnectionProvider();
Login login = provider.createLogin(); Login login = provider.createLogin();
@ -379,6 +361,7 @@ public class AccountTest {
account.changeKey(login.getKeyPair()); account.changeKey(login.getKeyPair());
provider.close(); provider.close();
});
} }
/** /**

View File

@ -20,7 +20,7 @@ import static org.shredzone.acme4j.toolbox.TestUtils.url;
import java.net.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.exception.AcmeException;
import org.shredzone.acme4j.toolbox.JSON; import org.shredzone.acme4j.toolbox.JSON;
import org.shredzone.acme4j.toolbox.TestUtils; import org.shredzone.acme4j.toolbox.TestUtils;

View File

@ -15,8 +15,7 @@ package org.shredzone.acme4j;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -25,7 +24,7 @@ import java.io.ObjectOutputStream;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.toolbox.TestUtils; import org.shredzone.acme4j.toolbox.TestUtils;
/** /**
@ -97,8 +96,9 @@ public class AcmeResourceTest {
/** /**
* Test if a rebind attempt fails. * Test if a rebind attempt fails.
*/ */
@Test(expected = IllegalStateException.class) @Test
public void testRebind() throws Exception { public void testRebind() throws Exception {
assertThrows(IllegalStateException.class, () -> {
Login login = TestUtils.login(); Login login = TestUtils.login();
URL location = new URL("http://example.com/acme/resource"); URL location = new URL("http://example.com/acme/resource");
@ -107,6 +107,7 @@ public class AcmeResourceTest {
Login login2 = TestUtils.login(); Login login2 = TestUtils.login();
resource.rebind(login2); // fails to rebind to another login resource.rebind(login2); // fails to rebind to another login
});
} }
/** /**

View File

@ -15,8 +15,7 @@ package org.shredzone.acme4j;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.fail;
import static org.shredzone.acme4j.toolbox.AcmeUtils.parseTimestamp; import static org.shredzone.acme4j.toolbox.AcmeUtils.parseTimestamp;
import static org.shredzone.acme4j.toolbox.TestUtils.getJSON; import static org.shredzone.acme4j.toolbox.TestUtils.getJSON;
import static org.shredzone.acme4j.toolbox.TestUtils.url; import static org.shredzone.acme4j.toolbox.TestUtils.url;
@ -28,7 +27,7 @@ import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.concurrent.atomic.AtomicBoolean; 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.Challenge;
import org.shredzone.acme4j.challenge.Dns01Challenge; import org.shredzone.acme4j.challenge.Dns01Challenge;
import org.shredzone.acme4j.challenge.Http01Challenge; import org.shredzone.acme4j.challenge.Http01Challenge;
@ -105,10 +104,12 @@ public class AuthorizationTest {
* Test that {@link Authorization#findChallenge(String)} fails on duplicate * Test that {@link Authorization#findChallenge(String)} fails on duplicate
* challenges. * challenges.
*/ */
@Test(expected = AcmeProtocolException.class) @Test
public void testFailDuplicateChallenges() throws IOException { public void testFailDuplicateChallenges() throws IOException {
assertThrows(AcmeProtocolException.class, () -> {
Authorization authorization = createChallengeAuthorization(); Authorization authorization = createChallengeAuthorization();
authorization.findChallenge(DUPLICATE_TYPE); authorization.findChallenge(DUPLICATE_TYPE);
});
} }
/** /**

View File

@ -33,7 +33,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.connector.Resource; import org.shredzone.acme4j.connector.Resource;
import org.shredzone.acme4j.exception.AcmeException; import org.shredzone.acme4j.exception.AcmeException;
import org.shredzone.acme4j.provider.TestableConnectionProvider; import org.shredzone.acme4j.provider.TestableConnectionProvider;

View File

@ -15,14 +15,13 @@ package org.shredzone.acme4j;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.fail;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.Map; import java.util.Map;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.exception.AcmeProtocolException; import org.shredzone.acme4j.exception.AcmeProtocolException;
import org.shredzone.acme4j.toolbox.JSONBuilder; import org.shredzone.acme4j.toolbox.JSONBuilder;
@ -74,9 +73,11 @@ public class IdentifierTest {
assertThat(id2.getDomain(), is("xn--xml-qla7ae5k.com")); assertThat(id2.getDomain(), is("xn--xml-qla7ae5k.com"));
} }
@Test(expected = AcmeProtocolException.class) @Test
public void testNoDns() { public void testNoDns() {
new Identifier("foo", "example.com").getDomain(); assertThrows(AcmeProtocolException.class, () ->
new Identifier("foo", "example.com").getDomain()
);
} }
@Test @Test
@ -97,9 +98,11 @@ public class IdentifierTest {
assertThat(id3.getIP().getHostAddress(), is("192.168.2.99")); assertThat(id3.getIP().getHostAddress(), is("192.168.2.99"));
} }
@Test(expected = AcmeProtocolException.class) @Test
public void testNoIp() { public void testNoIp() {
new Identifier("foo", "example.com").getIP(); assertThrows(AcmeProtocolException.class, () ->
new Identifier("foo", "example.com").getIP()
);
} }
@Test @Test

View File

@ -15,8 +15,7 @@ package org.shredzone.acme4j;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import static org.shredzone.acme4j.toolbox.TestUtils.getJSON; import static org.shredzone.acme4j.toolbox.TestUtils.getJSON;
import static org.shredzone.acme4j.toolbox.TestUtils.url; import static org.shredzone.acme4j.toolbox.TestUtils.url;
@ -26,7 +25,7 @@ import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.security.KeyPair; import java.security.KeyPair;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers; import org.mockito.ArgumentMatchers;
import org.shredzone.acme4j.challenge.Challenge; import org.shredzone.acme4j.challenge.Challenge;
import org.shredzone.acme4j.challenge.Dns01Challenge; import org.shredzone.acme4j.challenge.Dns01Challenge;

View File

@ -15,8 +15,7 @@ package org.shredzone.acme4j;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.fail;
import static org.shredzone.acme4j.toolbox.AcmeUtils.parseTimestamp; import static org.shredzone.acme4j.toolbox.AcmeUtils.parseTimestamp;
import static org.shredzone.acme4j.toolbox.TestUtils.getJSON; import static org.shredzone.acme4j.toolbox.TestUtils.getJSON;
import static org.shredzone.acme4j.toolbox.TestUtils.url; import static org.shredzone.acme4j.toolbox.TestUtils.url;
@ -29,9 +28,10 @@ import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.Arrays; import java.util.Arrays;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.connector.Resource; import org.shredzone.acme4j.connector.Resource;
import org.shredzone.acme4j.exception.AcmeException; import org.shredzone.acme4j.exception.AcmeException;
import org.shredzone.acme4j.exception.AcmeProtocolException;
import org.shredzone.acme4j.provider.TestableConnectionProvider; import org.shredzone.acme4j.provider.TestableConnectionProvider;
import org.shredzone.acme4j.toolbox.JSON; import org.shredzone.acme4j.toolbox.JSON;
import org.shredzone.acme4j.toolbox.JSONBuilder; import org.shredzone.acme4j.toolbox.JSONBuilder;
@ -179,8 +179,9 @@ public class OrderBuilderTest {
/** /**
* Test that an auto-renewal {@link Order} cannot be created if unsupported by the CA. * 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 { public void testAutoRenewOrderCertificateFails() throws Exception {
assertThrows(AcmeException.class, () -> {
TestableConnectionProvider provider = new TestableConnectionProvider(); TestableConnectionProvider provider = new TestableConnectionProvider();
provider.putTestResource(Resource.NEW_ORDER, resourceUrl); provider.putTestResource(Resource.NEW_ORDER, resourceUrl);
@ -193,6 +194,7 @@ public class OrderBuilderTest {
.create(); .create();
provider.close(); provider.close();
});
} }
/** /**
@ -207,35 +209,35 @@ public class OrderBuilderTest {
Account account = new Account(login); Account account = new Account(login);
assertThrows("accepted notBefore", IllegalArgumentException.class, () -> { assertThrows(IllegalArgumentException.class, () -> {
OrderBuilder ob = account.newOrder().autoRenewal(); OrderBuilder ob = account.newOrder().autoRenewal();
ob.notBefore(someInstant); ob.notBefore(someInstant);
}); }, "accepted notBefore");
assertThrows("accepted notAfter", IllegalArgumentException.class, () -> { assertThrows(IllegalArgumentException.class, () -> {
OrderBuilder ob = account.newOrder().autoRenewal(); OrderBuilder ob = account.newOrder().autoRenewal();
ob.notAfter(someInstant); ob.notAfter(someInstant);
}); }, "accepted notAfter");
assertThrows("accepted autoRenewal", IllegalArgumentException.class, () -> { assertThrows(IllegalArgumentException.class, () -> {
OrderBuilder ob = account.newOrder().notBefore(someInstant); OrderBuilder ob = account.newOrder().notBefore(someInstant);
ob.autoRenewal(); ob.autoRenewal();
}); }, "accepted autoRenewal");
assertThrows("accepted autoRenewalStart", IllegalArgumentException.class, () -> { assertThrows(IllegalArgumentException.class, () -> {
OrderBuilder ob = account.newOrder().notBefore(someInstant); OrderBuilder ob = account.newOrder().notBefore(someInstant);
ob.autoRenewalStart(someInstant); ob.autoRenewalStart(someInstant);
}); }, "accepted autoRenewalStart");
assertThrows("accepted autoRenewalEnd", IllegalArgumentException.class, () -> { assertThrows(IllegalArgumentException.class, () -> {
OrderBuilder ob = account.newOrder().notBefore(someInstant); OrderBuilder ob = account.newOrder().notBefore(someInstant);
ob.autoRenewalEnd(someInstant); ob.autoRenewalEnd(someInstant);
}); }, "accepted autoRenewalEnd");
assertThrows("accepted autoRenewalLifetime", IllegalArgumentException.class, () -> { assertThrows(IllegalArgumentException.class, () -> {
OrderBuilder ob = account.newOrder().notBefore(someInstant); OrderBuilder ob = account.newOrder().notBefore(someInstant);
ob.autoRenewalLifetime(Duration.ofDays(7)); ob.autoRenewalLifetime(Duration.ofDays(7));
}); }, "accepted autoRenewalLifetime");
provider.close(); provider.close();
} }

View File

@ -27,7 +27,7 @@ import java.time.Duration;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean; 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.provider.TestableConnectionProvider;
import org.shredzone.acme4j.toolbox.JSON; import org.shredzone.acme4j.toolbox.JSON;
import org.shredzone.acme4j.toolbox.JSONBuilder; import org.shredzone.acme4j.toolbox.JSONBuilder;

View File

@ -23,7 +23,7 @@ import java.net.URI;
import java.net.URL; import java.net.URL;
import java.util.List; 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.JSON;
import org.shredzone.acme4j.toolbox.JSONBuilder; import org.shredzone.acme4j.toolbox.JSONBuilder;
import org.shredzone.acme4j.toolbox.TestUtils; import org.shredzone.acme4j.toolbox.TestUtils;

View File

@ -15,8 +15,7 @@ package org.shredzone.acme4j;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import static org.shredzone.acme4j.toolbox.TestUtils.*; import static org.shredzone.acme4j.toolbox.TestUtils.*;
@ -27,7 +26,7 @@ import java.security.KeyPair;
import java.time.Duration; import java.time.Duration;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers; import org.mockito.ArgumentMatchers;
import org.shredzone.acme4j.connector.Resource; import org.shredzone.acme4j.connector.Resource;
import org.shredzone.acme4j.exception.AcmeException; import org.shredzone.acme4j.exception.AcmeException;
@ -61,10 +60,12 @@ public class SessionTest {
assertThat(session3, not(nullValue())); assertThat(session3, not(nullValue()));
assertThat(session3.getServerUri(), is(serverUri)); assertThat(session3.getServerUri(), is(serverUri));
assertThrows("Bad URI in constructor", IllegalArgumentException.class, assertThrows(IllegalArgumentException.class,
() -> new Session("#*aBaDuRi*#")); () -> new Session("#*aBaDuRi*#"),
assertThrows("Unsupported URI", IllegalArgumentException.class, "Bad URI in constructor");
() -> new Session(URI.create("acme://invalid"), new GenericAcmeProvider())); assertThrows(IllegalArgumentException.class,
() -> new Session(URI.create("acme://invalid"), new GenericAcmeProvider()),
"Unsupported URI");
} }
/** /**

View File

@ -16,8 +16,7 @@ package org.shredzone.acme4j;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.Parameterized;
/** /**
* Unit tests for {@link Status} enumeration. * Unit tests for {@link Status} enumeration.

View File

@ -16,8 +16,7 @@ package org.shredzone.acme4j.challenge;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.fail;
import static org.shredzone.acme4j.toolbox.AcmeUtils.parseTimestamp; import static org.shredzone.acme4j.toolbox.AcmeUtils.parseTimestamp;
import static org.shredzone.acme4j.toolbox.TestUtils.getJSON; import static org.shredzone.acme4j.toolbox.TestUtils.getJSON;
import static org.shredzone.acme4j.toolbox.TestUtils.url; import static org.shredzone.acme4j.toolbox.TestUtils.url;
@ -29,7 +28,7 @@ import java.net.URL;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.Login; import org.shredzone.acme4j.Login;
import org.shredzone.acme4j.Problem; import org.shredzone.acme4j.Problem;
import org.shredzone.acme4j.Status; import org.shredzone.acme4j.Status;
@ -85,9 +84,11 @@ public class ChallengeTest {
/** /**
* Test that an exception is thrown on challenge type mismatch. * Test that an exception is thrown on challenge type mismatch.
*/ */
@Test(expected = AcmeProtocolException.class) @Test
public void testNotAcceptable() { 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 that unmarshalling something different like a challenge fails.
*/ */
@Test(expected = AcmeProtocolException.class) @Test
public void testBadUnmarshall() { public void testBadUnmarshall() {
new Challenge(TestUtils.login(), getJSON("updateAccountResponse")); assertThrows(AcmeProtocolException.class, () ->
new Challenge(TestUtils.login(), getJSON("updateAccountResponse"))
);
} }
} }

View File

@ -18,7 +18,7 @@ import static org.hamcrest.Matchers.is;
import static org.shredzone.acme4j.toolbox.TestUtils.getJSON; import static org.shredzone.acme4j.toolbox.TestUtils.getJSON;
import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs; 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.Login;
import org.shredzone.acme4j.Status; import org.shredzone.acme4j.Status;
import org.shredzone.acme4j.toolbox.JSONBuilder; import org.shredzone.acme4j.toolbox.JSONBuilder;

View File

@ -15,10 +15,11 @@ package org.shredzone.acme4j.challenge;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.shredzone.acme4j.toolbox.TestUtils.getJSON; import static org.shredzone.acme4j.toolbox.TestUtils.getJSON;
import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs; 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.Login;
import org.shredzone.acme4j.Status; import org.shredzone.acme4j.Status;
import org.shredzone.acme4j.exception.AcmeProtocolException; 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 that an exception is thrown if there is no token.
*/ */
@Test(expected = AcmeProtocolException.class) @Test
public void testNoTokenSet() { public void testNoTokenSet() {
assertThrows(AcmeProtocolException.class, () -> {
Http01Challenge challenge = new Http01Challenge(login, getJSON("httpNoTokenChallenge")); Http01Challenge challenge = new Http01Challenge(login, getJSON("httpNoTokenChallenge"));
challenge.getToken(); challenge.getToken();
});
} }
} }

View File

@ -18,7 +18,7 @@ import static org.hamcrest.Matchers.is;
import static org.shredzone.acme4j.toolbox.TestUtils.getJSON; import static org.shredzone.acme4j.toolbox.TestUtils.getJSON;
import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs; 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.Login;
import org.shredzone.acme4j.Status; import org.shredzone.acme4j.Status;
import org.shredzone.acme4j.toolbox.AcmeUtils; import org.shredzone.acme4j.toolbox.AcmeUtils;

View File

@ -13,12 +13,11 @@
*/ */
package org.shredzone.acme4j.challenge; package org.shredzone.acme4j.challenge;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.Login; import org.shredzone.acme4j.Login;
import org.shredzone.acme4j.exception.AcmeProtocolException; import org.shredzone.acme4j.exception.AcmeProtocolException;
import org.shredzone.acme4j.provider.TestableConnectionProvider; import org.shredzone.acme4j.provider.TestableConnectionProvider;

View File

@ -18,8 +18,8 @@ import static java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME;
import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.any; import static org.mockito.Mockito.any;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import static org.shredzone.acme4j.toolbox.TestUtils.url; import static org.shredzone.acme4j.toolbox.TestUtils.url;
@ -51,8 +51,8 @@ import java.util.Optional;
import org.jose4j.jws.JsonWebSignature; import org.jose4j.jws.JsonWebSignature;
import org.jose4j.jwx.CompactSerializer; import org.jose4j.jwx.CompactSerializer;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers; import org.mockito.ArgumentMatchers;
import org.shredzone.acme4j.Login; import org.shredzone.acme4j.Login;
import org.shredzone.acme4j.Session; import org.shredzone.acme4j.Session;
@ -85,7 +85,7 @@ public class DefaultConnectionTest {
private Login login; private Login login;
private KeyPair keyPair; private KeyPair keyPair;
@Before @BeforeEach
public void setup() throws AcmeException, IOException { public void setup() throws AcmeException, IOException {
mockUrlConnection = mock(HttpURLConnection.class); mockUrlConnection = mock(HttpURLConnection.class);
@ -390,8 +390,6 @@ public class DefaultConnectionTest {
try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) { try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) {
conn.conn = mockUrlConnection; conn.conn = mockUrlConnection;
conn.handleRetryAfter("no header"); conn.handleRetryAfter("no header");
} catch (AcmeRetryAfterException ex) {
fail("an AcmeRetryAfterException was thrown");
} }
verify(mockUrlConnection, atLeastOnce()).getHeaderField("Retry-After"); verify(mockUrlConnection, atLeastOnce()).getHeaderField("Retry-After");
@ -407,8 +405,6 @@ public class DefaultConnectionTest {
try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) { try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) {
conn.conn = mockUrlConnection; conn.conn = mockUrlConnection;
conn.handleRetryAfter("http ok"); conn.handleRetryAfter("http ok");
} catch (AcmeRetryAfterException ex) {
fail("an AcmeRetryAfterException was thrown");
} }
} }
@ -725,22 +721,15 @@ public class DefaultConnectionTest {
@Override @Override
public void resetNonce(Session session) { public void resetNonce(Session session) {
assertThat(session, is(sameInstance(DefaultConnectionTest.this.session))); assertThat(session, is(sameInstance(DefaultConnectionTest.this.session)));
if (session.getNonce() == null) { assertThat(session.getNonce(), nullValue());
session.setNonce(nonce1); session.setNonce(nonce1);
} else {
fail("unknown nonce");
}
} }
@Override @Override
public String getNonce() { public String getNonce() {
assertThat(session, is(sameInstance(DefaultConnectionTest.this.session))); assertThat(session, is(sameInstance(DefaultConnectionTest.this.session)));
if (session.getNonce() == nonce1) { assertThat(session.getNonce(), is(nonce1));
return nonce2; return nonce2;
} else {
fail("unknown nonce");
return null;
}
} }
}) { }) {
JSONBuilder cb = new JSONBuilder(); JSONBuilder cb = new JSONBuilder();
@ -800,22 +789,15 @@ public class DefaultConnectionTest {
@Override @Override
public void resetNonce(Session session) { public void resetNonce(Session session) {
assertThat(session, is(sameInstance(DefaultConnectionTest.this.session))); assertThat(session, is(sameInstance(DefaultConnectionTest.this.session)));
if (session.getNonce() == null) { assertThat(session.getNonce(), nullValue());
session.setNonce(nonce1); session.setNonce(nonce1);
} else {
fail("unknown nonce");
}
} }
@Override @Override
public String getNonce() { public String getNonce() {
assertThat(session, is(sameInstance(DefaultConnectionTest.this.session))); assertThat(session, is(sameInstance(DefaultConnectionTest.this.session)));
if (session.getNonce() == nonce1) { assertThat(session.getNonce(), is(nonce1));
return nonce2; return nonce2;
} else {
fail("unknown nonce");
return null;
}
} }
}) { }) {
conn.sendSignedPostAsGetRequest(requestUrl, login); conn.sendSignedPostAsGetRequest(requestUrl, login);
@ -873,22 +855,15 @@ public class DefaultConnectionTest {
@Override @Override
public void resetNonce(Session session) { public void resetNonce(Session session) {
assertThat(session, is(sameInstance(DefaultConnectionTest.this.session))); assertThat(session, is(sameInstance(DefaultConnectionTest.this.session)));
if (session.getNonce() == null) { assertThat(session.getNonce(), nullValue());
session.setNonce(nonce1); session.setNonce(nonce1);
} else {
fail("unknown nonce");
}
} }
@Override @Override
public String getNonce() { public String getNonce() {
assertThat(session, is(sameInstance(DefaultConnectionTest.this.session))); assertThat(session, is(sameInstance(DefaultConnectionTest.this.session)));
if (session.getNonce() == nonce1) { assertThat(session.getNonce(), is(nonce1));
return nonce2; return nonce2;
} else {
fail("unknown nonce");
return null;
}
} }
}) { }) {
conn.sendCertificateRequest(requestUrl, login); conn.sendCertificateRequest(requestUrl, login);
@ -924,22 +899,15 @@ public class DefaultConnectionTest {
@Override @Override
public void resetNonce(Session session) { public void resetNonce(Session session) {
assertThat(session, is(sameInstance(DefaultConnectionTest.this.session))); assertThat(session, is(sameInstance(DefaultConnectionTest.this.session)));
if (session.getNonce() == null) { assertThat(session.getNonce(), nullValue());
session.setNonce(nonce1); session.setNonce(nonce1);
} else {
fail("unknown nonce");
}
} }
@Override @Override
public String getNonce() { public String getNonce() {
assertThat(session, is(sameInstance(DefaultConnectionTest.this.session))); assertThat(session, is(sameInstance(DefaultConnectionTest.this.session)));
if (session.getNonce() == nonce1) { assertThat(session.getNonce(), is(nonce1));
return nonce2; return nonce2;
} else {
fail("unknown nonce");
return null;
}
} }
}) { }) {
JSONBuilder cb = new JSONBuilder(); JSONBuilder cb = new JSONBuilder();
@ -989,17 +957,19 @@ public class DefaultConnectionTest {
/** /**
* Test signed POST requests if there is no nonce. * Test signed POST requests if there is no nonce.
*/ */
@Test(expected = AcmeException.class) @Test
public void testSendSignedRequestNoNonce() throws Exception { public void testSendSignedRequestNoNonce() throws Exception {
when(mockHttpConnection.openConnection(eq(new URL("https://example.com/acme/new-nonce")), any())) when(mockHttpConnection.openConnection(eq(new URL("https://example.com/acme/new-nonce")), any()))
.thenReturn(mockUrlConnection); .thenReturn(mockUrlConnection);
when(mockUrlConnection.getResponseCode()) when(mockUrlConnection.getResponseCode())
.thenReturn(HttpURLConnection.HTTP_NOT_FOUND); .thenReturn(HttpURLConnection.HTTP_NOT_FOUND);
assertThrows(AcmeException.class, () -> {
try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) { try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) {
JSONBuilder cb = new JSONBuilder(); JSONBuilder cb = new JSONBuilder();
conn.sendSignedRequest(requestUrl, cb, DefaultConnectionTest.this.session, DefaultConnectionTest.this.keyPair); 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 that a bad certificate throws an exception.
*/ */
@Test(expected = AcmeProtocolException.class) @Test
public void testReadBadCertificate() throws Exception { public void testReadBadCertificate() throws Exception {
// Build a broken certificate chain PEM file // Build a broken certificate chain PEM file
byte[] brokenPem; byte[] brokenPem;
@ -1079,10 +1049,12 @@ public class DefaultConnectionTest {
when(mockUrlConnection.getHeaderField("Content-Type")).thenReturn("application/pem-certificate-chain"); when(mockUrlConnection.getHeaderField("Content-Type")).thenReturn("application/pem-certificate-chain");
when(mockUrlConnection.getInputStream()).thenReturn(new ByteArrayInputStream(brokenPem)); when(mockUrlConnection.getInputStream()).thenReturn(new ByteArrayInputStream(brokenPem));
assertThrows(AcmeProtocolException.class, () -> {
try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) { try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) {
conn.conn = mockUrlConnection; conn.conn = mockUrlConnection;
conn.readCertificates(); conn.readCertificates();
} }
});
} }
/** /**

View File

@ -23,8 +23,8 @@ import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.time.Duration; import java.time.Duration;
import org.junit.Test; import org.junit.jupiter.api.Tag;
import org.junit.experimental.categories.Category; import org.junit.jupiter.api.Test;
/** /**
* Unit tests for {@link HttpConnector}. * Unit tests for {@link HttpConnector}.
@ -59,7 +59,7 @@ public class HttpConnectorTest {
* builds. * builds.
*/ */
@Test @Test
@Category(HttpURLConnection.class) @Tag("requires-network")
public void testOpenConnection() throws IOException { public void testOpenConnection() throws IOException {
NetworkSettings settings = new NetworkSettings(); NetworkSettings settings = new NetworkSettings();
HttpConnector connector = new HttpConnector(); HttpConnector connector = new HttpConnector();

View File

@ -15,14 +15,13 @@ package org.shredzone.acme4j.connector;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.fail;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Proxy; import java.net.Proxy;
import java.time.Duration; import java.time.Duration;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Unit tests for {@link NetworkSettings}. * Unit tests for {@link NetworkSettings}.
@ -52,14 +51,18 @@ public class NetworkSettingsTest {
public void testInvalidTimeouts() { public void testInvalidTimeouts() {
NetworkSettings settings = new NetworkSettings(); NetworkSettings settings = new NetworkSettings();
assertThrows("timeout accepted null", IllegalArgumentException.class, assertThrows(IllegalArgumentException.class,
() -> settings.setTimeout(null)); () -> settings.setTimeout(null),
assertThrows("timeout accepted zero duration", IllegalArgumentException.class, "timeout accepted null");
() -> settings.setTimeout(Duration.ZERO)); assertThrows(IllegalArgumentException.class,
assertThrows("timeout accepted negative duration", IllegalArgumentException.class, () -> settings.setTimeout(Duration.ZERO),
() -> settings.setTimeout(Duration.ofSeconds(20).negated())); "timeout accepted zero duration");
assertThrows("timeout accepted out of range value", IllegalArgumentException.class, assertThrows(IllegalArgumentException.class,
() -> settings.setTimeout(Duration.ofMillis(Integer.MAX_VALUE + 1L))); () -> 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");
} }
} }

View File

@ -15,6 +15,7 @@ package org.shredzone.acme4j.connector;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.shredzone.acme4j.toolbox.TestUtils.url; import static org.shredzone.acme4j.toolbox.TestUtils.url;
import java.io.IOException; import java.io.IOException;
@ -27,8 +28,8 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.Authorization; import org.shredzone.acme4j.Authorization;
import org.shredzone.acme4j.Login; import org.shredzone.acme4j.Login;
import org.shredzone.acme4j.provider.TestableConnectionProvider; import org.shredzone.acme4j.provider.TestableConnectionProvider;
@ -47,7 +48,7 @@ public class ResourceIteratorTest {
private final List<URL> resourceURLs = new ArrayList<>(PAGES * RESOURCES_PER_PAGE); private final List<URL> resourceURLs = new ArrayList<>(PAGES * RESOURCES_PER_PAGE);
private final List<URL> pageURLs = new ArrayList<>(PAGES); private final List<URL> pageURLs = new ArrayList<>(PAGES);
@Before @BeforeEach
public void setup() { public void setup() {
resourceURLs.clear(); resourceURLs.clear();
for (int ix = 0; ix < RESOURCES_PER_PAGE * PAGES; ix++) { 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 if the {@link ResourceIterator} handles a {@code null} start URL.
*/ */
@Test(expected = NoSuchElementException.class) @Test
public void nullTest() throws IOException { public void nullTest() throws IOException {
assertThrows(NoSuchElementException.class, () -> {
Iterator<Authorization> it = createIterator(null); Iterator<Authorization> it = createIterator(null);
assertThat(it, not(nullValue())); assertThat(it, not(nullValue()));
assertThat(it.hasNext(), is(false)); assertThat(it.hasNext(), is(false));
it.next(); // throws NoSuchElementException it.next(); // throws NoSuchElementException
});
} }
/** /**
@ -114,11 +117,13 @@ public class ResourceIteratorTest {
/** /**
* Test that {@link Iterator#remove()} fails. * Test that {@link Iterator#remove()} fails.
*/ */
@Test(expected = UnsupportedOperationException.class) @Test
public void removeTest() throws IOException { public void removeTest() throws IOException {
assertThrows(UnsupportedOperationException.class, () -> {
Iterator<Authorization> it = createIterator(pageURLs.get(0)); Iterator<Authorization> it = createIterator(pageURLs.get(0));
it.next(); it.next();
it.remove(); // throws UnsupportedOperationException it.remove(); // throws UnsupportedOperationException
});
} }
/** /**

View File

@ -16,7 +16,7 @@ package org.shredzone.acme4j.connector;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Unit test for {@link Resource}. * Unit test for {@link Resource}.

View File

@ -15,12 +15,13 @@ package org.shredzone.acme4j.connector;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
import java.util.ServiceLoader; import java.util.ServiceLoader;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.Login; import org.shredzone.acme4j.Login;
import org.shredzone.acme4j.Session; import org.shredzone.acme4j.Session;
import org.shredzone.acme4j.challenge.Challenge; 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 * There are no testing providers accepting {@code acme://example.org}. Test that
* connecting to this URI will result in an {@link IllegalArgumentException}. * connecting to this URI will result in an {@link IllegalArgumentException}.
*/ */
@Test(expected = IllegalArgumentException.class) @Test
public void testNone() throws Exception { 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 * There are two testing providers accepting {@code acme://example.net}. Test that
* connecting to this URI will result in an {@link IllegalArgumentException}. * connecting to this URI will result in an {@link IllegalArgumentException}.
*/ */
@Test(expected = IllegalArgumentException.class) @Test
public void testDuplicate() throws Exception { 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 { public static class Provider1 implements AcmeProvider {

View File

@ -21,7 +21,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Unit tests for {@link TrimmingInputStream}. * Unit tests for {@link TrimmingInputStream}.

View File

@ -19,7 +19,7 @@ import static org.hamcrest.Matchers.nullValue;
import java.io.IOException; import java.io.IOException;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Unit tests for {@link AcmeException}. * Unit tests for {@link AcmeException}.
@ -48,7 +48,7 @@ public class AcmeExceptionTest {
AcmeException ex = new AcmeException(message, cause); AcmeException ex = new AcmeException(message, cause);
assertThat(ex.getMessage(), is(message)); assertThat(ex.getMessage(), is(message));
assertThat(ex.getCause(), is((Throwable) cause)); assertThat(ex.getCause(), is(cause));
} }
} }

View File

@ -19,7 +19,7 @@ import static org.mockito.Mockito.mock;
import java.net.URL; import java.net.URL;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.AcmeResource; import org.shredzone.acme4j.AcmeResource;
import org.shredzone.acme4j.Login; import org.shredzone.acme4j.Login;
import org.shredzone.acme4j.toolbox.TestUtils; import org.shredzone.acme4j.toolbox.TestUtils;

View File

@ -19,7 +19,7 @@ import static org.hamcrest.Matchers.notNullValue;
import java.io.IOException; import java.io.IOException;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Unit tests for {@link AcmeNetworkException}. * Unit tests for {@link AcmeNetworkException}.

View File

@ -16,7 +16,7 @@ package org.shredzone.acme4j.exception;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Unit tests for {@link AcmeProtocolException}. * Unit tests for {@link AcmeProtocolException}.

View File

@ -25,7 +25,7 @@ import java.time.Instant;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.Problem; import org.shredzone.acme4j.Problem;
/** /**

View File

@ -15,11 +15,12 @@ package org.shredzone.acme4j.exception;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Unit tests for {@link AcmeRetryAfterException}. * Unit tests for {@link AcmeRetryAfterException}.
@ -43,9 +44,11 @@ public class AcmeRetryAfterExceptionTest {
/** /**
* Test that date is required. * Test that date is required.
*/ */
@Test(expected = NullPointerException.class) @Test
public void testRequiredAcmeRetryAfterException() throws AcmeException { public void testRequiredAcmeRetryAfterException() {
assertThrows(NullPointerException.class, () -> {
throw new AcmeRetryAfterException("null-test", null); throw new AcmeRetryAfterException("null-test", null);
});
} }
} }

View File

@ -22,7 +22,7 @@ import java.net.MalformedURLException;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.Problem; import org.shredzone.acme4j.Problem;
/** /**

View File

@ -15,8 +15,7 @@ package org.shredzone.acme4j.provider;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.any; import static org.mockito.Mockito.any;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import static org.shredzone.acme4j.toolbox.TestUtils.getJSON; import static org.shredzone.acme4j.toolbox.TestUtils.getJSON;
@ -31,7 +30,7 @@ import java.time.temporal.ChronoUnit;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean; 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.Login;
import org.shredzone.acme4j.Session; import org.shredzone.acme4j.Session;
import org.shredzone.acme4j.challenge.Challenge; import org.shredzone.acme4j.challenge.Challenge;

View File

@ -20,7 +20,7 @@ import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; 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.Connection;
import org.shredzone.acme4j.connector.DefaultConnection; import org.shredzone.acme4j.connector.DefaultConnection;

View File

@ -15,14 +15,13 @@ package org.shredzone.acme4j.provider.letsencrypt;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.fail;
import static org.shredzone.acme4j.toolbox.TestUtils.url; import static org.shredzone.acme4j.toolbox.TestUtils.url;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Unit tests for {@link LetsEncryptAcmeProvider}. * Unit tests for {@link LetsEncryptAcmeProvider}.

View File

@ -15,14 +15,13 @@ package org.shredzone.acme4j.provider.pebble;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.fail;
import static org.shredzone.acme4j.toolbox.TestUtils.url; import static org.shredzone.acme4j.toolbox.TestUtils.url;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Unit tests for {@link PebbleAcmeProvider}. * Unit tests for {@link PebbleAcmeProvider}.

View File

@ -16,8 +16,7 @@ package org.shredzone.acme4j.toolbox;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.fail;
import static org.shredzone.acme4j.toolbox.AcmeUtils.*; import static org.shredzone.acme4j.toolbox.AcmeUtils.*;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -40,17 +39,16 @@ import java.util.List;
import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.hamcrest.BaseMatcher; import org.hamcrest.BaseMatcher;
import org.hamcrest.Description; import org.hamcrest.Description;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.exception.AcmeProtocolException; import org.shredzone.acme4j.exception.AcmeProtocolException;
import org.shredzone.acme4j.toolbox.AcmeUtils.*;
/** /**
* Unit tests for {@link AcmeUtils}. * Unit tests for {@link AcmeUtils}.
*/ */
public class AcmeUtilsTest { public class AcmeUtilsTest {
@BeforeClass @BeforeAll
public static void setup() { public static void setup() {
Security.addProvider(new BouncyCastleProvider()); Security.addProvider(new BouncyCastleProvider());
} }
@ -173,14 +171,18 @@ public class AcmeUtilsTest {
*/ */
@Test @Test
public void testInvalid() { public void testInvalid() {
assertThrows("accepted empty string", IllegalArgumentException.class, assertThrows(IllegalArgumentException.class,
() -> parseTimestamp("")); () -> parseTimestamp(""),
assertThrows("accepted nonsense string", IllegalArgumentException.class, "accepted empty string");
() -> parseTimestamp("abc")); assertThrows(IllegalArgumentException.class,
assertThrows("accepted date only string", IllegalArgumentException.class, () -> parseTimestamp("abc"),
() -> parseTimestamp("2015-12-27")); "accepted nonsense string");
assertThrows("accepted string without time", IllegalArgumentException.class, assertThrows(IllegalArgumentException.class,
() -> parseTimestamp("2015-12-27T")); () -> 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() { public void testValidateContact() {
AcmeUtils.validateContact(URI.create("mailto:foo@example.com")); AcmeUtils.validateContact(URI.create("mailto:foo@example.com"));
assertThrows("multiple recipients are accepted", IllegalArgumentException.class, assertThrows(IllegalArgumentException.class,
() -> AcmeUtils.validateContact(URI.create("mailto:foo@example.com,bar@example.com"))); () -> AcmeUtils.validateContact(URI.create("mailto:foo@example.com,bar@example.com")),
assertThrows("hfields are accepted", IllegalArgumentException.class, "multiple recipients are accepted");
() -> AcmeUtils.validateContact(URI.create("mailto:foo@example.com?to=bar@example.com"))); assertThrows(IllegalArgumentException.class,
assertThrows("only hfields are accepted", IllegalArgumentException.class, () -> AcmeUtils.validateContact(URI.create("mailto:foo@example.com?to=bar@example.com")),
() -> AcmeUtils.validateContact(URI.create("mailto:?to=foo@example.com"))); "hfields are accepted");
assertThrows(IllegalArgumentException.class,
() -> AcmeUtils.validateContact(URI.create("mailto:?to=foo@example.com")),
"only hfields are accepted");
} }
/** /**

View File

@ -28,7 +28,7 @@ import java.util.Map;
import org.jose4j.json.JsonUtil; import org.jose4j.json.JsonUtil;
import org.jose4j.lang.JoseException; import org.jose4j.lang.JoseException;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Unit test for {@link JSONBuilder}. * Unit test for {@link JSONBuilder}.

View File

@ -16,8 +16,7 @@ package org.shredzone.acme4j.toolbox;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.fail;
import static org.shredzone.acme4j.toolbox.TestUtils.url; import static org.shredzone.acme4j.toolbox.TestUtils.url;
import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs; import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs;
@ -40,7 +39,7 @@ import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.Problem; import org.shredzone.acme4j.Problem;
import org.shredzone.acme4j.Status; import org.shredzone.acme4j.Status;
import org.shredzone.acme4j.exception.AcmeProtocolException; import org.shredzone.acme4j.exception.AcmeProtocolException;
@ -92,9 +91,11 @@ public class JSONTest {
/** /**
* Test that bad JSON fails. * Test that bad JSON fails.
*/ */
@Test(expected = AcmeProtocolException.class) @Test
public void testParsersBadJSON() { 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").optional().isPresent(), is(false));
assertThat(json.get("none").map(Value::asString).isPresent(), is(false)); assertThat(json.get("none").map(Value::asString).isPresent(), is(false));
assertThrows("asString", AcmeProtocolException.class, assertThrows(AcmeProtocolException.class,
() -> json.get("none").asString()); () -> json.get("none").asString(),
assertThrows("asURI", AcmeProtocolException.class, "asString");
() -> json.get("none").asURI()); assertThrows(AcmeProtocolException.class,
assertThrows("asURL", AcmeProtocolException.class, () -> json.get("none").asURI(),
() -> json.get("none").asURL()); "asURI");
assertThrows("asInstant", AcmeProtocolException.class, assertThrows(AcmeProtocolException.class,
() -> json.get("none").asInstant()); () -> json.get("none").asURL(),
assertThrows("asDuration", AcmeProtocolException.class, "asURL");
() -> json.get("none").asDuration()); assertThrows(AcmeProtocolException.class,
assertThrows("asObject", AcmeProtocolException.class, () -> json.get("none").asInstant(),
() -> json.get("none").asObject()); "asInstant");
assertThrows("asEncodedObject", AcmeProtocolException.class, assertThrows(AcmeProtocolException.class,
() -> json.get("none").asEncodedObject()); () -> json.get("none").asDuration(),
assertThrows("asStatus", AcmeProtocolException.class, "asDuration");
() -> json.get("none").asStatus()); assertThrows(AcmeProtocolException.class,
assertThrows("asBinary", AcmeProtocolException.class, () -> json.get("none").asObject(),
() -> json.get("none").asBinary()); "asObject");
assertThrows("asProblem", AcmeProtocolException.class, assertThrows(AcmeProtocolException.class,
() -> json.get("none").asProblem(BASE_URL)); () -> json.get("none").asEncodedObject(),
assertThrows("asInt", AcmeProtocolException.class, "asEncodedObject");
() -> json.get("none").asInt()); assertThrows(AcmeProtocolException.class,
assertThrows("asBoolean", AcmeProtocolException.class, () -> json.get("none").asStatus(),
() -> json.get("none").asBoolean()); "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() { public void testWrongGetter() {
JSON json = TestUtils.getJSON("datatypes"); JSON json = TestUtils.getJSON("datatypes");
assertThrows("asObject", AcmeProtocolException.class, assertThrows(AcmeProtocolException.class,
() -> json.get("text").asObject()); () -> json.get("text").asObject(),
assertThrows("asEncodedObject", AcmeProtocolException.class, "asObject");
() -> json.get("text").asEncodedObject()); assertThrows(AcmeProtocolException.class,
assertThrows("asArray", AcmeProtocolException.class, () -> json.get("text").asEncodedObject(),
() -> json.get("text").asArray()); "asEncodedObject");
assertThrows("asInt", AcmeProtocolException.class, assertThrows(AcmeProtocolException.class,
() -> json.get("text").asInt()); () -> json.get("text").asArray(),
assertThrows("asURI", AcmeProtocolException.class, "asArray");
() -> json.get("text").asURI()); assertThrows(AcmeProtocolException.class,
assertThrows("asURL", AcmeProtocolException.class, () -> json.get("text").asInt(),
() -> json.get("text").asURL()); "asInt");
assertThrows("asInstant", AcmeProtocolException.class, assertThrows(AcmeProtocolException.class,
() -> json.get("text").asInstant()); () -> json.get("text").asURI(),
assertThrows("asDuration", AcmeProtocolException.class, "asURI");
() -> json.get("text").asDuration()); assertThrows(AcmeProtocolException.class,
assertThrows("asProblem", AcmeProtocolException.class, () -> json.get("text").asURL(),
() -> json.get("text").asProblem(BASE_URL)); "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");
} }
/** /**

View File

@ -16,7 +16,7 @@ package org.shredzone.acme4j.toolbox;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; 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 org.shredzone.acme4j.toolbox.TestUtils.url;
import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs; 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.jws.JsonWebSignature;
import org.jose4j.jwx.CompactSerializer; import org.jose4j.jwx.CompactSerializer;
import org.jose4j.lang.JoseException; import org.jose4j.lang.JoseException;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Unit tests for {@link JoseUtils}. * Unit tests for {@link JoseUtils}.
@ -307,7 +307,7 @@ public class JoseUtilsTest {
expectedPayload.append("}"); expectedPayload.append("}");
assertThat(decodedPayload, sameJSONAs(expectedPayload.toString())); assertThat(decodedPayload, sameJSONAs(expectedPayload.toString()));
} catch (JoseException ex) { } catch (JoseException ex) {
fail(ex.getMessage()); fail(ex);
} }
} }

View File

@ -17,13 +17,12 @@ import static java.util.concurrent.TimeUnit.SECONDS;
import static org.awaitility.Awaitility.await; import static org.awaitility.Awaitility.await;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.fail;
import java.net.URI; import java.net.URI;
import java.security.KeyPair; import java.security.KeyPair;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.Account; import org.shredzone.acme4j.Account;
import org.shredzone.acme4j.AccountBuilder; import org.shredzone.acme4j.AccountBuilder;
import org.shredzone.acme4j.Authorization; import org.shredzone.acme4j.Authorization;
@ -80,9 +79,7 @@ public class OrderHttpIT {
.conditionEvaluationListener(cond -> updateAuth(auth)) .conditionEvaluationListener(cond -> updateAuth(auth))
.until(auth::getStatus, not(oneOf(Status.PENDING, Status.PROCESSING))); .until(auth::getStatus, not(oneOf(Status.PENDING, Status.PROCESSING)));
if (auth.getStatus() != Status.VALID) { assertThat(auth.getStatus(), is(Status.VALID));
fail("Authorization failed");
}
client.httpRemoveToken(challenge.getToken()); client.httpRemoveToken(challenge.getToken());
} }

View File

@ -16,14 +16,13 @@ package org.shredzone.acme4j.it.pebble;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.fail;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
import java.security.KeyPair; import java.security.KeyPair;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.Account; import org.shredzone.acme4j.Account;
import org.shredzone.acme4j.AccountBuilder; import org.shredzone.acme4j.AccountBuilder;
import org.shredzone.acme4j.Login; import org.shredzone.acme4j.Login;
@ -192,11 +191,11 @@ public class AccountIT extends PebbleITBase {
KeyPair newKeyPair = createKeyPair(); KeyPair newKeyPair = createKeyPair();
acct.changeKey(newKeyPair); acct.changeKey(newKeyPair);
assertThrows("Old account key is still accessible", AcmeServerException.class, () -> { assertThrows(AcmeServerException.class, () -> {
Session sessionOldKey = new Session(pebbleURI()); Session sessionOldKey = new Session(pebbleURI());
Account oldAccount = sessionOldKey.login(location, keyPair).getAccount(); Account oldAccount = sessionOldKey.login(location, keyPair).getAccount();
oldAccount.update(); oldAccount.update();
}); }, "Old account key is still accessible");
Session sessionNewKey = new Session(pebbleURI()); Session sessionNewKey = new Session(pebbleURI());
Account newAccount = sessionNewKey.login(location, newKeyPair).getAccount(); Account newAccount = sessionNewKey.login(location, newKeyPair).getAccount();
@ -223,12 +222,12 @@ public class AccountIT extends PebbleITBase {
assertThat(acct.getStatus(), is(Status.DEACTIVATED)); assertThat(acct.getStatus(), is(Status.DEACTIVATED));
// Make sure account cannot be accessed any more... // Make sure account cannot be accessed any more...
AcmeUnauthorizedException ex = assertThrows("Account can still be accessed", AcmeUnauthorizedException ex = assertThrows(AcmeUnauthorizedException.class,
AcmeUnauthorizedException.class, () -> { () -> {
Session session2 = new Session(pebbleURI()); Session session2 = new Session(pebbleURI());
Account acct2 = session2.login(location, keyPair).getAccount(); Account acct2 = session2.login(location, keyPair).getAccount();
acct2.update(); acct2.update();
}); }, "Account can still be accessed");
assertThat(ex.getMessage(), is("Account has been deactivated")); assertThat(ex.getMessage(), is("Account has been deactivated"));
} }

View File

@ -17,8 +17,7 @@ import static java.util.concurrent.TimeUnit.SECONDS;
import static org.awaitility.Awaitility.await; import static org.awaitility.Awaitility.await;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.fail;
import java.net.URI; import java.net.URI;
import java.security.KeyPair; import java.security.KeyPair;
@ -27,7 +26,7 @@ import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.Account; import org.shredzone.acme4j.Account;
import org.shredzone.acme4j.AccountBuilder; import org.shredzone.acme4j.AccountBuilder;
import org.shredzone.acme4j.Authorization; 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.challenge.TlsAlpn01Challenge;
import org.shredzone.acme4j.exception.AcmeException; import org.shredzone.acme4j.exception.AcmeException;
import org.shredzone.acme4j.exception.AcmeServerException; import org.shredzone.acme4j.exception.AcmeServerException;
import org.shredzone.acme4j.exception.AcmeUnauthorizedException;
import org.shredzone.acme4j.it.BammBammClient; import org.shredzone.acme4j.it.BammBammClient;
import org.shredzone.acme4j.util.CSRBuilder; import org.shredzone.acme4j.util.CSRBuilder;
@ -186,9 +184,7 @@ public class OrderIT extends PebbleITBase {
.conditionEvaluationListener(cond -> updateAuth(auth)) .conditionEvaluationListener(cond -> updateAuth(auth))
.until(auth::getStatus, not(oneOf(Status.PENDING, Status.PROCESSING))); .until(auth::getStatus, not(oneOf(Status.PENDING, Status.PROCESSING)));
if (auth.getStatus() != Status.VALID) { assertThat(auth.getStatus(), is(Status.VALID));
fail("Authorization failed");
}
} }
CSRBuilder csr = new CSRBuilder(); CSRBuilder csr = new CSRBuilder();
@ -204,9 +200,7 @@ public class OrderIT extends PebbleITBase {
.conditionEvaluationListener(cond -> updateOrder(order)) .conditionEvaluationListener(cond -> updateOrder(order))
.until(order::getStatus, not(oneOf(Status.PENDING, Status.PROCESSING, Status.READY))); .until(order::getStatus, not(oneOf(Status.PENDING, Status.PROCESSING, Status.READY)));
if (order.getStatus() != Status.VALID) { assertThat(order.getStatus(), is(Status.VALID));
fail("Order failed");
}
Certificate certificate = order.getCertificate(); Certificate certificate = order.getCertificate();
X509Certificate cert = certificate.getCertificate(); X509Certificate cert = certificate.getCertificate();
@ -224,16 +218,17 @@ public class OrderIT extends PebbleITBase {
revoker.revoke(session, certificate, keyPair, domainKeyPair); revoker.revoke(session, certificate, keyPair, domainKeyPair);
// Make sure certificate is revoked // 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); Login login2 = session.login(account.getLocation(), keyPair);
Certificate cert2 = login2.bindCertificate(certificate.getLocation()); Certificate cert2 = login2.bindCertificate(certificate.getLocation());
cert2.download(); cert2.download();
}); }, "Could download revoked cert");
assertThat(ex.getMessage(), is("HTTP 404: Not Found")); assertThat(ex.getMessage(), is("HTTP 404: Not Found"));
// Try to revoke again // Try to revoke again
AcmeServerException ex2 = assertThrows("Could revoke again", AcmeServerException.class, AcmeServerException ex2 = assertThrows(AcmeServerException.class,
() -> certificate.revoke()); () -> certificate.revoke(),
"Could revoke again");
assertThat(ex2.getProblem().getType(), is(URI.create("urn:ietf:params:acme:error:alreadyRevoked"))); assertThat(ex2.getProblem().getType(), is(URI.create("urn:ietf:params:acme:error:alreadyRevoked")));
} }

View File

@ -18,7 +18,6 @@ import static java.util.stream.Collectors.toList;
import static org.awaitility.Awaitility.await; import static org.awaitility.Awaitility.await;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.fail;
import java.security.KeyPair; import java.security.KeyPair;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
@ -28,7 +27,7 @@ import java.time.temporal.ChronoUnit;
import java.util.List; import java.util.List;
import org.bouncycastle.asn1.x509.GeneralName; 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.Account;
import org.shredzone.acme4j.AccountBuilder; import org.shredzone.acme4j.AccountBuilder;
import org.shredzone.acme4j.Authorization; import org.shredzone.acme4j.Authorization;
@ -102,9 +101,7 @@ public class OrderWildcardIT extends PebbleITBase {
.conditionEvaluationListener(cond -> updateAuth(auth)) .conditionEvaluationListener(cond -> updateAuth(auth))
.until(auth::getStatus, not(oneOf(Status.PENDING, Status.PROCESSING))); .until(auth::getStatus, not(oneOf(Status.PENDING, Status.PROCESSING)));
if (auth.getStatus() != Status.VALID) { assertThat(auth.getStatus(), is(Status.VALID));
fail("Authorization failed");
}
} }
CSRBuilder csr = new CSRBuilder(); CSRBuilder csr = new CSRBuilder();

View File

@ -22,7 +22,7 @@ import java.security.KeyPair;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.shredzone.acme4j.Authorization; import org.shredzone.acme4j.Authorization;
import org.shredzone.acme4j.Order; import org.shredzone.acme4j.Order;
import org.shredzone.acme4j.exception.AcmeException; import org.shredzone.acme4j.exception.AcmeException;
@ -51,7 +51,7 @@ public abstract class PebbleITBase {
private final List<CleanupCallback> cleanup = new ArrayList<>(); private final List<CleanupCallback> cleanup = new ArrayList<>();
@After @AfterEach
public void performCleanup() throws Exception { public void performCleanup() throws Exception {
for (CleanupCallback callback : cleanup) { for (CleanupCallback callback : cleanup) {
callback.cleanup(); callback.cleanup();

View File

@ -19,7 +19,7 @@ import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs;
import java.net.URI; import java.net.URI;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.Metadata; import org.shredzone.acme4j.Metadata;
import org.shredzone.acme4j.Session; import org.shredzone.acme4j.Session;
import org.shredzone.acme4j.connector.Resource; import org.shredzone.acme4j.connector.Resource;

View File

@ -40,7 +40,7 @@ public interface ResponseBodyGenerator {
/** /**
* The content-type of the response body: {@value #RESPONSE_BODY_TYPE} * 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}. * Sets the content of the {@link Message}.

View File

@ -18,7 +18,7 @@ import static org.hamcrest.Matchers.is;
import jakarta.mail.internet.AddressException; import jakarta.mail.internet.AddressException;
import jakarta.mail.internet.InternetAddress; import jakarta.mail.internet.InternetAddress;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Tests of {@link EmailIdentifier}. * Tests of {@link EmailIdentifier}.

View File

@ -15,11 +15,12 @@ package org.shredzone.acme4j.smime.challenge;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.Status; import org.shredzone.acme4j.Status;
import org.shredzone.acme4j.challenge.Challenge; import org.shredzone.acme4j.challenge.Challenge;
import org.shredzone.acme4j.provider.AbstractAcmeProvider; import org.shredzone.acme4j.provider.AbstractAcmeProvider;
@ -63,10 +64,12 @@ public class EmailReply00ChallengeTest extends SMIMETests {
/** /**
* Test that {@link EmailReply00Challenge#getAuthorization()} is not implemented. * Test that {@link EmailReply00Challenge#getAuthorization()} is not implemented.
*/ */
@Test(expected = UnsupportedOperationException.class) @Test
public void testInvalidGetAuthorization() { public void testInvalidGetAuthorization() {
assertThrows(UnsupportedOperationException.class, () -> {
EmailReply00Challenge challenge = new EmailReply00Challenge(mockLogin(), getJSON("emailReplyChallenge")); EmailReply00Challenge challenge = new EmailReply00Challenge(mockLogin(), getJSON("emailReplyChallenge"));
challenge.getAuthorization(); challenge.getAuthorization();
});
} }
/** /**

View File

@ -16,7 +16,7 @@ package org.shredzone.acme4j.smime.csr;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is; 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.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -47,9 +47,8 @@ import org.bouncycastle.pkcs.PKCS10CertificationRequest;
import org.hamcrest.BaseMatcher; import org.hamcrest.BaseMatcher;
import org.hamcrest.Description; import org.hamcrest.Description;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.Assert; import org.junit.jupiter.api.BeforeAll;
import org.junit.BeforeClass; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.shredzone.acme4j.util.KeyPairUtils; import org.shredzone.acme4j.util.KeyPairUtils;
/** /**
@ -60,7 +59,7 @@ public class SMIMECSRBuilderTest {
private static KeyPair testKey; private static KeyPair testKey;
private static KeyPair testEcKey; private static KeyPair testEcKey;
@BeforeClass @BeforeAll
public static void setup() { public static void setup() {
Security.addProvider(new BouncyCastleProvider()); Security.addProvider(new BouncyCastleProvider());
@ -241,10 +240,12 @@ public class SMIMECSRBuilderTest {
/** /**
* Make sure an exception is thrown when nothing is set. * Make sure an exception is thrown when nothing is set.
*/ */
@Test(expected = IllegalStateException.class) @Test
public void testNoEmail() throws IOException { public void testNoEmail() throws IOException {
assertThrows(IllegalStateException.class, () -> {
SMIMECSRBuilder builder = new SMIMECSRBuilder(); SMIMECSRBuilder builder = new SMIMECSRBuilder();
builder.sign(testKey); builder.sign(testKey);
});
} }
/** /**
@ -254,13 +255,13 @@ public class SMIMECSRBuilderTest {
public void testNoSign() throws IOException { public void testNoSign() throws IOException {
SMIMECSRBuilder builder = new SMIMECSRBuilder(); SMIMECSRBuilder builder = new SMIMECSRBuilder();
assertThrows("getCSR", IllegalStateException.class, builder::getCSR); assertThrows(IllegalStateException.class, builder::getCSR, "getCSR");
assertThrows("getEncoded", IllegalStateException.class, builder::getEncoded); assertThrows(IllegalStateException.class, builder::getEncoded, "getEncoded");
assertThrows("write", IllegalStateException.class,() -> { assertThrows(IllegalStateException.class, () -> {
try (StringWriter w = new StringWriter()) { try (StringWriter w = new StringWriter()) {
builder.write(w); builder.write(w);
} }
}); },"write");
} }
/** /**

View File

@ -16,6 +16,7 @@ package org.shredzone.acme4j.smime.email;
import static jakarta.mail.Message.RecipientType.TO; import static jakarta.mail.Message.RecipientType.TO;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.IOException; import java.io.IOException;
import java.util.Optional; import java.util.Optional;
@ -23,7 +24,7 @@ import java.util.Optional;
import jakarta.mail.Message; import jakarta.mail.Message;
import jakarta.mail.MessagingException; import jakarta.mail.MessagingException;
import jakarta.mail.internet.InternetAddress; import jakarta.mail.internet.InternetAddress;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.Identifier; import org.shredzone.acme4j.Identifier;
import org.shredzone.acme4j.exception.AcmeProtocolException; import org.shredzone.acme4j.exception.AcmeProtocolException;
import org.shredzone.acme4j.smime.EmailIdentifier; import org.shredzone.acme4j.smime.EmailIdentifier;
@ -35,10 +36,10 @@ import org.shredzone.acme4j.smime.challenge.EmailReply00Challenge;
*/ */
public class EmailProcessorTest extends SMIMETests { public class EmailProcessorTest extends SMIMETests {
private InternetAddress expectedFrom = email("acme-generator@example.org"); private final InternetAddress expectedFrom = email("acme-generator@example.org");
private InternetAddress expectedTo = email("alexey@example.com"); private final InternetAddress expectedTo = email("alexey@example.com");
private InternetAddress expectedReplyTo = email("acme-validator@example.org"); private final InternetAddress expectedReplyTo = email("acme-validator@example.org");
private Message message = mockMessage("challenge"); private final Message message = mockMessage("challenge");
@Test @Test
public void testEmailParser() throws MessagingException { public void testEmailParser() throws MessagingException {
@ -55,46 +56,60 @@ public class EmailProcessorTest extends SMIMETests {
assertThat(processor.getReplyTo(), contains(email("acme-validator@example.org"))); assertThat(processor.getReplyTo(), contains(email("acme-validator@example.org")));
} }
@Test(expected = AcmeProtocolException.class) @Test
public void textExpectedFromFails() { public void textExpectedFromFails() {
assertThrows(AcmeProtocolException.class, () -> {
EmailProcessor processor = new EmailProcessor(message); EmailProcessor processor = new EmailProcessor(message);
processor.expectedFrom(expectedTo); processor.expectedFrom(expectedTo);
});
} }
@Test(expected = AcmeProtocolException.class) @Test
public void textExpectedToFails() { public void textExpectedToFails() {
assertThrows(AcmeProtocolException.class, () -> {
EmailProcessor processor = new EmailProcessor(message); EmailProcessor processor = new EmailProcessor(message);
processor.expectedTo(expectedFrom); processor.expectedTo(expectedFrom);
});
} }
@Test(expected = AcmeProtocolException.class) @Test
public void textExpectedIdentifierFails1() { public void textExpectedIdentifierFails1() {
assertThrows(AcmeProtocolException.class, () -> {
EmailProcessor processor = new EmailProcessor(message); EmailProcessor processor = new EmailProcessor(message);
processor.expectedIdentifier(EmailIdentifier.email(expectedFrom)); processor.expectedIdentifier(EmailIdentifier.email(expectedFrom));
});
} }
@Test(expected = AcmeProtocolException.class) @Test
public void textExpectedIdentifierFails2() { public void textExpectedIdentifierFails2() {
assertThrows(AcmeProtocolException.class, () -> {
EmailProcessor processor = new EmailProcessor(message); EmailProcessor processor = new EmailProcessor(message);
processor.expectedIdentifier(Identifier.ip("192.168.0.1")); processor.expectedIdentifier(Identifier.ip("192.168.0.1"));
});
} }
@Test(expected = IllegalStateException.class) @Test
public void textNoChallengeFails1() { public void textNoChallengeFails1() {
assertThrows(IllegalStateException.class, () -> {
EmailProcessor processor = new EmailProcessor(message); EmailProcessor processor = new EmailProcessor(message);
processor.getToken(); processor.getToken();
});
} }
@Test(expected = IllegalStateException.class) @Test
public void textNoChallengeFails2() { public void textNoChallengeFails2() {
assertThrows(IllegalStateException.class, () -> {
EmailProcessor processor = new EmailProcessor(message); EmailProcessor processor = new EmailProcessor(message);
processor.getAuthorization(); processor.getAuthorization();
});
} }
@Test(expected = IllegalStateException.class) @Test
public void textNoChallengeFails3() { public void textNoChallengeFails3() {
assertThrows(IllegalStateException.class, () -> {
EmailProcessor processor = new EmailProcessor(message); EmailProcessor processor = new EmailProcessor(message);
processor.respond(); processor.respond();
});
} }
@Test @Test
@ -108,11 +123,13 @@ public class EmailProcessorTest extends SMIMETests {
assertThat(processor.respond(), is(notNullValue())); assertThat(processor.respond(), is(notNullValue()));
} }
@Test(expected = AcmeProtocolException.class) @Test
public void testChallengeMismatch() { public void testChallengeMismatch() {
assertThrows(AcmeProtocolException.class, () -> {
EmailReply00Challenge challenge = mockChallenge("emailReplyChallengeMismatch"); EmailReply00Challenge challenge = mockChallenge("emailReplyChallengeMismatch");
EmailProcessor processor = new EmailProcessor(message); EmailProcessor processor = new EmailProcessor(message);
processor.withChallenge(challenge); processor.withChallenge(challenge);
});
} }
@Test @Test

View File

@ -15,8 +15,7 @@ package org.shredzone.acme4j.util;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -24,6 +23,7 @@ import java.io.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.security.KeyPair; import java.security.KeyPair;
import java.security.Security; import java.security.Security;
import java.util.Arrays; import java.util.Arrays;
@ -45,8 +45,8 @@ import org.bouncycastle.openssl.PEMParser;
import org.bouncycastle.pkcs.PKCS10CertificationRequest; import org.bouncycastle.pkcs.PKCS10CertificationRequest;
import org.hamcrest.BaseMatcher; import org.hamcrest.BaseMatcher;
import org.hamcrest.Description; import org.hamcrest.Description;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.Identifier; import org.shredzone.acme4j.Identifier;
/** /**
@ -57,7 +57,7 @@ public class CSRBuilderTest {
private static KeyPair testKey; private static KeyPair testKey;
private static KeyPair testEcKey; private static KeyPair testEcKey;
@BeforeClass @BeforeAll
public static void setup() { public static void setup() {
Security.addProvider(new BouncyCastleProvider()); Security.addProvider(new BouncyCastleProvider());
@ -230,25 +230,29 @@ public class CSRBuilderTest {
builder.write(baos); builder.write(baos);
pemBytes = baos.toByteArray(); 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. * Make sure an exception is thrown when no domain is set.
*/ */
@Test(expected = IllegalStateException.class) @Test
public void testNoDomain() throws IOException { public void testNoDomain() throws IOException {
assertThrows(IllegalStateException.class, () -> {
CSRBuilder builder = new CSRBuilder(); CSRBuilder builder = new CSRBuilder();
builder.sign(testKey); builder.sign(testKey);
});
} }
/** /**
* Make sure an exception is thrown when an unknown identifier type is used. * Make sure an exception is thrown when an unknown identifier type is used.
*/ */
@Test(expected = IllegalArgumentException.class) @Test
public void testUnknownType() { public void testUnknownType() {
assertThrows(IllegalArgumentException.class, () -> {
CSRBuilder builder = new CSRBuilder(); CSRBuilder builder = new CSRBuilder();
builder.addIdentifier(new Identifier("UnKnOwN", "123")); builder.addIdentifier(new Identifier("UnKnOwN", "123"));
});
} }
/** /**
@ -258,13 +262,13 @@ public class CSRBuilderTest {
public void testNoSign() throws IOException { public void testNoSign() throws IOException {
CSRBuilder builder = new CSRBuilder(); CSRBuilder builder = new CSRBuilder();
assertThrows("getCSR()", IllegalStateException.class, builder::getCSR); assertThrows(IllegalStateException.class, builder::getCSR, "getCSR()");
assertThrows("getEncoded()", IllegalStateException.class, builder::getEncoded); assertThrows(IllegalStateException.class, builder::getEncoded, "getEncoded()");
assertThrows("write()", IllegalStateException.class, () -> { assertThrows(IllegalStateException.class, () -> {
try (StringWriter w = new StringWriter()) { try (StringWriter w = new StringWriter()) {
builder.write(w); builder.write(w);
}; }
}); }, "write()");
} }
/** /**

View File

@ -42,7 +42,7 @@ import org.bouncycastle.asn1.BERTags;
import org.bouncycastle.asn1.DEROctetString; import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.x509.GeneralName; import org.bouncycastle.asn1.x509.GeneralName;
import org.bouncycastle.pkcs.PKCS10CertificationRequest; import org.bouncycastle.pkcs.PKCS10CertificationRequest;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.Identifier; import org.shredzone.acme4j.Identifier;
import org.shredzone.acme4j.challenge.TlsAlpn01Challenge; import org.shredzone.acme4j.challenge.TlsAlpn01Challenge;
import org.shredzone.acme4j.toolbox.AcmeUtils; import org.shredzone.acme4j.toolbox.AcmeUtils;

View File

@ -27,8 +27,8 @@ import java.security.interfaces.ECPublicKey;
import java.security.interfaces.RSAPublicKey; import java.security.interfaces.RSAPublicKey;
import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Unit tests for {@link KeyPairUtils}. * Unit tests for {@link KeyPairUtils}.
@ -37,7 +37,7 @@ public class KeyPairUtilsTest {
private static final int KEY_SIZE = 2048; private static final int KEY_SIZE = 2048;
private static final String EC_CURVE = "secp256r1"; private static final String EC_CURVE = "secp256r1";
@BeforeClass @BeforeAll
public static void setup() { public static void setup() {
Security.addProvider(new BouncyCastleProvider()); Security.addProvider(new BouncyCastleProvider());
} }

View File

@ -119,7 +119,7 @@
<configuration combine.children="append"> <configuration combine.children="append">
<parallel>classes</parallel> <parallel>classes</parallel>
<threadCount>10</threadCount> <threadCount>10</threadCount>
<excludedGroups>java.net.HttpURLConnection</excludedGroups> <excludedGroups>requires-network</excludedGroups>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
@ -203,9 +203,9 @@
</exclusions> </exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit</artifactId> <artifactId>junit-jupiter-api</artifactId>
<version>4.13.2</version> <version>5.8.2</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>