From 1e43da11990ddb988e819ca6ed8d392c95c385df Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michae=CC=88l=20van=20de=20Giessen?= <mg@smile.nl>
Date: Fri, 28 Oct 2016 09:03:18 +0200
Subject: [PATCH 01/11] #24 - moved assertWithin to TestUtil

---
 .../java/nl/stil4m/mollie/ClientIntegrationTest.java |  5 +++--
 .../stil4m/mollie/DynamicClientIntegrationTest.java  |  9 +--------
 src/test/java/nl/stil4m/mollie/TestUtil.java         | 12 ++++++++++++
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java b/src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java
index 2b47b92..c1256e6 100644
--- a/src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java
+++ b/src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java
@@ -24,6 +24,7 @@
 
 import static nl.stil4m.mollie.TestUtil.TEST_TIMEOUT;
 import static nl.stil4m.mollie.TestUtil.VALID_API_KEY;
+import static nl.stil4m.mollie.TestUtil.assertWithin;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.notNullValue;
@@ -44,7 +45,7 @@ public void testCreatePayment() throws IOException, InterruptedException {
         Date beforeTest = new Date();
         ResponseOrError<CreatedPayment> 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(), 5000L);
+        assertWithin(beforeTest, payment.getData().getCreatedDatetime(), new Date(), 5000L);
     }
 
     @Test
@@ -57,7 +58,7 @@ public void testCreateIdealPayment() throws IOException, URISyntaxException, Int
         ResponseOrError<CreatedPayment> 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(), 5000L);
+        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 e7e2317..0d02161 100644
--- a/src/test/java/nl/stil4m/mollie/DynamicClientIntegrationTest.java
+++ b/src/test/java/nl/stil4m/mollie/DynamicClientIntegrationTest.java
@@ -17,6 +17,7 @@
 
 import static nl.stil4m.mollie.TestUtil.TEST_TIMEOUT;
 import static nl.stil4m.mollie.TestUtil.VALID_API_KEY;
+import static nl.stil4m.mollie.TestUtil.assertWithin;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.notNullValue;
@@ -143,14 +144,6 @@ public void testCreateAndGetCreditCardPayment() throws IOException {
 
     }
 
-
-    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));
-    }
-
     @Test
     public void testGetPayment() throws IOException {
         ResponseOrError<CreatedPayment> payment = client.payments(VALID_API_KEY).create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null));
diff --git a/src/test/java/nl/stil4m/mollie/TestUtil.java b/src/test/java/nl/stil4m/mollie/TestUtil.java
index b0ce5c2..5b3fb8b 100644
--- a/src/test/java/nl/stil4m/mollie/TestUtil.java
+++ b/src/test/java/nl/stil4m/mollie/TestUtil.java
@@ -1,8 +1,20 @@
 package nl.stil4m.mollie;
 
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+import java.util.Date;
+
 public class TestUtil {
 
     public static final String VALID_API_KEY = "test_35Rjpa5ETePvpeQVU2JQEwzuNyq8BA";
 
     public static final Long TEST_TIMEOUT = 2000L;
+    
+    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));
+    }
 }

From 90aea4498270c758a46bd7a1c662eea09473d47c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michae=CC=88l=20van=20de=20Giessen?= <mg@smile.nl>
Date: Fri, 28 Oct 2016 09:09:45 +0200
Subject: [PATCH 02/11] #24 - assertWithin using standard junit api

added fail messages
hamcrest Matchers.is=deprecated?
---
 src/test/java/nl/stil4m/mollie/TestUtil.java | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/test/java/nl/stil4m/mollie/TestUtil.java b/src/test/java/nl/stil4m/mollie/TestUtil.java
index 5b3fb8b..0d5c38b 100644
--- a/src/test/java/nl/stil4m/mollie/TestUtil.java
+++ b/src/test/java/nl/stil4m/mollie/TestUtil.java
@@ -1,10 +1,9 @@
 package nl.stil4m.mollie;
 
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-
 import java.util.Date;
 
+import static org.junit.Assert.assertTrue;
+
 public class TestUtil {
 
     public static final String VALID_API_KEY = "test_35Rjpa5ETePvpeQVU2JQEwzuNyq8BA";
@@ -14,7 +13,8 @@ public class TestUtil {
     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));
+        
+        assertTrue(target+" expected to be after "+new Date(beforeTime),beforeTime <= target.getTime());
+        assertTrue(target+" expected to be before "+new Date(afterTime),target.getTime() <= afterTime);
     }
 }

From ef6dd1cc1090679709163ea3ec9a8b74a2815aa8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michae=CC=88l=20van=20de=20Giessen?= <mg@smile.nl>
Date: Fri, 28 Oct 2016 09:28:28 +0200
Subject: [PATCH 03/11] unused imports

---
 src/main/java/nl/stil4m/mollie/concepts/Customers.java    | 1 -
 src/main/java/nl/stil4m/mollie/domain/CreateCustomer.java | 2 --
 2 files changed, 3 deletions(-)

diff --git a/src/main/java/nl/stil4m/mollie/concepts/Customers.java b/src/main/java/nl/stil4m/mollie/concepts/Customers.java
index 5c9183b..0045efc 100644
--- a/src/main/java/nl/stil4m/mollie/concepts/Customers.java
+++ b/src/main/java/nl/stil4m/mollie/concepts/Customers.java
@@ -9,7 +9,6 @@
 import nl.stil4m.mollie.domain.UpdateCustomer;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.methods.HttpPut;
 import org.apache.http.client.utils.URIBuilder;
 import org.apache.http.entity.ContentType;
 import org.apache.http.entity.StringEntity;
diff --git a/src/main/java/nl/stil4m/mollie/domain/CreateCustomer.java b/src/main/java/nl/stil4m/mollie/domain/CreateCustomer.java
index 870465e..91f29fb 100644
--- a/src/main/java/nl/stil4m/mollie/domain/CreateCustomer.java
+++ b/src/main/java/nl/stil4m/mollie/domain/CreateCustomer.java
@@ -2,8 +2,6 @@
 
 import com.fasterxml.jackson.annotation.JsonProperty;
 
-import java.util.Date;
-import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 

From 2844b862e6fff6ac0f02be6d47dcf30001fab060 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michae=CC=88l=20van=20de=20Giessen?= <mg@smile.nl>
Date: Fri, 28 Oct 2016 09:29:45 +0200
Subject: [PATCH 04/11] #24 - moved Payments integration tests to
 PaymentsIntegrationTest

---
 .../stil4m/mollie/ClientIntegrationTest.java  | 65 -------------
 .../concepts/PaymentsIntegrationTest.java     | 96 +++++++++++++++++++
 2 files changed, 96 insertions(+), 65 deletions(-)
 create mode 100644 src/test/java/nl/stil4m/mollie/concepts/PaymentsIntegrationTest.java

diff --git a/src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java b/src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java
index c1256e6..6a2823d 100644
--- a/src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java
+++ b/src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java
@@ -6,16 +6,12 @@
 import nl.stil4m.mollie.domain.Issuer;
 import nl.stil4m.mollie.domain.Method;
 import nl.stil4m.mollie.domain.Page;
-import nl.stil4m.mollie.domain.Payment;
 import nl.stil4m.mollie.domain.Refund;
-import nl.stil4m.mollie.domain.subpayments.ideal.CreateIdealPayment;
-import nl.stil4m.mollie.domain.subpayments.ideal.IdealPaymentOptions;
 import org.junit.Before;
 import org.junit.Test;
 
 import java.io.IOException;
 import java.net.URISyntaxException;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Optional;
@@ -24,11 +20,9 @@
 
 import static nl.stil4m.mollie.TestUtil.TEST_TIMEOUT;
 import static nl.stil4m.mollie.TestUtil.VALID_API_KEY;
-import static nl.stil4m.mollie.TestUtil.assertWithin;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.notNullValue;
-import static org.junit.Assert.fail;
 
 public class ClientIntegrationTest {
 
@@ -40,65 +34,6 @@ public void before() throws InterruptedException {
         client = new ClientBuilder().withApiKey(VALID_API_KEY).build();
     }
 
-    @Test
-    public void testCreatePayment() throws IOException, InterruptedException {
-        Date beforeTest = new Date();
-        ResponseOrError<CreatedPayment> payment = client.payments().create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null));
-
-        assertWithin(beforeTest, payment.getData().getCreatedDatetime(), new Date(), 5000L);
-    }
-
-    @Test
-    public void testCreateIdealPayment() throws IOException, URISyntaxException, InterruptedException {
-        Date beforeTest = new Date();
-        ResponseOrError<Page<Issuer>> all = client.issuers().all(Optional.empty(), Optional.empty());
-        assertThat(all.getSuccess(), is(true));
-        Issuer issuer = all.getData().getData().get(0);
-
-        ResponseOrError<CreatedPayment> 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));
-        assertWithin(beforeTest, payment.getData().getCreatedDatetime(), new Date(), 5000L);
-    }
-
-    @Test
-    public void testGetPayment() throws IOException, InterruptedException {
-        ResponseOrError<CreatedPayment> payment = client.payments().create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null));
-        String id = payment.getData().getId();
-
-        ResponseOrError<Payment> paymentStatus = client.payments().get(id);
-        assertThat(paymentStatus.getData().getStatus(), is("open"));
-    }
-
-    @Test
-    public void testGetPaymentWithRefunds() throws IOException, InterruptedException {
-        ResponseOrError<Payment> getResponse = client.payments().get("tr_3AdTKpQGii");
-
-        getResponse.get(payment -> assertThat(payment.getLinks().getRefunds().isPresent(), is(true)), errorData -> System.out.println());
-
-    }
-
-
-    @Test
-    public void testGetPaymentWithEmptyId() throws IOException, InterruptedException {
-        try {
-            client.payments().get("");
-            fail();
-        } catch (IllegalArgumentException e) {
-            assertThat(e.getMessage(), is("Payment id may not be an empty string"));
-        }
-    }
-
-    @Test
-    public void testGetPaymentWithNullId() throws IOException, InterruptedException {
-        try {
-            client.payments().get(null);
-            fail();
-        } catch (IllegalArgumentException e) {
-            assertThat(e.getMessage(), is("Payment id may not be null"));
-        }
-    }
-
     @Test
     public void testGetMethods() throws IOException, URISyntaxException, InterruptedException {
         ResponseOrError<Page<Method>> allResponse = client.methods().all(Optional.empty(), Optional.empty());
diff --git a/src/test/java/nl/stil4m/mollie/concepts/PaymentsIntegrationTest.java b/src/test/java/nl/stil4m/mollie/concepts/PaymentsIntegrationTest.java
new file mode 100644
index 0000000..861702d
--- /dev/null
+++ b/src/test/java/nl/stil4m/mollie/concepts/PaymentsIntegrationTest.java
@@ -0,0 +1,96 @@
+package nl.stil4m.mollie.concepts;
+
+import static nl.stil4m.mollie.TestUtil.TEST_TIMEOUT;
+import static nl.stil4m.mollie.TestUtil.VALID_API_KEY;
+import static nl.stil4m.mollie.TestUtil.assertWithin;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Date;
+import java.util.Optional;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import nl.stil4m.mollie.Client;
+import nl.stil4m.mollie.ClientBuilder;
+import nl.stil4m.mollie.ResponseOrError;
+import nl.stil4m.mollie.domain.CreatePayment;
+import nl.stil4m.mollie.domain.CreatedPayment;
+import nl.stil4m.mollie.domain.Issuer;
+import nl.stil4m.mollie.domain.Page;
+import nl.stil4m.mollie.domain.Payment;
+import nl.stil4m.mollie.domain.subpayments.ideal.CreateIdealPayment;
+import nl.stil4m.mollie.domain.subpayments.ideal.IdealPaymentOptions;
+
+public class PaymentsIntegrationTest {
+    
+    private Client client;
+
+    @Before
+    public void before() throws InterruptedException {
+        Thread.sleep(TEST_TIMEOUT);
+        client = new ClientBuilder().withApiKey(VALID_API_KEY).build();
+    }
+    
+    @Test
+    public void testCreatePayment() throws IOException, InterruptedException {
+        Date beforeTest = new Date();
+        ResponseOrError<CreatedPayment> payment = client.payments().create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null));
+
+        assertWithin(beforeTest, payment.getData().getCreatedDatetime(), new Date(), 5000L);
+    }
+
+    @Test
+    public void testCreateIdealPayment() throws IOException, URISyntaxException, InterruptedException {
+        Date beforeTest = new Date();
+        ResponseOrError<Page<Issuer>> all = client.issuers().all(Optional.empty(), Optional.empty());
+        assertThat(all.getSuccess(), is(true));
+        Issuer issuer = all.getData().getData().get(0);
+
+        ResponseOrError<CreatedPayment> 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));
+        assertWithin(beforeTest, payment.getData().getCreatedDatetime(), new Date(), 5000L);
+    }
+
+    @Test
+    public void testGetPayment() throws IOException, InterruptedException {
+        ResponseOrError<CreatedPayment> payment = client.payments().create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null));
+        String id = payment.getData().getId();
+
+        ResponseOrError<Payment> paymentStatus = client.payments().get(id);
+        assertThat(paymentStatus.getData().getStatus(), is("open"));
+    }
+
+    @Test
+    public void testGetPaymentWithRefunds() throws IOException, InterruptedException {
+        ResponseOrError<Payment> getResponse = client.payments().get("tr_3AdTKpQGii");
+
+        getResponse.get(payment -> assertThat(payment.getLinks().getRefunds().isPresent(), is(true)), errorData -> System.out.println());
+
+    }
+
+    @Test
+    public void testGetPaymentWithEmptyId() throws IOException, InterruptedException {
+        try {
+            client.payments().get("");
+            fail();
+        } catch (IllegalArgumentException e) {
+            assertThat(e.getMessage(), is("Payment id may not be an empty string"));
+        }
+    }
+
+    @Test
+    public void testGetPaymentWithNullId() throws IOException, InterruptedException {
+        try {
+            client.payments().get(null);
+            fail();
+        } catch (IllegalArgumentException e) {
+            assertThat(e.getMessage(), is("Payment id may not be null"));
+        }
+    }
+}

From e0a26b88dce5d2ab1a7b4e4a7d54d9357e39917e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michae=CC=88l=20van=20de=20Giessen?= <mg@smile.nl>
Date: Fri, 28 Oct 2016 09:32:19 +0200
Subject: [PATCH 05/11] #24 - moved Methods integration tests to
 MethodsIntegrationTest

---
 .../stil4m/mollie/ClientIntegrationTest.java  | 37 ----------
 .../concepts/MethodsIntegrationTest.java      | 72 +++++++++++++++++++
 2 files changed, 72 insertions(+), 37 deletions(-)
 create mode 100644 src/test/java/nl/stil4m/mollie/concepts/MethodsIntegrationTest.java

diff --git a/src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java b/src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java
index 6a2823d..2cc37ff 100644
--- a/src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java
+++ b/src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java
@@ -4,7 +4,6 @@
 import nl.stil4m.mollie.domain.CreatePayment;
 import nl.stil4m.mollie.domain.CreatedPayment;
 import nl.stil4m.mollie.domain.Issuer;
-import nl.stil4m.mollie.domain.Method;
 import nl.stil4m.mollie.domain.Page;
 import nl.stil4m.mollie.domain.Refund;
 import org.junit.Before;
@@ -34,42 +33,6 @@ public void before() throws InterruptedException {
         client = new ClientBuilder().withApiKey(VALID_API_KEY).build();
     }
 
-    @Test
-    public void testGetMethods() throws IOException, URISyntaxException, InterruptedException {
-        ResponseOrError<Page<Method>> allResponse = client.methods().all(Optional.empty(), Optional.empty());
-        assertThat(allResponse.getSuccess(), is(true));
-
-        Page<Method> all = allResponse.getData();
-        assertThat(all.getCount(), is(10));
-        assertThat(all.getOffset(), is(0));
-        assertThat(all.getLinks(), is(notNullValue()));
-
-        Set<String> identifiers = all.getData().stream().map(Method::getId).collect(Collectors.toSet());
-        assertThat(identifiers.containsAll(Sets.newHashSet("ideal", "creditcard", "paypal")), is(true));
-    }
-
-    @Test
-    public void testGetMethod() throws IOException, URISyntaxException, InterruptedException {
-        ResponseOrError<Method> methodResponse = client.methods().get("ideal");
-        assertThat(methodResponse.getSuccess(), is(true));
-
-        Method method = methodResponse.getData();
-        assertThat(method.getId(), is("ideal"));
-        assertThat(method.getDescription(), is("iDEAL"));
-        assertThat(method.getAmount().getMinimum(), is(0.36));
-        assertThat(method.getAmount().getMaximum(), is(50000.0));
-        assertThat(method.getImage().getNormal(), is("https://www.mollie.com/images/payscreen/methods/ideal.png"));
-        assertThat(method.getImage().getBigger(), is("https://www.mollie.com/images/payscreen/methods/ideal@2x.png"));
-    }
-
-    @Test
-    public void testGetInvalidMethod() throws IOException, InterruptedException {
-        ResponseOrError<Method> methodResponse = client.methods().get("no-such-method");
-        assertThat(methodResponse.getSuccess(), is(false));
-        assertThat(methodResponse.getStatus(), is(404));
-        assertThat(methodResponse.getError().keySet(), is(Sets.newHashSet("error")));
-    }
-
     @Test
     public void testGetIssuers() throws IOException, URISyntaxException, InterruptedException {
         ResponseOrError<Page<Issuer>> allResponse = client.issuers().all(Optional.empty(), Optional.empty());
diff --git a/src/test/java/nl/stil4m/mollie/concepts/MethodsIntegrationTest.java b/src/test/java/nl/stil4m/mollie/concepts/MethodsIntegrationTest.java
new file mode 100644
index 0000000..313e609
--- /dev/null
+++ b/src/test/java/nl/stil4m/mollie/concepts/MethodsIntegrationTest.java
@@ -0,0 +1,72 @@
+package nl.stil4m.mollie.concepts;
+
+import static nl.stil4m.mollie.TestUtil.TEST_TIMEOUT;
+import static nl.stil4m.mollie.TestUtil.VALID_API_KEY;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.Sets;
+
+import nl.stil4m.mollie.Client;
+import nl.stil4m.mollie.ClientBuilder;
+import nl.stil4m.mollie.ResponseOrError;
+import nl.stil4m.mollie.domain.Method;
+import nl.stil4m.mollie.domain.Page;
+
+public class MethodsIntegrationTest {
+    
+    private Client client;
+
+    @Before
+    public void before() throws InterruptedException {
+        Thread.sleep(TEST_TIMEOUT);
+        client = new ClientBuilder().withApiKey(VALID_API_KEY).build();
+    }
+    
+    @Test
+    public void testGetMethods() throws IOException, URISyntaxException, InterruptedException {
+        ResponseOrError<Page<Method>> allResponse = client.methods().all(Optional.empty(), Optional.empty());
+        assertThat(allResponse.getSuccess(), is(true));
+
+        Page<Method> all = allResponse.getData();
+        assertThat(all.getCount(), is(10));
+        assertThat(all.getOffset(), is(0));
+        assertThat(all.getLinks(), is(notNullValue()));
+
+        Set<String> identifiers = all.getData().stream().map(Method::getId).collect(Collectors.toSet());
+        assertThat(identifiers.containsAll(Sets.newHashSet("ideal", "creditcard", "paypal")), is(true));
+    }
+
+    @Test
+    public void testGetMethod() throws IOException, URISyntaxException, InterruptedException {
+        ResponseOrError<Method> methodResponse = client.methods().get("ideal");
+        assertThat(methodResponse.getSuccess(), is(true));
+
+        Method method = methodResponse.getData();
+        assertThat(method.getId(), is("ideal"));
+        assertThat(method.getDescription(), is("iDEAL"));
+        assertThat(method.getAmount().getMinimum(), is(0.36));
+        assertThat(method.getAmount().getMaximum(), is(50000.0));
+        assertThat(method.getImage().getNormal(), is("https://www.mollie.com/images/payscreen/methods/ideal.png"));
+        assertThat(method.getImage().getBigger(), is("https://www.mollie.com/images/payscreen/methods/ideal@2x.png"));
+    }
+
+    @Test
+    public void testGetInvalidMethod() throws IOException, InterruptedException {
+        ResponseOrError<Method> methodResponse = client.methods().get("no-such-method");
+        assertThat(methodResponse.getSuccess(), is(false));
+        assertThat(methodResponse.getStatus(), is(404));
+        assertThat(methodResponse.getError().keySet(), is(Sets.newHashSet("error")));
+    }
+}

From 7f424f21b675232bf11ee3fb18a7d7a040c445b8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michae=CC=88l=20van=20de=20Giessen?= <mg@smile.nl>
Date: Fri, 28 Oct 2016 09:34:15 +0200
Subject: [PATCH 06/11] #24 - moved Issuers integration tests to
 IssuersIntegrationTest

---
 .../stil4m/mollie/ClientIntegrationTest.java  | 33 ----------
 .../concepts/IssuersIntegrationTest.java      | 64 +++++++++++++++++++
 2 files changed, 64 insertions(+), 33 deletions(-)
 create mode 100644 src/test/java/nl/stil4m/mollie/concepts/IssuersIntegrationTest.java

diff --git a/src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java b/src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java
index 2cc37ff..387848f 100644
--- a/src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java
+++ b/src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java
@@ -1,9 +1,7 @@
 package nl.stil4m.mollie;
 
-import com.google.common.collect.Sets;
 import nl.stil4m.mollie.domain.CreatePayment;
 import nl.stil4m.mollie.domain.CreatedPayment;
-import nl.stil4m.mollie.domain.Issuer;
 import nl.stil4m.mollie.domain.Page;
 import nl.stil4m.mollie.domain.Refund;
 import org.junit.Before;
@@ -14,8 +12,6 @@
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Optional;
-import java.util.Set;
-import java.util.stream.Collectors;
 
 import static nl.stil4m.mollie.TestUtil.TEST_TIMEOUT;
 import static nl.stil4m.mollie.TestUtil.VALID_API_KEY;
@@ -33,35 +29,6 @@ public void before() throws InterruptedException {
         client = new ClientBuilder().withApiKey(VALID_API_KEY).build();
     }
 
-    @Test
-    public void testGetIssuers() throws IOException, URISyntaxException, InterruptedException {
-        ResponseOrError<Page<Issuer>> allResponse = client.issuers().all(Optional.empty(), Optional.empty());
-        assertThat(allResponse.getSuccess(), is(true));
-
-        Page<Issuer> all = allResponse.getData();
-        assertThat(all.getCount(), is(1));
-        assertThat(all.getTotalCount(), is(1));
-        assertThat(all.getOffset(), is(0));
-        assertThat(all.getLinks(), is(notNullValue()));
-        assertThat(all.getLinks().getPrevious().isPresent(), is(false));
-        assertThat(all.getLinks().getNext().isPresent(), is(false));
-
-        Set<String> identifiers = all.getData().stream().map(Issuer::getId).collect(Collectors.toSet());
-        assertThat(identifiers.containsAll(Sets.newHashSet("ideal_TESTNL99")), is(true));
-    }
-
-    @Test
-    public void testGetIssuer() throws IOException, URISyntaxException, InterruptedException {
-        ResponseOrError<Issuer> allResponse = client.issuers().get("ideal_TESTNL99");
-        assertThat(allResponse.getSuccess(), is(true));
-
-        Issuer issuer = allResponse.getData();
-        assertThat(issuer.getResource(), is("issuer"));
-        assertThat(issuer.getId(), is("ideal_TESTNL99"));
-        assertThat(issuer.getName(), is("TBM Bank"));
-        assertThat(issuer.getMethod(), is("ideal"));
-    }
-
     @Test
     public void testGetRefunds() throws IOException, URISyntaxException, InterruptedException {
         ResponseOrError<CreatedPayment> payment = client.payments().create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null));
diff --git a/src/test/java/nl/stil4m/mollie/concepts/IssuersIntegrationTest.java b/src/test/java/nl/stil4m/mollie/concepts/IssuersIntegrationTest.java
new file mode 100644
index 0000000..7fe0ecd
--- /dev/null
+++ b/src/test/java/nl/stil4m/mollie/concepts/IssuersIntegrationTest.java
@@ -0,0 +1,64 @@
+package nl.stil4m.mollie.concepts;
+
+import static nl.stil4m.mollie.TestUtil.TEST_TIMEOUT;
+import static nl.stil4m.mollie.TestUtil.VALID_API_KEY;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.Sets;
+
+import nl.stil4m.mollie.Client;
+import nl.stil4m.mollie.ClientBuilder;
+import nl.stil4m.mollie.ResponseOrError;
+import nl.stil4m.mollie.domain.Issuer;
+import nl.stil4m.mollie.domain.Page;
+
+public class IssuersIntegrationTest {
+
+    private Client client;
+
+    @Before
+    public void before() throws InterruptedException {
+        Thread.sleep(TEST_TIMEOUT);
+        client = new ClientBuilder().withApiKey(VALID_API_KEY).build();
+    }
+
+    @Test
+    public void testGetIssuers() throws IOException, URISyntaxException, InterruptedException {
+        ResponseOrError<Page<Issuer>> allResponse = client.issuers().all(Optional.empty(), Optional.empty());
+        assertThat(allResponse.getSuccess(), is(true));
+
+        Page<Issuer> all = allResponse.getData();
+        assertThat(all.getCount(), is(1));
+        assertThat(all.getTotalCount(), is(1));
+        assertThat(all.getOffset(), is(0));
+        assertThat(all.getLinks(), is(notNullValue()));
+        assertThat(all.getLinks().getPrevious().isPresent(), is(false));
+        assertThat(all.getLinks().getNext().isPresent(), is(false));
+
+        Set<String> identifiers = all.getData().stream().map(Issuer::getId).collect(Collectors.toSet());
+        assertThat(identifiers.containsAll(Sets.newHashSet("ideal_TESTNL99")), is(true));
+    }
+
+    @Test
+    public void testGetIssuer() throws IOException, URISyntaxException, InterruptedException {
+        ResponseOrError<Issuer> allResponse = client.issuers().get("ideal_TESTNL99");
+        assertThat(allResponse.getSuccess(), is(true));
+
+        Issuer issuer = allResponse.getData();
+        assertThat(issuer.getResource(), is("issuer"));
+        assertThat(issuer.getId(), is("ideal_TESTNL99"));
+        assertThat(issuer.getName(), is("TBM Bank"));
+        assertThat(issuer.getMethod(), is("ideal"));
+    }
+}
\ No newline at end of file

From 6706a2a5324ecf876fdecab627c017c06f8a63a3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michae=CC=88l=20van=20de=20Giessen?= <mg@smile.nl>
Date: Fri, 28 Oct 2016 09:35:58 +0200
Subject: [PATCH 07/11] #24 - remainings tests were for Refunds, renamed to
 RefundsIntegrationTest

---
 .../RefundsIntegrationTest.java}                           | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
 rename src/test/java/nl/stil4m/mollie/{ClientIntegrationTest.java => concepts/RefundsIntegrationTest.java} (95%)

diff --git a/src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java b/src/test/java/nl/stil4m/mollie/concepts/RefundsIntegrationTest.java
similarity index 95%
rename from src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java
rename to src/test/java/nl/stil4m/mollie/concepts/RefundsIntegrationTest.java
index 387848f..fdc88c3 100644
--- a/src/test/java/nl/stil4m/mollie/ClientIntegrationTest.java
+++ b/src/test/java/nl/stil4m/mollie/concepts/RefundsIntegrationTest.java
@@ -1,5 +1,8 @@
-package nl.stil4m.mollie;
+package nl.stil4m.mollie.concepts;
 
+import nl.stil4m.mollie.Client;
+import nl.stil4m.mollie.ClientBuilder;
+import nl.stil4m.mollie.ResponseOrError;
 import nl.stil4m.mollie.domain.CreatePayment;
 import nl.stil4m.mollie.domain.CreatedPayment;
 import nl.stil4m.mollie.domain.Page;
@@ -19,7 +22,7 @@
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.notNullValue;
 
-public class ClientIntegrationTest {
+public class RefundsIntegrationTest {
 
     private Client client;
 

From 08f3b498fccac856751e58b3ab491affce523232 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michae=CC=88l=20van=20de=20Giessen?= <mg@smile.nl>
Date: Fri, 28 Oct 2016 09:58:02 +0200
Subject: [PATCH 08/11] #24 - concept integration tests setup only the required
 concepts under test

---
 .../CustomerPaymentsIntegrationTest.java      | 42 ++++++------
 .../concepts/CustomersIntegrationTest.java    | 46 ++++++-------
 .../concepts/IssuersIntegrationTest.java      | 11 ++--
 .../concepts/MethodsIntegrationTest.java      | 21 +++---
 .../concepts/PaymentsIntegrationTest.java     | 25 +++++---
 .../concepts/RefundsIntegrationTest.java      | 64 ++++++++++---------
 6 files changed, 114 insertions(+), 95 deletions(-)

diff --git a/src/test/java/nl/stil4m/mollie/concepts/CustomerPaymentsIntegrationTest.java b/src/test/java/nl/stil4m/mollie/concepts/CustomerPaymentsIntegrationTest.java
index a9c3d47..1dd1512 100644
--- a/src/test/java/nl/stil4m/mollie/concepts/CustomerPaymentsIntegrationTest.java
+++ b/src/test/java/nl/stil4m/mollie/concepts/CustomerPaymentsIntegrationTest.java
@@ -1,5 +1,20 @@
 package nl.stil4m.mollie.concepts;
 
+import static nl.stil4m.mollie.TestUtil.TEST_TIMEOUT;
+import static nl.stil4m.mollie.TestUtil.VALID_API_KEY;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.UUID;
+
+import org.junit.Before;
+import org.junit.Test;
+
 import nl.stil4m.mollie.Client;
 import nl.stil4m.mollie.ClientBuilder;
 import nl.stil4m.mollie.ResponseOrError;
@@ -10,30 +25,16 @@
 import nl.stil4m.mollie.domain.Page;
 import nl.stil4m.mollie.domain.Payment;
 import nl.stil4m.mollie.domain.customerpayments.FirstRecurringPayment;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-import java.util.UUID;
-
-import static nl.stil4m.mollie.TestUtil.TEST_TIMEOUT;
-import static nl.stil4m.mollie.TestUtil.VALID_API_KEY;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
 
 public class CustomerPaymentsIntegrationTest {
 
-    private Client client;
+    private CustomerPayments customerPayments;
     private Customer customer;
 
     @Before
     public void before() throws InterruptedException, IOException {
         Thread.sleep(TEST_TIMEOUT);
-        client = new ClientBuilder().withApiKey(VALID_API_KEY).build();
+        Client client = new ClientBuilder().withApiKey(VALID_API_KEY).build();
 
         Map<String, Object> defaultMetadata = new HashMap<>();
         defaultMetadata.put("foo", "bar");
@@ -41,18 +42,23 @@ public void before() throws InterruptedException, IOException {
         String uuid = UUID.randomUUID().toString();
         String name = "Test Customer " + uuid;
         customer = client.customers().create(new CreateCustomer(name, "test@foobar.com", Optional.empty(), defaultMetadata)).getData();
+        
+        customerPayments = client.customerPayments(customer.getId());
     }
 
     @Test
     public void testGetCustomerPayments() throws IOException, URISyntaxException {
-        ResponseOrError<Page<Payment>> all = client.customerPayments(customer.getId()).all(Optional.empty(), Optional.empty());
+        ResponseOrError<Page<Payment>> all = customerPayments.all(Optional.empty(), Optional.empty());
+        
         assertThat(all.getSuccess(), is(true));
     }
 
     @Test
     public void testCreateCustomerPayment() throws IOException, URISyntaxException {
         CustomerPayment customerPayment = new FirstRecurringPayment(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null));
-        ResponseOrError<Payment> all = client.customerPayments(customer.getId()).create(customerPayment);
+        
+        ResponseOrError<Payment> all = customerPayments.create(customerPayment);
+        
         assertThat(all.getSuccess(), is(true));
     }
 }
diff --git a/src/test/java/nl/stil4m/mollie/concepts/CustomersIntegrationTest.java b/src/test/java/nl/stil4m/mollie/concepts/CustomersIntegrationTest.java
index bd80f94..c4990b8 100644
--- a/src/test/java/nl/stil4m/mollie/concepts/CustomersIntegrationTest.java
+++ b/src/test/java/nl/stil4m/mollie/concepts/CustomersIntegrationTest.java
@@ -1,14 +1,9 @@
 package nl.stil4m.mollie.concepts;
 
-import nl.stil4m.mollie.Client;
-import nl.stil4m.mollie.ClientBuilder;
-import nl.stil4m.mollie.ResponseOrError;
-import nl.stil4m.mollie.domain.CreateCustomer;
-import nl.stil4m.mollie.domain.Customer;
-import nl.stil4m.mollie.domain.Page;
-import nl.stil4m.mollie.domain.UpdateCustomer;
-import org.junit.Before;
-import org.junit.Test;
+import static nl.stil4m.mollie.TestUtil.TEST_TIMEOUT;
+import static nl.stil4m.mollie.TestUtil.VALID_API_KEY;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
 
 import java.io.IOException;
 import java.net.URISyntaxException;
@@ -17,20 +12,25 @@
 import java.util.Optional;
 import java.util.UUID;
 
-import static nl.stil4m.mollie.TestUtil.TEST_TIMEOUT;
-import static nl.stil4m.mollie.TestUtil.VALID_API_KEY;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
+import org.junit.Before;
+import org.junit.Test;
+
+import nl.stil4m.mollie.ClientBuilder;
+import nl.stil4m.mollie.ResponseOrError;
+import nl.stil4m.mollie.domain.CreateCustomer;
+import nl.stil4m.mollie.domain.Customer;
+import nl.stil4m.mollie.domain.Page;
+import nl.stil4m.mollie.domain.UpdateCustomer;
 
 public class CustomersIntegrationTest {
 
-    private Client client;
+    private Customers customers;
     private Map<String, Object> defaultMetadata;
 
     @Before
     public void before() throws InterruptedException {
         Thread.sleep(TEST_TIMEOUT);
-        client = new ClientBuilder().withApiKey(VALID_API_KEY).build();
+        customers = new ClientBuilder().withApiKey(VALID_API_KEY).build().customers();
 
         defaultMetadata = new HashMap<>();
         defaultMetadata.put("foo", "bar");
@@ -39,7 +39,7 @@ public void before() throws InterruptedException {
 
     @Test
     public void testGetCustomers() throws IOException, URISyntaxException {
-        ResponseOrError<Page<Customer>> all = client.customers().all(Optional.empty(), Optional.empty());
+        ResponseOrError<Page<Customer>> all = customers.all(Optional.empty(), Optional.empty());
         assertThat(all.getSuccess(), is(true));
         //TODO Expand
     }
@@ -48,7 +48,7 @@ public void testGetCustomers() throws IOException, URISyntaxException {
     public void testCreateCustomer() throws IOException, URISyntaxException {
         String uuid = UUID.randomUUID().toString();
 
-        ResponseOrError<Customer> createdCustomer = client.customers().create(new CreateCustomer(
+        ResponseOrError<Customer> createdCustomer = customers.create(new CreateCustomer(
                 "Test Customer " + uuid,
                 "test@foobar.nl",
                 Optional.of("gb_EN"),
@@ -63,9 +63,9 @@ public void testCreateCustomer() throws IOException, URISyntaxException {
     public void testGetCustomer() throws IOException, URISyntaxException {
         String uuid = UUID.randomUUID().toString();
         String originalName = "Test Customer " + uuid;
-        ResponseOrError<Customer> createdCustomer = client.customers().create(new CreateCustomer(originalName, "test@foobar.nl", Optional.empty(), defaultMetadata));
+        ResponseOrError<Customer> createdCustomer = customers.create(new CreateCustomer(originalName, "test@foobar.nl", Optional.empty(), defaultMetadata));
 
-        ResponseOrError<Customer> fetchedCustomer = client.customers().get(createdCustomer.getData().getId());
+        ResponseOrError<Customer> fetchedCustomer = customers.get(createdCustomer.getData().getId());
         assertThat(fetchedCustomer.getData().getName(), is(originalName));
         //TODO Expand
     }
@@ -74,9 +74,9 @@ public void testGetCustomer() throws IOException, URISyntaxException {
     public void testUpdateCustomerEmail() throws IOException, URISyntaxException {
         String uuid = UUID.randomUUID().toString();
         String originalName = "Test Customer " + uuid;
-        ResponseOrError<Customer> createdCustomer = client.customers().create(new CreateCustomer(originalName, "test@foobar.nl", Optional.empty(), null));
+        ResponseOrError<Customer> createdCustomer = customers.create(new CreateCustomer(originalName, "test@foobar.nl", Optional.empty(), null));
 
-        ResponseOrError<Customer> update = client.customers().update(createdCustomer.getData().getId(), new UpdateCustomer(
+        ResponseOrError<Customer> update = customers.update(createdCustomer.getData().getId(), new UpdateCustomer(
                 Optional.empty(),
                 Optional.of("test+2@foobar.nl"),
                 Optional.empty(),
@@ -94,9 +94,9 @@ public void testUpdateCustomerName() throws IOException, URISyntaxException {
         String uuid2 = UUID.randomUUID().toString();
         String originalName = "Test Customer " + uuid;
         String newName = "Test Customer " + uuid2;
-        ResponseOrError<Customer> createdCustomer = client.customers().create(new CreateCustomer(originalName, "test@foobar.nl", Optional.empty(), null));
+        ResponseOrError<Customer> createdCustomer = customers.create(new CreateCustomer(originalName, "test@foobar.nl", Optional.empty(), null));
 
-        ResponseOrError<Customer> update = client.customers().update(createdCustomer.getData().getId(), new UpdateCustomer(
+        ResponseOrError<Customer> update = customers.update(createdCustomer.getData().getId(), new UpdateCustomer(
                 Optional.of(newName),
                 Optional.empty(),
                 Optional.empty(),
diff --git a/src/test/java/nl/stil4m/mollie/concepts/IssuersIntegrationTest.java b/src/test/java/nl/stil4m/mollie/concepts/IssuersIntegrationTest.java
index 7fe0ecd..49101f0 100644
--- a/src/test/java/nl/stil4m/mollie/concepts/IssuersIntegrationTest.java
+++ b/src/test/java/nl/stil4m/mollie/concepts/IssuersIntegrationTest.java
@@ -17,7 +17,6 @@
 
 import com.google.common.collect.Sets;
 
-import nl.stil4m.mollie.Client;
 import nl.stil4m.mollie.ClientBuilder;
 import nl.stil4m.mollie.ResponseOrError;
 import nl.stil4m.mollie.domain.Issuer;
@@ -25,17 +24,18 @@
 
 public class IssuersIntegrationTest {
 
-    private Client client;
+    private Issuers issuers;
 
     @Before
     public void before() throws InterruptedException {
         Thread.sleep(TEST_TIMEOUT);
-        client = new ClientBuilder().withApiKey(VALID_API_KEY).build();
+        issuers = new ClientBuilder().withApiKey(VALID_API_KEY).build().issuers();
     }
 
     @Test
     public void testGetIssuers() throws IOException, URISyntaxException, InterruptedException {
-        ResponseOrError<Page<Issuer>> allResponse = client.issuers().all(Optional.empty(), Optional.empty());
+        ResponseOrError<Page<Issuer>> allResponse = issuers.all(Optional.empty(), Optional.empty());
+        
         assertThat(allResponse.getSuccess(), is(true));
 
         Page<Issuer> all = allResponse.getData();
@@ -52,7 +52,8 @@ public void testGetIssuers() throws IOException, URISyntaxException, Interrupted
 
     @Test
     public void testGetIssuer() throws IOException, URISyntaxException, InterruptedException {
-        ResponseOrError<Issuer> allResponse = client.issuers().get("ideal_TESTNL99");
+        ResponseOrError<Issuer> allResponse = issuers.get("ideal_TESTNL99");
+        
         assertThat(allResponse.getSuccess(), is(true));
 
         Issuer issuer = allResponse.getData();
diff --git a/src/test/java/nl/stil4m/mollie/concepts/MethodsIntegrationTest.java b/src/test/java/nl/stil4m/mollie/concepts/MethodsIntegrationTest.java
index 313e609..311f713 100644
--- a/src/test/java/nl/stil4m/mollie/concepts/MethodsIntegrationTest.java
+++ b/src/test/java/nl/stil4m/mollie/concepts/MethodsIntegrationTest.java
@@ -2,6 +2,9 @@
 
 import static nl.stil4m.mollie.TestUtil.TEST_TIMEOUT;
 import static nl.stil4m.mollie.TestUtil.VALID_API_KEY;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
 
 import java.io.IOException;
 import java.net.URISyntaxException;
@@ -9,16 +12,11 @@
 import java.util.Set;
 import java.util.stream.Collectors;
 
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-
 import org.junit.Before;
 import org.junit.Test;
 
 import com.google.common.collect.Sets;
 
-import nl.stil4m.mollie.Client;
 import nl.stil4m.mollie.ClientBuilder;
 import nl.stil4m.mollie.ResponseOrError;
 import nl.stil4m.mollie.domain.Method;
@@ -26,17 +24,18 @@
 
 public class MethodsIntegrationTest {
     
-    private Client client;
+    private Methods methods;
 
     @Before
     public void before() throws InterruptedException {
         Thread.sleep(TEST_TIMEOUT);
-        client = new ClientBuilder().withApiKey(VALID_API_KEY).build();
+        methods = new ClientBuilder().withApiKey(VALID_API_KEY).build().methods();
     }
     
     @Test
     public void testGetMethods() throws IOException, URISyntaxException, InterruptedException {
-        ResponseOrError<Page<Method>> allResponse = client.methods().all(Optional.empty(), Optional.empty());
+        ResponseOrError<Page<Method>> allResponse = methods.all(Optional.empty(), Optional.empty());
+        
         assertThat(allResponse.getSuccess(), is(true));
 
         Page<Method> all = allResponse.getData();
@@ -50,7 +49,8 @@ public void testGetMethods() throws IOException, URISyntaxException, Interrupted
 
     @Test
     public void testGetMethod() throws IOException, URISyntaxException, InterruptedException {
-        ResponseOrError<Method> methodResponse = client.methods().get("ideal");
+        ResponseOrError<Method> methodResponse = methods.get("ideal");
+        
         assertThat(methodResponse.getSuccess(), is(true));
 
         Method method = methodResponse.getData();
@@ -64,7 +64,8 @@ public void testGetMethod() throws IOException, URISyntaxException, InterruptedE
 
     @Test
     public void testGetInvalidMethod() throws IOException, InterruptedException {
-        ResponseOrError<Method> methodResponse = client.methods().get("no-such-method");
+        ResponseOrError<Method> methodResponse = methods.get("no-such-method");
+        
         assertThat(methodResponse.getSuccess(), is(false));
         assertThat(methodResponse.getStatus(), is(404));
         assertThat(methodResponse.getError().keySet(), is(Sets.newHashSet("error")));
diff --git a/src/test/java/nl/stil4m/mollie/concepts/PaymentsIntegrationTest.java b/src/test/java/nl/stil4m/mollie/concepts/PaymentsIntegrationTest.java
index 861702d..0f1933a 100644
--- a/src/test/java/nl/stil4m/mollie/concepts/PaymentsIntegrationTest.java
+++ b/src/test/java/nl/stil4m/mollie/concepts/PaymentsIntegrationTest.java
@@ -28,18 +28,22 @@
 
 public class PaymentsIntegrationTest {
     
-    private Client client;
+    private Payments payments;
+    private Issuers issuers;
 
     @Before
     public void before() throws InterruptedException {
         Thread.sleep(TEST_TIMEOUT);
-        client = new ClientBuilder().withApiKey(VALID_API_KEY).build();
+        Client client = new ClientBuilder().withApiKey(VALID_API_KEY).build();
+        payments = client.payments();
+        issuers = client.issuers();
     }
     
     @Test
     public void testCreatePayment() throws IOException, InterruptedException {
         Date beforeTest = new Date();
-        ResponseOrError<CreatedPayment> payment = client.payments().create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null));
+        
+        ResponseOrError<CreatedPayment> payment = payments.create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null));
 
         assertWithin(beforeTest, payment.getData().getCreatedDatetime(), new Date(), 5000L);
     }
@@ -47,11 +51,11 @@ public void testCreatePayment() throws IOException, InterruptedException {
     @Test
     public void testCreateIdealPayment() throws IOException, URISyntaxException, InterruptedException {
         Date beforeTest = new Date();
-        ResponseOrError<Page<Issuer>> all = client.issuers().all(Optional.empty(), Optional.empty());
+        ResponseOrError<Page<Issuer>> all = issuers.all(Optional.empty(), Optional.empty());
         assertThat(all.getSuccess(), is(true));
         Issuer issuer = all.getData().getData().get(0);
 
-        ResponseOrError<CreatedPayment> payment = client.payments().create(new CreateIdealPayment(1.00, "Some description", "http://example.com", Optional.empty(), null, new IdealPaymentOptions(issuer.getId())));
+        ResponseOrError<CreatedPayment> payment = payments.create(new CreateIdealPayment(1.00, "Some description", "http://example.com", Optional.empty(), null, new IdealPaymentOptions(issuer.getId())));
 
         assertThat(payment.getSuccess(), is(true));
         assertWithin(beforeTest, payment.getData().getCreatedDatetime(), new Date(), 5000L);
@@ -59,16 +63,17 @@ public void testCreateIdealPayment() throws IOException, URISyntaxException, Int
 
     @Test
     public void testGetPayment() throws IOException, InterruptedException {
-        ResponseOrError<CreatedPayment> payment = client.payments().create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null));
+        ResponseOrError<CreatedPayment> payment = payments.create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null));
         String id = payment.getData().getId();
 
-        ResponseOrError<Payment> paymentStatus = client.payments().get(id);
+        ResponseOrError<Payment> paymentStatus = payments.get(id);
+        
         assertThat(paymentStatus.getData().getStatus(), is("open"));
     }
 
     @Test
     public void testGetPaymentWithRefunds() throws IOException, InterruptedException {
-        ResponseOrError<Payment> getResponse = client.payments().get("tr_3AdTKpQGii");
+        ResponseOrError<Payment> getResponse = payments.get("tr_3AdTKpQGii");
 
         getResponse.get(payment -> assertThat(payment.getLinks().getRefunds().isPresent(), is(true)), errorData -> System.out.println());
 
@@ -77,7 +82,7 @@ public void testGetPaymentWithRefunds() throws IOException, InterruptedException
     @Test
     public void testGetPaymentWithEmptyId() throws IOException, InterruptedException {
         try {
-            client.payments().get("");
+            payments.get("");
             fail();
         } catch (IllegalArgumentException e) {
             assertThat(e.getMessage(), is("Payment id may not be an empty string"));
@@ -87,7 +92,7 @@ public void testGetPaymentWithEmptyId() throws IOException, InterruptedException
     @Test
     public void testGetPaymentWithNullId() throws IOException, InterruptedException {
         try {
-            client.payments().get(null);
+            payments.get(null);
             fail();
         } catch (IllegalArgumentException e) {
             assertThat(e.getMessage(), is("Payment id may not be null"));
diff --git a/src/test/java/nl/stil4m/mollie/concepts/RefundsIntegrationTest.java b/src/test/java/nl/stil4m/mollie/concepts/RefundsIntegrationTest.java
index fdc88c3..f4bbbbd 100644
--- a/src/test/java/nl/stil4m/mollie/concepts/RefundsIntegrationTest.java
+++ b/src/test/java/nl/stil4m/mollie/concepts/RefundsIntegrationTest.java
@@ -1,14 +1,10 @@
 package nl.stil4m.mollie.concepts;
 
-import nl.stil4m.mollie.Client;
-import nl.stil4m.mollie.ClientBuilder;
-import nl.stil4m.mollie.ResponseOrError;
-import nl.stil4m.mollie.domain.CreatePayment;
-import nl.stil4m.mollie.domain.CreatedPayment;
-import nl.stil4m.mollie.domain.Page;
-import nl.stil4m.mollie.domain.Refund;
-import org.junit.Before;
-import org.junit.Test;
+import static nl.stil4m.mollie.TestUtil.TEST_TIMEOUT;
+import static nl.stil4m.mollie.TestUtil.VALID_API_KEY;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
 
 import java.io.IOException;
 import java.net.URISyntaxException;
@@ -16,28 +12,37 @@
 import java.util.Map;
 import java.util.Optional;
 
-import static nl.stil4m.mollie.TestUtil.TEST_TIMEOUT;
-import static nl.stil4m.mollie.TestUtil.VALID_API_KEY;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
+import org.junit.Before;
+import org.junit.Test;
+
+import nl.stil4m.mollie.Client;
+import nl.stil4m.mollie.ClientBuilder;
+import nl.stil4m.mollie.ResponseOrError;
+import nl.stil4m.mollie.domain.CreatePayment;
+import nl.stil4m.mollie.domain.CreatedPayment;
+import nl.stil4m.mollie.domain.Page;
+import nl.stil4m.mollie.domain.Refund;
 
 public class RefundsIntegrationTest {
 
-    private Client client;
+    private Refunds refunds;
+    private Payments payments;
 
     @Before
     public void before() throws InterruptedException {
         Thread.sleep(TEST_TIMEOUT);
-        client = new ClientBuilder().withApiKey(VALID_API_KEY).build();
+        Client client = new ClientBuilder().withApiKey(VALID_API_KEY).build();
+        refunds = client.refunds();
+        payments = client.payments();
     }
 
     @Test
     public void testGetRefunds() throws IOException, URISyntaxException, InterruptedException {
-        ResponseOrError<CreatedPayment> payment = client.payments().create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null));
+        ResponseOrError<CreatedPayment> payment = payments.create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null));
         String id = payment.getData().getId();
 
-        ResponseOrError<Page<Refund>> all = client.refunds().all(id, Optional.empty(), Optional.empty());
+        ResponseOrError<Page<Refund>> all = refunds.all(id, Optional.empty(), Optional.empty());
+        
         assertThat(all.getSuccess(), is(true));
         Page<Refund> refundPage = all.getData();
         assertThat(refundPage.getCount(), is(0));
@@ -47,11 +52,11 @@ public void testGetRefunds() throws IOException, URISyntaxException, Interrupted
 
     @Test
     public void testListRefundsForExistingPayment() throws IOException, URISyntaxException, InterruptedException {
-        CreatedPayment createdPayment = client.payments().create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null)).getData();
-        ResponseOrError<Page<Refund>> all = client.refunds().all(createdPayment.getId(), Optional.empty(), Optional.empty());
+        CreatedPayment createdPayment = payments.create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null)).getData();
+        
+        ResponseOrError<Page<Refund>> all = refunds.all(createdPayment.getId(), Optional.empty(), Optional.empty());
 
         assertThat(all.getSuccess(), is(true));
-
         Page<Refund> data = all.getData();
         assertThat(data.getData().size(), is(0));
     }
@@ -62,12 +67,12 @@ public void testCancelNonExistingRefund() throws IOException {
         Map<String, String> errorData = new HashMap<>();
         errorData.put("type", "request");
         errorData.put("message", "The refund id is invalid");
-        ResponseOrError<CreatedPayment> payment = client.payments().create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null));
-
+        ResponseOrError<CreatedPayment> payment = payments.create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null));
         assertThat(payment.getSuccess(), is(true));
         String id = payment.getData().getId();
 
-        ResponseOrError<Void> cancel = client.refunds().cancel(id, "foo_bar");
+        ResponseOrError<Void> cancel = refunds.cancel(id, "foo_bar");
+        
         assertThat(cancel.getSuccess(), is(false));
         assertThat(cancel.getError().get("error"), is(errorData));
     }
@@ -77,10 +82,11 @@ public void testGetNonExistingRefund() throws IOException {
         Map<String, String> errorData = new HashMap<>();
         errorData.put("type", "request");
         errorData.put("message", "The refund id is invalid");
-        ResponseOrError<CreatedPayment> payment = client.payments().create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null));
+        ResponseOrError<CreatedPayment> payment = payments.create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null));
         String id = payment.getData().getId();
 
-        ResponseOrError<Refund> get = client.refunds().get(id, "foo_bar");
+        ResponseOrError<Refund> get = refunds.get(id, "foo_bar");
+        
         assertThat(get.getSuccess(), is(false));
         assertThat(get.getError().get("error"), is(errorData));
     }
@@ -90,11 +96,11 @@ public void testCreateRefund() throws IOException, URISyntaxException {
         Map<String, String> errorData = new HashMap<>();
         errorData.put("type", "request");
         errorData.put("message", "The payment is already refunded or has not been paid for yet");
-
-        ResponseOrError<CreatedPayment> payment = client.payments().create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null));
+        ResponseOrError<CreatedPayment> payment = payments.create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null));
         String id = payment.getData().getId();
 
-        ResponseOrError<Refund> create = client.refunds().create(id, Optional.of(1.00));
+        ResponseOrError<Refund> create = refunds.create(id, Optional.of(1.00));
+        
         assertThat(create.getSuccess(), is(false));
         assertThat(create.getError().get("error"), is(errorData));
     }

From f2b64ab21989dc4d5e2d9a4da35c53c0d03a565a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michae=CC=88l=20van=20de=20Giessen?= <mg@smile.nl>
Date: Fri, 28 Oct 2016 10:09:40 +0200
Subject: [PATCH 09/11] #24 - moved Payments integration tests to
 PaymentsIntegrationTest

merged duplicate tests
testGetPayment was identical
testCreatePayment was more complete in DynamicClientIntegrationTest (retained the DynamicClientIntegrationTest version)
---
 .../mollie/DynamicClientIntegrationTest.java  | 191 +-----------------
 .../concepts/PaymentsIntegrationTest.java     | 172 +++++++++++++++-
 2 files changed, 170 insertions(+), 193 deletions(-)

diff --git a/src/test/java/nl/stil4m/mollie/DynamicClientIntegrationTest.java b/src/test/java/nl/stil4m/mollie/DynamicClientIntegrationTest.java
index 0d02161..f7239b9 100644
--- a/src/test/java/nl/stil4m/mollie/DynamicClientIntegrationTest.java
+++ b/src/test/java/nl/stil4m/mollie/DynamicClientIntegrationTest.java
@@ -1,27 +1,16 @@
 package nl.stil4m.mollie;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
-import nl.stil4m.mollie.domain.CreatePayment;
-import nl.stil4m.mollie.domain.CreatedPayment;
-import nl.stil4m.mollie.domain.Page;
-import nl.stil4m.mollie.domain.Payment;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-
 import static nl.stil4m.mollie.TestUtil.TEST_TIMEOUT;
 import static nl.stil4m.mollie.TestUtil.VALID_API_KEY;
-import static nl.stil4m.mollie.TestUtil.assertWithin;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.hamcrest.Matchers.nullValue;
+
+import java.io.IOException;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
 
 public class DynamicClientIntegrationTest {
 
@@ -44,170 +33,4 @@ public void validateInvalidApiKey() throws IOException {
     public void validateValidApiKey() throws IOException {
         assertThat(client.status(VALID_API_KEY).checkApiKey().getValid(), is(true));
     }
-
-    @Test
-    public void testCreatePayment() throws IOException {
-        Date beforeTest = new Date();
-        Map<String, Object> meta = new HashMap<>();
-        meta.put("foo", "bar");
-
-        ResponseOrError<CreatedPayment> 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(), 5000L);
-
-        assertThat(createdPayment.getMethod(), is(nullValue()));
-        assertThat(createdPayment.getAmount(), is(1.00));
-        assertThat(createdPayment.getDescription(), is("Some description"));
-        assertThat(createdPayment.getId(), is(notNullValue()));
-        assertThat(createdPayment.getDetails(), is(nullValue()));
-        assertThat(createdPayment.getLinks(), is(notNullValue()));
-        assertThat(createdPayment.getLinks().getPaymentUrl().matches("https://www.mollie.com/payscreen/select-method/[A-Za-z0-9]+"), is(true));
-        assertThat(createdPayment.getLinks().getRedirectUrl(), is("http://example.com"));
-        assertThat(createdPayment.getLinks().getWebhookUrl(), is("https://stil4m.github.io"));
-        assertThat(createdPayment.getMode(), is("test"));
-        assertThat(createdPayment.getStatus(), is("open"));
-        assertThat(createdPayment.getMetadata(), is(meta));
-    }
-
-    @Test
-    public void testCreatePaymentWithMethod() throws IOException {
-        Date beforeTest = new Date();
-        Map<String, Object> meta = new HashMap<>();
-        meta.put("foo", "bar");
-
-        ResponseOrError<CreatedPayment> 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(), 5000L);
-
-        assertThat(createdPayment.getMethod(), is("ideal"));
-        assertThat(createdPayment.getAmount(), is(1.00));
-        assertThat(createdPayment.getDescription(), is("Some description"));
-        assertThat(createdPayment.getId(), is(notNullValue()));
-        assertThat(createdPayment.getDetails(), is(nullValue()));
-        assertThat(createdPayment.getLinks(), is(notNullValue()));
-        assertThat(createdPayment.getLinks().getPaymentUrl().matches("https://www.mollie.com/paymentscreen/ideal/select-issuer/[A-Za-z0-9]+"), is(true));
-        assertThat(createdPayment.getLinks().getRedirectUrl(), is("http://example.com"));
-        assertThat(createdPayment.getLinks().getWebhookUrl(), is(is("https://stil4m.github.io")));
-        assertThat(createdPayment.getMode(), is("test"));
-        assertThat(createdPayment.getStatus(), is("open"));
-        assertThat(createdPayment.getMetadata(), is(meta));
-    }
-
-
-    @Test
-    public void testCreateAndGetPayment() throws IOException {
-        Map<String, Object> meta = new HashMap<>();
-        meta.put("foo", "bar");
-
-        ResponseOrError<CreatedPayment> createResponse = client.payments(VALID_API_KEY).create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), meta));
-        ResponseOrError<Payment> paymentResponse = client.payments(VALID_API_KEY).get(createResponse.getData().getId());
-        Payment payment = paymentResponse.getData();
-
-        assertThat(payment.getMethod(), is(nullValue()));
-        assertThat(payment.getAmount(), is(1.00));
-        assertThat(payment.getDescription(), is("Some description"));
-        assertThat(payment.getId(), is(notNullValue()));
-        assertThat(payment.getDetails(), is(nullValue()));
-        assertThat(payment.getLinks(), is(notNullValue()));
-        assertThat(payment.getLinks().getPaymentUrl().matches("https://www.mollie.com/payscreen/select-method/[A-Za-z0-9]+"), is(true));
-        assertThat(payment.getLinks().getRedirectUrl(), is("http://example.com"));
-        assertThat(payment.getLinks().getWebhookUrl(), is(is("https://stil4m.github.io")));
-        assertThat(payment.getMode(), is("test"));
-        assertThat(payment.getStatus(), is("open"));
-        assertThat(payment.getMetadata(), is(meta));
-
-    }
-
-    @Test
-    public void testCreateAndGetCreditCardPayment() throws IOException {
-        Map<String, Object> meta = new HashMap<>();
-        meta.put("foo", "bar");
-
-        ResponseOrError<CreatedPayment> createResponse = client.payments(VALID_API_KEY).create(new CreatePayment(Optional.of("creditcard"), 2.00, "Some credit card description", "http://example.com", Optional.empty(), meta));
-        ResponseOrError<Payment> paymentResponse = client.payments(VALID_API_KEY).get(createResponse.getData().getId());
-        Payment payment = paymentResponse.getData();
-
-        assertThat(payment.getMethod(), is("creditcard"));
-        assertThat(payment.getAmount(), is(2.00));
-        assertThat(payment.getDescription(), is("Some credit card description"));
-        assertThat(payment.getId(), is(notNullValue()));
-        assertThat(payment.getDetails(), is(notNullValue())); // feeRegion=other
-        assertThat(payment.getLinks(), is(notNullValue()));
-        assertThat(payment.getLinks().getPaymentUrl().matches("https://www.mollie.com/paymentscreen/creditcard/testmode/[A-Za-z0-9]+"), is(true));
-        assertThat(payment.getLinks().getRedirectUrl(), is("http://example.com"));
-        assertThat(payment.getLinks().getWebhookUrl(), is(is("https://stil4m.github.io")));
-        assertThat(payment.getMode(), is("test"));
-        assertThat(payment.getStatus(), is("open"));
-        assertThat(payment.getMetadata(), is(meta));
-
-    }
-
-    @Test
-    public void testGetPayment() throws IOException {
-        ResponseOrError<CreatedPayment> payment = client.payments(VALID_API_KEY).create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null));
-        String id = payment.getData().getId();
-
-        ResponseOrError<Payment> paymentStatus = client.payments(VALID_API_KEY).get(id);
-        assertThat(paymentStatus.getData().getStatus(), is("open"));
-    }
-
-    @Test
-    public void testGetPayments() throws IOException, URISyntaxException {
-        ResponseOrError<Page<Payment>> result = client.payments(VALID_API_KEY).list(Optional.empty(), Optional.empty());
-        assertThat(result.getSuccess(), is(true));
-        Page<Payment> page = result.getData();
-
-        assertThat(page.getTotalCount(), is(notNullValue()));
-        assertThat(page.getData().size(), is(Math.min(10, page.getTotalCount())));
-        assertThat(page.getOffset(), is(0));
-        assertThat(page.getCount(), is(10));
-
-        assertThat(page.getLinks().getPrevious().isPresent(), is(false));
-        assertThat(page.getLinks().getNext().isPresent(), is(true));
-        assertThat(page.getLinks().getLast().isPresent(), is(true));
-        assertThat(page.getLinks().getFirst().isPresent(), is(true));
-    }
-
-    @Test
-    public void testGetPaymentsWithOffsetAndCount() throws IOException, URISyntaxException {
-        ResponseOrError<Page<Payment>> result = client.payments(VALID_API_KEY).list(Optional.of(20), Optional.of(40));
-        assertThat(result.getSuccess(), is(true));
-        Page<Payment> page = result.getData();
-
-        assertThat(page.getTotalCount(), is(notNullValue()));
-        assertThat(page.getData().size(), is(Math.min(20, page.getTotalCount())));
-        assertThat(page.getOffset(), is(40));
-        assertThat(page.getCount(), is(20));
-
-        assertThat(page.getLinks().getPrevious().isPresent(), is(true));
-        assertThat(page.getLinks().getNext().isPresent(), is(true));
-        assertThat(page.getLinks().getLast().isPresent(), is(true));
-        assertThat(page.getLinks().getFirst().isPresent(), is(true));
-    }
-
-    @Test
-    public void testNextPayments() throws IOException, URISyntaxException {
-        ResponseOrError<Page<Payment>> result = client.payments(VALID_API_KEY).list(Optional.empty(), Optional.empty());
-        assertThat(result.getSuccess(), is(true));
-        Page<Payment> page = result.getData();
-
-        Page<Payment> nextPage = client.payments(VALID_API_KEY).next(page).getData();
-
-        assertThat(nextPage.getOffset(), is(10));
-        assertThat(nextPage.getCount(), is(10));
-    }
-
-    @Test
-    public void testPreviousPayments() throws IOException, URISyntaxException {
-        ResponseOrError<Page<Payment>> result = client.payments(VALID_API_KEY).list(Optional.of(20), Optional.of(40));
-        assertThat(result.getSuccess(), is(true));
-        Page<Payment> page = result.getData();
-
-        Page<Payment> previousPage = client.payments(VALID_API_KEY).previous(page).getData();
-
-        assertThat(previousPage.getOffset(), is(20));
-        assertThat(previousPage.getCount(), is(20));
-    }
 }
diff --git a/src/test/java/nl/stil4m/mollie/concepts/PaymentsIntegrationTest.java b/src/test/java/nl/stil4m/mollie/concepts/PaymentsIntegrationTest.java
index 0f1933a..5322983 100644
--- a/src/test/java/nl/stil4m/mollie/concepts/PaymentsIntegrationTest.java
+++ b/src/test/java/nl/stil4m/mollie/concepts/PaymentsIntegrationTest.java
@@ -5,11 +5,15 @@
 import static nl.stil4m.mollie.TestUtil.assertWithin;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
 import static org.junit.Assert.fail;
 
 import java.io.IOException;
 import java.net.URISyntaxException;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Optional;
 
 import org.junit.Before;
@@ -38,15 +42,6 @@ public void before() throws InterruptedException {
         payments = client.payments();
         issuers = client.issuers();
     }
-    
-    @Test
-    public void testCreatePayment() throws IOException, InterruptedException {
-        Date beforeTest = new Date();
-        
-        ResponseOrError<CreatedPayment> payment = payments.create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null));
-
-        assertWithin(beforeTest, payment.getData().getCreatedDatetime(), new Date(), 5000L);
-    }
 
     @Test
     public void testCreateIdealPayment() throws IOException, URISyntaxException, InterruptedException {
@@ -98,4 +93,163 @@ public void testGetPaymentWithNullId() throws IOException, InterruptedException
             assertThat(e.getMessage(), is("Payment id may not be null"));
         }
     }
+    
+
+
+    @Test
+    public void testCreatePayment() throws IOException {
+        Date beforeTest = new Date();
+        Map<String, Object> meta = new HashMap<>();
+        meta.put("foo", "bar");
+
+        ResponseOrError<CreatedPayment> payment = payments.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(), 5000L);
+
+        assertThat(createdPayment.getMethod(), is(nullValue()));
+        assertThat(createdPayment.getAmount(), is(1.00));
+        assertThat(createdPayment.getDescription(), is("Some description"));
+        assertThat(createdPayment.getId(), is(notNullValue()));
+        assertThat(createdPayment.getDetails(), is(nullValue()));
+        assertThat(createdPayment.getLinks(), is(notNullValue()));
+        assertThat(createdPayment.getLinks().getPaymentUrl().matches("https://www.mollie.com/payscreen/select-method/[A-Za-z0-9]+"), is(true));
+        assertThat(createdPayment.getLinks().getRedirectUrl(), is("http://example.com"));
+        assertThat(createdPayment.getLinks().getWebhookUrl(), is("https://stil4m.github.io"));
+        assertThat(createdPayment.getMode(), is("test"));
+        assertThat(createdPayment.getStatus(), is("open"));
+        assertThat(createdPayment.getMetadata(), is(meta));
+    }
+
+    @Test
+    public void testCreatePaymentWithMethod() throws IOException {
+        Date beforeTest = new Date();
+        Map<String, Object> meta = new HashMap<>();
+        meta.put("foo", "bar");
+
+        ResponseOrError<CreatedPayment> payment = payments.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(), 5000L);
+
+        assertThat(createdPayment.getMethod(), is("ideal"));
+        assertThat(createdPayment.getAmount(), is(1.00));
+        assertThat(createdPayment.getDescription(), is("Some description"));
+        assertThat(createdPayment.getId(), is(notNullValue()));
+        assertThat(createdPayment.getDetails(), is(nullValue()));
+        assertThat(createdPayment.getLinks(), is(notNullValue()));
+        assertThat(createdPayment.getLinks().getPaymentUrl().matches("https://www.mollie.com/paymentscreen/ideal/select-issuer/[A-Za-z0-9]+"), is(true));
+        assertThat(createdPayment.getLinks().getRedirectUrl(), is("http://example.com"));
+        assertThat(createdPayment.getLinks().getWebhookUrl(), is(is("https://stil4m.github.io")));
+        assertThat(createdPayment.getMode(), is("test"));
+        assertThat(createdPayment.getStatus(), is("open"));
+        assertThat(createdPayment.getMetadata(), is(meta));
+    }
+
+
+    @Test
+    public void testCreateAndGetPayment() throws IOException {
+        Map<String, Object> meta = new HashMap<>();
+        meta.put("foo", "bar");
+
+        ResponseOrError<CreatedPayment> createResponse = payments.create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), meta));
+        ResponseOrError<Payment> paymentResponse = payments.get(createResponse.getData().getId());
+        Payment payment = paymentResponse.getData();
+
+        assertThat(payment.getMethod(), is(nullValue()));
+        assertThat(payment.getAmount(), is(1.00));
+        assertThat(payment.getDescription(), is("Some description"));
+        assertThat(payment.getId(), is(notNullValue()));
+        assertThat(payment.getDetails(), is(nullValue()));
+        assertThat(payment.getLinks(), is(notNullValue()));
+        assertThat(payment.getLinks().getPaymentUrl().matches("https://www.mollie.com/payscreen/select-method/[A-Za-z0-9]+"), is(true));
+        assertThat(payment.getLinks().getRedirectUrl(), is("http://example.com"));
+        assertThat(payment.getLinks().getWebhookUrl(), is(is("https://stil4m.github.io")));
+        assertThat(payment.getMode(), is("test"));
+        assertThat(payment.getStatus(), is("open"));
+        assertThat(payment.getMetadata(), is(meta));
+
+    }
+
+    @Test
+    public void testCreateAndGetCreditCardPayment() throws IOException {
+        Map<String, Object> meta = new HashMap<>();
+        meta.put("foo", "bar");
+
+        ResponseOrError<CreatedPayment> createResponse = payments.create(new CreatePayment(Optional.of("creditcard"), 2.00, "Some credit card description", "http://example.com", Optional.empty(), meta));
+        ResponseOrError<Payment> paymentResponse = payments.get(createResponse.getData().getId());
+        Payment payment = paymentResponse.getData();
+
+        assertThat(payment.getMethod(), is("creditcard"));
+        assertThat(payment.getAmount(), is(2.00));
+        assertThat(payment.getDescription(), is("Some credit card description"));
+        assertThat(payment.getId(), is(notNullValue()));
+        assertThat(payment.getDetails(), is(notNullValue())); // feeRegion=other
+        assertThat(payment.getLinks(), is(notNullValue()));
+        assertThat(payment.getLinks().getPaymentUrl().matches("https://www.mollie.com/paymentscreen/creditcard/testmode/[A-Za-z0-9]+"), is(true));
+        assertThat(payment.getLinks().getRedirectUrl(), is("http://example.com"));
+        assertThat(payment.getLinks().getWebhookUrl(), is(is("https://stil4m.github.io")));
+        assertThat(payment.getMode(), is("test"));
+        assertThat(payment.getStatus(), is("open"));
+        assertThat(payment.getMetadata(), is(meta));
+
+    }
+
+    @Test
+    public void testGetPayments() throws IOException, URISyntaxException {
+        ResponseOrError<Page<Payment>> result = payments.list(Optional.empty(), Optional.empty());
+        assertThat(result.getSuccess(), is(true));
+        Page<Payment> page = result.getData();
+
+        assertThat(page.getTotalCount(), is(notNullValue()));
+        assertThat(page.getData().size(), is(Math.min(10, page.getTotalCount())));
+        assertThat(page.getOffset(), is(0));
+        assertThat(page.getCount(), is(10));
+
+        assertThat(page.getLinks().getPrevious().isPresent(), is(false));
+        assertThat(page.getLinks().getNext().isPresent(), is(true));
+        assertThat(page.getLinks().getLast().isPresent(), is(true));
+        assertThat(page.getLinks().getFirst().isPresent(), is(true));
+    }
+
+    @Test
+    public void testGetPaymentsWithOffsetAndCount() throws IOException, URISyntaxException {
+        ResponseOrError<Page<Payment>> result = payments.list(Optional.of(20), Optional.of(40));
+        assertThat(result.getSuccess(), is(true));
+        Page<Payment> page = result.getData();
+
+        assertThat(page.getTotalCount(), is(notNullValue()));
+        assertThat(page.getData().size(), is(Math.min(20, page.getTotalCount())));
+        assertThat(page.getOffset(), is(40));
+        assertThat(page.getCount(), is(20));
+
+        assertThat(page.getLinks().getPrevious().isPresent(), is(true));
+        assertThat(page.getLinks().getNext().isPresent(), is(true));
+        assertThat(page.getLinks().getLast().isPresent(), is(true));
+        assertThat(page.getLinks().getFirst().isPresent(), is(true));
+    }
+
+    @Test
+    public void testNextPayments() throws IOException, URISyntaxException {
+        ResponseOrError<Page<Payment>> result = payments.list(Optional.empty(), Optional.empty());
+        assertThat(result.getSuccess(), is(true));
+        Page<Payment> page = result.getData();
+
+        Page<Payment> nextPage = payments.next(page).getData();
+
+        assertThat(nextPage.getOffset(), is(10));
+        assertThat(nextPage.getCount(), is(10));
+    }
+
+    @Test
+    public void testPreviousPayments() throws IOException, URISyntaxException {
+        ResponseOrError<Page<Payment>> result = payments.list(Optional.of(20), Optional.of(40));
+        assertThat(result.getSuccess(), is(true));
+        Page<Payment> page = result.getData();
+
+        Page<Payment> previousPage = payments.previous(page).getData();
+
+        assertThat(previousPage.getOffset(), is(20));
+        assertThat(previousPage.getCount(), is(20));
+    }
 }

From ba8f57424eff90a1c3faedcc2c45984ed9488d6c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michae=CC=88l=20van=20de=20Giessen?= <mg@smile.nl>
Date: Fri, 28 Oct 2016 10:24:03 +0200
Subject: [PATCH 10/11] ClientBuilderTest and dynamicClient build using method
 reference or orElse

---
 .../stil4m/mollie/DynamicClientBuilder.java   |  4 ++--
 .../nl/stil4m/mollie/ClientBuilderTest.java   | 24 +++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)
 create mode 100644 src/test/java/nl/stil4m/mollie/ClientBuilderTest.java

diff --git a/src/main/java/nl/stil4m/mollie/DynamicClientBuilder.java b/src/main/java/nl/stil4m/mollie/DynamicClientBuilder.java
index 77fa588..3f811dc 100644
--- a/src/main/java/nl/stil4m/mollie/DynamicClientBuilder.java
+++ b/src/main/java/nl/stil4m/mollie/DynamicClientBuilder.java
@@ -30,8 +30,8 @@ public DynamicClientBuilder withMapper(ObjectMapper objectMapper) {
     }
 
     public DynamicClient build() {
-        final HttpClient client = this.client.orElseGet(() -> HttpClientBuilder.create().build());
-        final String endpoint = this.endpoint.orElseGet(() -> "https://api.mollie.com/v1");
+        final HttpClient client = this.client.orElseGet(HttpClientBuilder.create()::build);
+        final String endpoint = this.endpoint.orElse("https://api.mollie.com/v1");
         final ObjectMapper objectMapper = this.objectMapper.orElseGet(ObjectMapper::new);
         objectMapper.registerModule(new Jdk8Module());
         return new DynamicClient(endpoint, new RequestExecutor(client, objectMapper));
diff --git a/src/test/java/nl/stil4m/mollie/ClientBuilderTest.java b/src/test/java/nl/stil4m/mollie/ClientBuilderTest.java
new file mode 100644
index 0000000..d6e561c
--- /dev/null
+++ b/src/test/java/nl/stil4m/mollie/ClientBuilderTest.java
@@ -0,0 +1,24 @@
+package nl.stil4m.mollie;
+
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+public class ClientBuilderTest {
+    
+    ClientBuilder builder = new ClientBuilder();
+    
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testBuildWithoutApiKey() {
+        builder.build();
+    }
+    
+    @Test
+    public void testBuildWithApiKey() {
+        Client client = builder.withApiKey("test").build();
+        
+        assertNotNull(client);
+    }
+}
\ No newline at end of file

From d8b1814c480cebe5591d3ee9ac4bc3ad0d054814 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michae=CC=88l=20van=20de=20Giessen?= <mg@smile.nl>
Date: Fri, 28 Oct 2016 10:58:38 +0200
Subject: [PATCH 11/11] #24 assertWithin using hamcrest lessThanOrEqualTo

---
 src/test/java/nl/stil4m/mollie/TestUtil.java | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/test/java/nl/stil4m/mollie/TestUtil.java b/src/test/java/nl/stil4m/mollie/TestUtil.java
index 0d5c38b..49e6a9f 100644
--- a/src/test/java/nl/stil4m/mollie/TestUtil.java
+++ b/src/test/java/nl/stil4m/mollie/TestUtil.java
@@ -2,7 +2,8 @@
 
 import java.util.Date;
 
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.lessThanOrEqualTo;
 
 public class TestUtil {
 
@@ -14,7 +15,7 @@ public static void assertWithin(Date before, Date target, Date after, Long addit
         long beforeTime = before.getTime() - (before.getTime() % 1000) - additionalSpan;
         long afterTime = after.getTime() - (after.getTime() % 1000) + additionalSpan;
         
-        assertTrue(target+" expected to be after "+new Date(beforeTime),beforeTime <= target.getTime());
-        assertTrue(target+" expected to be before "+new Date(afterTime),target.getTime() <= afterTime);
+        assertThat(new Date(beforeTime), lessThanOrEqualTo(target));
+        assertThat(target, lessThanOrEqualTo(new Date(afterTime)));
     }
 }