Fix unit tests for Java 9

pull/55/head
Richard Körber 2017-10-07 18:08:04 +02:00
parent 148c98d673
commit 2a5075dd5a
3 changed files with 7 additions and 17 deletions

View File

@ -29,6 +29,7 @@ import java.net.URL;
import java.security.cert.X509Certificate;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@ -313,7 +314,7 @@ public class DefaultConnectionTest {
*/
@Test
public void testHandleRetryAfterHeaderDate() throws AcmeException, IOException {
Instant retryDate = Instant.now().plus(Duration.ofHours(10));
Instant retryDate = Instant.now().plus(Duration.ofHours(10)).truncatedTo(ChronoUnit.MILLIS);
String retryMsg = "absolute date";
when(mockUrlConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK);
@ -490,7 +491,7 @@ public class DefaultConnectionTest {
Map<String, List<String>> linkHeader = new HashMap<>();
linkHeader.put("Link", Arrays.asList("<https://example.com/rates.pdf>; rel=\"urn:ietf:params:acme:documentation\""));
Instant retryAfter = Instant.now().plusSeconds(30L);
Instant retryAfter = Instant.now().plusSeconds(30L).truncatedTo(ChronoUnit.MILLIS);
when(mockUrlConnection.getHeaderField("Content-Type")).thenReturn("application/problem+json");
when(mockUrlConnection.getHeaderField("Retry-After")).thenReturn(retryAfter.toString());

View File

@ -37,8 +37,6 @@ import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import javax.xml.bind.DatatypeConverter;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
@ -68,20 +66,10 @@ public class AcmeUtilsTest {
}
/**
* Test sha-256 hash.
* Test sha-256 hash and hex encode.
*/
@Test
public void testSha256Hash() {
byte[] hash = sha256hash("foobar");
byte[] expected = DatatypeConverter.parseHexBinary("c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2");
assertThat(hash, is(expected));
}
/**
* Test hex encode.
*/
@Test
public void testHexEncode() {
public void testSha256HashHexEncode() {
String hexEncode = hexEncode(sha256hash("foobar"));
assertThat(hexEncode, is("c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2"));
}

View File

@ -22,6 +22,7 @@ import java.security.KeyPair;
import java.security.cert.X509Certificate;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import org.junit.Test;
import org.shredzone.acme4j.Account;
@ -138,7 +139,7 @@ public class OrderIT extends PebbleITBase {
csr.sign(domainKeyPair);
byte[] encodedCsr = csr.getEncoded();
Instant notBefore = Instant.now();
Instant notBefore = Instant.now().truncatedTo(ChronoUnit.MILLIS);
Instant notAfter = notBefore.plus(Duration.ofDays(20L));
Order order = account.orderCertificate(encodedCsr, notBefore, notAfter);