From 6186552af6f609bf57a9755470f586b2f1a2bbd1 Mon Sep 17 00:00:00 2001 From: Mats Stijlaart Date: Tue, 25 Oct 2016 10:09:02 +0200 Subject: [PATCH] Be less strict about datetime of created payments, due to mismatch test machine and mollie instance --- .../java/nl/stil4m/mollie/ClientIntegrationTest.java | 4 ++-- .../nl/stil4m/mollie/DynamicClientIntegrationTest.java | 10 +++++----- .../domain/subpayments/CreateIdealPaymentTest.java | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java b/src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java index c5d1592..285752b 100644 --- a/src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java +++ b/src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java @@ -45,7 +45,7 @@ public void testCreatePayment() throws IOException, InterruptedException { Date beforeTest = new Date(); ResponseOrError payment = client.payments().create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null)); - DynamicClientIntegrationTest.assertWithin(beforeTest, payment.getData().getCreatedDatetime(), new Date()); + DynamicClientIntegrationTest.assertWithin(beforeTest, payment.getData().getCreatedDatetime(), new Date(), 5000L); } @Test @@ -58,7 +58,7 @@ public void testCreateIdealPayment() throws IOException, URISyntaxException, Int ResponseOrError payment = client.payments().create(new CreateIdealPayment(1.00, "Some description", "http://example.com", Optional.empty(), null, new IdealPaymentOptions(issuer.getId()))); assertThat(payment.getSuccess(), is(true)); - DynamicClientIntegrationTest.assertWithin(beforeTest, payment.getData().getCreatedDatetime(), new Date()); + DynamicClientIntegrationTest.assertWithin(beforeTest, payment.getData().getCreatedDatetime(), new Date(), 5000L); } @Test diff --git a/src/test/java/nl/stil4m/mollie/DynamicClientIntegrationTest.java b/src/test/java/nl/stil4m/mollie/DynamicClientIntegrationTest.java index f449809..e7e2317 100644 --- a/src/test/java/nl/stil4m/mollie/DynamicClientIntegrationTest.java +++ b/src/test/java/nl/stil4m/mollie/DynamicClientIntegrationTest.java @@ -53,7 +53,7 @@ public void testCreatePayment() throws IOException { ResponseOrError payment = client.payments(VALID_API_KEY).create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), meta)); CreatedPayment createdPayment = payment.getData(); - assertWithin(beforeTest, createdPayment.getCreatedDatetime(), new Date()); + assertWithin(beforeTest, createdPayment.getCreatedDatetime(), new Date(), 5000L); assertThat(createdPayment.getMethod(), is(nullValue())); assertThat(createdPayment.getAmount(), is(1.00)); @@ -78,7 +78,7 @@ public void testCreatePaymentWithMethod() throws IOException { ResponseOrError payment = client.payments(VALID_API_KEY).create(new CreatePayment(Optional.of("ideal"), 1.00, "Some description", "http://example.com", Optional.empty(), meta)); CreatedPayment createdPayment = payment.getData(); - assertWithin(beforeTest, createdPayment.getCreatedDatetime(), new Date()); + assertWithin(beforeTest, createdPayment.getCreatedDatetime(), new Date(), 5000L); assertThat(createdPayment.getMethod(), is("ideal")); assertThat(createdPayment.getAmount(), is(1.00)); @@ -144,9 +144,9 @@ public void testCreateAndGetCreditCardPayment() throws IOException { } - public static void assertWithin(Date before, Date target, Date after) { - long beforeTime = before.getTime() - (before.getTime() % 1000) - 1000; //Subtract another 1000 just to be safe - long afterTime = after.getTime() - (after.getTime() % 1000) + 1000; + public static void assertWithin(Date before, Date target, Date after, Long additionalSpan) { + long beforeTime = before.getTime() - (before.getTime() % 1000) - additionalSpan; + long afterTime = after.getTime() - (after.getTime() % 1000) + additionalSpan; assertThat(beforeTime <= target.getTime(), is(true)); assertThat(target.getTime() <= afterTime, is(true)); } diff --git a/src/test/java/nl/stil4m/mollie/domain/subpayments/CreateIdealPaymentTest.java b/src/test/java/nl/stil4m/mollie/domain/subpayments/CreateIdealPaymentTest.java index 7e2b00a..c100ea0 100644 --- a/src/test/java/nl/stil4m/mollie/domain/subpayments/CreateIdealPaymentTest.java +++ b/src/test/java/nl/stil4m/mollie/domain/subpayments/CreateIdealPaymentTest.java @@ -23,6 +23,7 @@ public class CreateIdealPaymentTest { public void before() throws InterruptedException { Thread.sleep(TEST_TIMEOUT); } + @Test public void testSerialize() throws IOException { ObjectMapper objectMapper = new ObjectMapper();