Use Assertj instead of Hamcrest

This commit is contained in:
Richard Körber
2022-05-14 12:39:27 +02:00
parent f3c7e8a46c
commit a25b8c1b8d
53 changed files with 1382 additions and 1561 deletions

View File

@@ -14,9 +14,8 @@
package org.shredzone.acme4j.it.boulder;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import java.net.URI;
import java.security.KeyPair;
@@ -67,7 +66,7 @@ public class OrderHttpIT {
for (Authorization auth : order.getAuthorizations()) {
Http01Challenge challenge = auth.findChallenge(Http01Challenge.TYPE);
assertThat(challenge, is(notNullValue()));
assertThat(challenge).isNotNull();
client.httpAddToken(challenge.getToken(), challenge.getAuthorization());
@@ -77,9 +76,9 @@ public class OrderHttpIT {
.pollInterval(1, SECONDS)
.timeout(30, SECONDS)
.conditionEvaluationListener(cond -> updateAuth(auth))
.until(auth::getStatus, not(oneOf(Status.PENDING, Status.PROCESSING)));
.untilAsserted(() -> assertThat(auth.getStatus()).isNotIn(Status.PENDING, Status.PROCESSING));
assertThat(auth.getStatus(), is(Status.VALID));
assertThat(auth.getStatus()).isEqualTo(Status.VALID);
client.httpRemoveToken(challenge.getToken());
}
@@ -95,14 +94,14 @@ public class OrderHttpIT {
.pollInterval(1, SECONDS)
.timeout(30, SECONDS)
.conditionEvaluationListener(cond -> updateOrder(order))
.until(order::getStatus, not(oneOf(Status.PENDING, Status.PROCESSING)));
.untilAsserted(() -> assertThat(order.getStatus()).isNotIn(Status.PENDING, Status.PROCESSING));
Certificate certificate = order.getCertificate();
X509Certificate cert = certificate.getCertificate();
assertThat(cert, not(nullValue()));
assertThat(cert.getNotAfter(), not(nullValue()));
assertThat(cert.getNotBefore(), not(nullValue()));
assertThat(cert.getSubjectX500Principal().getName(), containsString("CN=" + TEST_DOMAIN));
assertThat(cert).isNotNull();
assertThat(cert.getNotAfter()).isNotNull();
assertThat(cert.getNotBefore()).isNotNull();
assertThat(cert.getSubjectX500Principal().getName()).contains("CN=" + TEST_DOMAIN);
}
/**

View File

@@ -13,9 +13,7 @@
*/
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.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.net.URI;
@@ -57,18 +55,18 @@ public class AccountIT extends PebbleITBase {
// Check registered data
Account acct = login.getAccount();
assertThat(acct.getLocation(), is(location));
assertThat(acct.getContacts(), contains(URI.create("mailto:acme@example.com")));
assertThat(acct.getStatus(), is(Status.VALID));
assertThat(acct.getLocation()).isEqualTo(location);
assertThat(acct.getContacts()).contains(URI.create("mailto:acme@example.com"));
assertThat(acct.getStatus()).isEqualTo(Status.VALID);
// Bind another Account object
Session session2 = new Session(pebbleURI());
Login login2 = new Login(location, keyPair, session2);
assertThat(login2.getAccountLocation(), is(location));
assertThat(login2.getAccountLocation()).isEqualTo(location);
Account acct2 = login2.getAccount();
assertThat(acct2.getLocation(), is(location));
assertThat(acct2.getContacts(), contains(URI.create("mailto:acme@example.com")));
assertThat(acct2.getStatus(), is(Status.VALID));
assertThat(acct2.getLocation()).isEqualTo(location);
assertThat(acct2.getContacts()).contains(URI.create("mailto:acme@example.com"));
assertThat(acct2.getStatus()).isEqualTo(Status.VALID);
}
/**
@@ -100,7 +98,7 @@ public class AccountIT extends PebbleITBase {
URL location2 = login2.getAccountLocation();
assertIsPebbleUrl(location2);
assertThat(location1, is(location2));
assertThat(location1).isEqualTo(location2);
}
/**
@@ -128,7 +126,7 @@ public class AccountIT extends PebbleITBase {
URL location2 = login2.getAccountLocation();
assertIsPebbleUrl(location2);
assertThat(location1, is(location2));
assertThat(location1).isEqualTo(location2);
}
/**
@@ -142,7 +140,7 @@ public class AccountIT extends PebbleITBase {
Session session = new Session(pebbleURI());
new AccountBuilder().onlyExisting().useKeyPair(keyPair).create(session);
});
assertThat(ex.getType(), is(URI.create("urn:ietf:params:acme:error:accountDoesNotExist")));
assertThat(ex.getType()).isEqualTo(URI.create("urn:ietf:params:acme:error:accountDoesNotExist"));
}
/**
@@ -163,15 +161,15 @@ public class AccountIT extends PebbleITBase {
acct.modify().addContact("mailto:acme2@example.com").commit();
assertThat(acct.getContacts(), contains(
assertThat(acct.getContacts()).contains(
URI.create("mailto:acme@example.com"),
URI.create("mailto:acme2@example.com")));
URI.create("mailto:acme2@example.com"));
// Still the same after updating
acct.update();
assertThat(acct.getContacts(), contains(
assertThat(acct.getContacts()).contains(
URI.create("mailto:acme@example.com"),
URI.create("mailto:acme2@example.com")));
URI.create("mailto:acme2@example.com"));
}
/**
@@ -199,7 +197,7 @@ public class AccountIT extends PebbleITBase {
Session sessionNewKey = new Session(pebbleURI());
Account newAccount = sessionNewKey.login(location, newKeyPair).getAccount();
assertThat(newAccount.getStatus(), is(Status.VALID));
assertThat(newAccount.getStatus()).isEqualTo(Status.VALID);
}
/**
@@ -219,7 +217,7 @@ public class AccountIT extends PebbleITBase {
acct.deactivate();
// Make sure it is deactivated now...
assertThat(acct.getStatus(), is(Status.DEACTIVATED));
assertThat(acct.getStatus()).isEqualTo(Status.DEACTIVATED);
// Make sure account cannot be accessed any more...
AcmeUnauthorizedException ex = assertThrows(AcmeUnauthorizedException.class,
@@ -228,7 +226,7 @@ public class AccountIT extends PebbleITBase {
Account acct2 = session2.login(location, keyPair).getAccount();
acct2.update();
}, "Account can still be accessed");
assertThat(ex.getMessage(), is("Account has been deactivated"));
assertThat(ex.getMessage()).isEqualTo("Account has been deactivated");
}
}

View File

@@ -14,9 +14,8 @@
package org.shredzone.acme4j.it.pebble;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.net.URI;
@@ -61,7 +60,7 @@ public class OrderIT extends PebbleITBase {
BammBammClient client = getBammBammClient();
Http01Challenge challenge = auth.findChallenge(Http01Challenge.TYPE);
assertThat(challenge, is(notNullValue()));
assertThat(challenge).isNotNull();
client.httpAddToken(challenge.getToken(), challenge.getAuthorization());
@@ -80,7 +79,7 @@ public class OrderIT extends PebbleITBase {
BammBammClient client = getBammBammClient();
Dns01Challenge challenge = auth.findChallenge(Dns01Challenge.TYPE);
assertThat(challenge, is(notNullValue()));
assertThat(challenge).isNotNull();
String challengeDomainName = "_acme-challenge." + auth.getIdentifier().getDomain();
@@ -101,7 +100,7 @@ public class OrderIT extends PebbleITBase {
BammBammClient client = getBammBammClient();
TlsAlpn01Challenge challenge = auth.findChallenge(TlsAlpn01Challenge.TYPE);
assertThat(challenge, is(notNullValue()));
assertThat(challenge).isNotNull();
client.tlsAlpnAddCertificate(
auth.getIdentifier().getDomain(),
@@ -122,7 +121,7 @@ public class OrderIT extends PebbleITBase {
BammBammClient client = getBammBammClient();
Http01Challenge challenge = auth.findChallenge(Http01Challenge.TYPE);
assertThat(challenge, is(notNullValue()));
assertThat(challenge).isNotNull();
client.httpAddToken(challenge.getToken(), challenge.getAuthorization());
@@ -163,13 +162,13 @@ public class OrderIT extends PebbleITBase {
.notBefore(notBefore)
.notAfter(notAfter)
.create();
assertThat(order.getNotBefore(), is(notBefore));
assertThat(order.getNotAfter(), is(notAfter));
assertThat(order.getStatus(), is(Status.PENDING));
assertThat(order.getNotBefore()).isEqualTo(notBefore);
assertThat(order.getNotAfter()).isEqualTo(notAfter);
assertThat(order.getStatus()).isEqualTo(Status.PENDING);
for (Authorization auth : order.getAuthorizations()) {
assertThat(auth.getIdentifier().getDomain(), is(domain));
assertThat(auth.getStatus(), is(Status.PENDING));
assertThat(auth.getIdentifier().getDomain()).isEqualTo(domain);
assertThat(auth.getStatus()).isEqualTo(Status.PENDING);
if (auth.getStatus() == Status.VALID) {
continue;
@@ -182,9 +181,9 @@ public class OrderIT extends PebbleITBase {
.pollInterval(1, SECONDS)
.timeout(30, SECONDS)
.conditionEvaluationListener(cond -> updateAuth(auth))
.until(auth::getStatus, not(oneOf(Status.PENDING, Status.PROCESSING)));
.untilAsserted(() -> assertThat(auth.getStatus()).isNotIn(Status.PENDING, Status.PROCESSING));
assertThat(auth.getStatus(), is(Status.VALID));
assertThat(auth.getStatus()).isEqualTo(Status.VALID);
}
CSRBuilder csr = new CSRBuilder();
@@ -198,21 +197,22 @@ public class OrderIT extends PebbleITBase {
.pollInterval(1, SECONDS)
.timeout(30, SECONDS)
.conditionEvaluationListener(cond -> updateOrder(order))
.until(order::getStatus, not(oneOf(Status.PENDING, Status.PROCESSING, Status.READY)));
.untilAsserted(() -> assertThat(order.getStatus())
.isNotIn(Status.PENDING, Status.PROCESSING, Status.READY));
assertThat(order.getStatus(), is(Status.VALID));
assertThat(order.getStatus()).isEqualTo(Status.VALID);
Certificate certificate = order.getCertificate();
X509Certificate cert = certificate.getCertificate();
assertThat(cert, not(nullValue()));
assertThat(cert.getNotBefore().toInstant(), is(notBefore));
assertThat(cert.getNotAfter().toInstant(), is(notAfter));
assertThat(cert.getSubjectX500Principal().getName(), containsString("CN=" + domain));
assertThat(cert).isNotNull();
assertThat(cert.getNotBefore().toInstant()).isEqualTo(notBefore);
assertThat(cert.getNotAfter().toInstant()).isEqualTo(notAfter);
assertThat(cert.getSubjectX500Principal().getName()).contains("CN=" + domain);
for (Authorization auth : order.getAuthorizations()) {
assertThat(auth.getStatus(), is(Status.VALID));
assertThat(auth.getStatus()).isEqualTo(Status.VALID);
auth.deactivate();
assertThat(auth.getStatus(), is(Status.DEACTIVATED));
assertThat(auth.getStatus()).isEqualTo(Status.DEACTIVATED);
}
revoker.revoke(session, certificate, keyPair, domainKeyPair);
@@ -223,13 +223,13 @@ public class OrderIT extends PebbleITBase {
Certificate cert2 = login2.bindCertificate(certificate.getLocation());
cert2.download();
}, "Could download revoked cert");
assertThat(ex.getMessage(), is("HTTP 404: Not Found"));
assertThat(ex.getMessage()).isEqualTo("HTTP 404: Not Found");
// Try to revoke again
AcmeServerException ex2 = assertThrows(AcmeServerException.class,
() -> certificate.revoke(),
"Could revoke again");
assertThat(ex2.getProblem().getType(), is(URI.create("urn:ietf:params:acme:error:alreadyRevoked")));
assertThat(ex2.getProblem().getType()).isEqualTo(URI.create("urn:ietf:params:acme:error:alreadyRevoked"));
}
/**

View File

@@ -15,9 +15,8 @@ package org.shredzone.acme4j.it.pebble;
import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import java.security.KeyPair;
import java.security.cert.X509Certificate;
@@ -73,20 +72,20 @@ public class OrderWildcardIT extends PebbleITBase {
.notBefore(notBefore)
.notAfter(notAfter)
.create();
assertThat(order.getNotBefore(), is(notBefore));
assertThat(order.getNotAfter(), is(notAfter));
assertThat(order.getStatus(), is(Status.PENDING));
assertThat(order.getNotBefore()).isEqualTo(notBefore);
assertThat(order.getNotAfter()).isEqualTo(notAfter);
assertThat(order.getStatus()).isEqualTo(Status.PENDING);
for (Authorization auth : order.getAuthorizations()) {
assertThat(auth.getIdentifier().getDomain(), is(TEST_DOMAIN));
assertThat(auth.getStatus(), is(Status.PENDING));
assertThat(auth.getIdentifier().getDomain()).isEqualTo(TEST_DOMAIN);
assertThat(auth.getStatus()).isEqualTo(Status.PENDING);
if (auth.getStatus() == Status.VALID) {
continue;
}
Dns01Challenge challenge = auth.findChallenge(Dns01Challenge.TYPE);
assertThat(challenge, is(notNullValue()));
assertThat(challenge).isNotNull();
String challengeDomainName = "_acme-challenge." + TEST_DOMAIN;
@@ -99,9 +98,10 @@ public class OrderWildcardIT extends PebbleITBase {
.pollInterval(1, SECONDS)
.timeout(30, SECONDS)
.conditionEvaluationListener(cond -> updateAuth(auth))
.until(auth::getStatus, not(oneOf(Status.PENDING, Status.PROCESSING)));
.untilAsserted(() -> assertThat(
auth.getStatus()).isNotIn(Status.PENDING, Status.PROCESSING));
assertThat(auth.getStatus(), is(Status.VALID));
assertThat(auth.getStatus()).isEqualTo(Status.VALID);
}
CSRBuilder csr = new CSRBuilder();
@@ -116,21 +116,22 @@ public class OrderWildcardIT extends PebbleITBase {
.pollInterval(1, SECONDS)
.timeout(30, SECONDS)
.conditionEvaluationListener(cond -> updateOrder(order))
.until(order::getStatus, not(oneOf(Status.PENDING, Status.PROCESSING)));
.untilAsserted(() -> assertThat(
order.getStatus()).isNotIn(Status.PENDING, Status.PROCESSING));
Certificate certificate = order.getCertificate();
X509Certificate cert = certificate.getCertificate();
assertThat(cert, not(nullValue()));
assertThat(cert.getNotAfter(), not(notBefore));
assertThat(cert.getNotBefore(), not(notAfter));
assertThat(cert.getSubjectX500Principal().getName(), containsString("CN=" + TEST_DOMAIN));
assertThat(cert).isNotNull();
assertThat(cert.getNotAfter()).isNotEqualTo(notBefore);
assertThat(cert.getNotBefore()).isNotEqualTo(notAfter);
assertThat(cert.getSubjectX500Principal().getName()).contains("CN=" + TEST_DOMAIN);
List<String> san = cert.getSubjectAlternativeNames().stream()
.filter(it -> ((Number) it.get(0)).intValue() == GeneralName.dNSName)
.map(it -> (String) it.get(1))
.collect(toList());
assertThat(san, contains(TEST_DOMAIN, TEST_WILDCARD_DOMAIN));
assertThat(san).contains(TEST_DOMAIN, TEST_WILDCARD_DOMAIN);
}
}

View File

@@ -13,8 +13,7 @@
*/
package org.shredzone.acme4j.it.pebble;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.assertj.core.api.Assertions.assertThat;
import java.net.URI;
import java.net.URL;
@@ -97,11 +96,11 @@ public abstract class PebbleITBase {
* {@link URL} to assert
*/
protected void assertIsPebbleUrl(URL url) {
assertThat(url, not(nullValue()));
assertThat(url.getProtocol(), is("https"));
assertThat(url.getHost(), is(pebbleHost));
assertThat(url.getPort(), is(pebblePort));
assertThat(url.getPath(), not(emptyOrNullString()));
assertThat(url).isNotNull();
assertThat(url.getProtocol()).isEqualTo("https");
assertThat(url.getHost()).isEqualTo(pebbleHost);
assertThat(url.getPort()).isEqualTo(pebblePort);
assertThat(url.getPath()).isNotEmpty();
}
/**

View File

@@ -13,9 +13,8 @@
*/
package org.shredzone.acme4j.it.pebble;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs;
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
import static org.assertj.core.api.Assertions.assertThat;
import java.net.URI;
@@ -44,15 +43,15 @@ public class SessionIT extends PebbleITBase {
Session session = new Session(pebbleURI());
Metadata meta = session.getMetadata();
assertThat(meta, not(nullValue()));
assertThat(meta).isNotNull();
assertThat(meta.getTermsOfService(), is(URI.create("data:text/plain,Do%20what%20thou%20wilt")));
assertThat(meta.getWebsite(), is(nullValue()));
assertThat(meta.getCaaIdentities(), is(empty()));
assertThat(meta.getJSON().toString(), sameJSONAs("{"
assertThat(meta.getTermsOfService()).isEqualTo(URI.create("data:text/plain,Do%20what%20thou%20wilt"));
assertThat(meta.getWebsite()).isNull();
assertThat(meta.getCaaIdentities()).isEmpty();
assertThatJson(meta.getJSON().toString()).isEqualTo("{"
+ "'termsOfService': 'data:text/plain,Do%20what%20thou%20wilt',"
+ "'externalAccountRequired': false"
+ "}"));
+ "}");
}
}