diff --git a/voto-async/src/test/java/com/addhen/voto/sdk/async/test/AsyncVotoApiClientTest.java b/voto-async/src/test/java/com/addhen/voto/sdk/async/test/AsyncVotoApiClientTest.java index bc6703b..dd6f114 100644 --- a/voto-async/src/test/java/com/addhen/voto/sdk/async/test/AsyncVotoApiClientTest.java +++ b/voto-async/src/test/java/com/addhen/voto/sdk/async/test/AsyncVotoApiClientTest.java @@ -55,6 +55,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; + /** * @author Henry Addo */ @@ -101,7 +102,7 @@ public void shouldThrowExceptionWhenIdIsNull() throws IOException { } @Test - public void shouldSuccessfullyCreateSubscriber() throws IOException { + public void shouldSuccessfullyCreateSubscriber() throws IOException, InterruptedException { mAsyncVotoApiClient .createSubscriber("0243555333889", null, new Callback() { @Override @@ -110,24 +111,22 @@ public void onResponse(Call call, CreateSubscriberResponse createSubscriberResponse = response.body(); assertNotNull(createSubscriberResponse); assertNotNull(createSubscriberResponse.data); - assertEquals(430l, (long) createSubscriberResponse.data.id); + assertEquals(11, (long) createSubscriberResponse.data.id); + mCountDownLatch.countDown(); } @Override public void onFailure(Call call, Throwable t) { + mCountDownLatch.countDown(); } }); - try { - mCountDownLatch.await(30, TimeUnit.SECONDS); - } catch (InterruptedException e) { - fail(e.getMessage()); - } + mCountDownLatch.await(30, TimeUnit.SECONDS); } @Test - public void shouldSuccessfullyCreateBulkSubscribers() throws IOException { + public void shouldSuccessfullyCreateBulkSubscribers() throws IOException, InterruptedException { mAsyncVotoApiClient.createBulkSubscribers("02345", null, null, new Callback() { @@ -153,15 +152,11 @@ public void onFailure(Call call, } }); - try { - mCountDownLatch.await(40, TimeUnit.SECONDS); - } catch (InterruptedException e) { - fail(e.getMessage()); - } + mCountDownLatch.await(40, TimeUnit.SECONDS); } @Test - public void shouldSuccessfullyDeleteSubscriber() throws IOException { + public void shouldSuccessfullyDeleteSubscriber() throws IOException, InterruptedException { mAsyncVotoApiClient.deleteSubscriber(1l, new Callback() { @@ -172,17 +167,19 @@ public void onResponse(Call call, assertNotNull(response); assertEquals(200, (int) response.status); assertEquals("Successfully deleted subscriber", response.message); + mCountDownLatch.countDown(); } @Override public void onFailure(Call call, Throwable t) { - + mCountDownLatch.countDown(); } }); + mCountDownLatch.await(40, TimeUnit.SECONDS); } @Test - public void shouldSuccessfullyListSubscribers() throws IOException { + public void shouldSuccessfullyListSubscribers() throws IOException, InterruptedException { mAsyncVotoApiClient.listSubscribers(10, new Callback() { @@ -226,17 +223,19 @@ public void onResponse(Call call, assertEquals("Ejisu", response.data.subscribers.get(0).properties.location); assertEquals("Out flying kites", response.data.subscribers.get(0).properties.comments); + mCountDownLatch.countDown(); } @Override public void onFailure(Call call, Throwable t) { - + mCountDownLatch.countDown(); } }); + mCountDownLatch.await(40, TimeUnit.SECONDS); } @Test - public void shouldSuccessfullyModifySubscriber() throws IOException { + public void shouldSuccessfullyModifySubscriber() throws IOException, InterruptedException { mAsyncVotoApiClient .modifySubscriberDetails(1l, null, new Callback() { @Override @@ -244,17 +243,20 @@ public void onResponse(Call call, Response resp) { CreateSubscriberResponse createSubscriberResponse = resp.body(); assertNotNull(createSubscriberResponse); + mCountDownLatch.countDown(); } @Override public void onFailure(Call call, Throwable t) { // Do nothing + mCountDownLatch.countDown(); } }); + mCountDownLatch.await(40, TimeUnit.SECONDS); } @Test - public void shouldSuccessfullyListSubscriberDetails() throws IOException { + public void shouldSuccessfullyListSubscriberDetails() throws IOException, InterruptedException { mAsyncVotoApiClient .listSubscriberDetails(1l, new Callback() { @Override @@ -262,13 +264,16 @@ public void onResponse(Call call, Response resp) { SubscriberDetailsResponse createSubscriberResponse = resp.body(); assertNotNull(createSubscriberResponse); + mCountDownLatch.countDown(); } @Override public void onFailure(Call call, Throwable t) { // Do nothing + mCountDownLatch.countDown(); } }); + mCountDownLatch.await(40, TimeUnit.SECONDS); } @Test diff --git a/voto/src/test/java/com/addhen/voto/sdk/test/BaseTestCase.java b/voto/src/test/java/com/addhen/voto/sdk/test/BaseTestCase.java index 13fad5b..bc97dca 100644 --- a/voto/src/test/java/com/addhen/voto/sdk/test/BaseTestCase.java +++ b/voto/src/test/java/com/addhen/voto/sdk/test/BaseTestCase.java @@ -31,6 +31,7 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Random; +import java.util.concurrent.Executor; import retrofit2.Retrofit; import retrofit2.mock.BehaviorDelegate; @@ -69,7 +70,6 @@ protected static String formatShowingDate(Date date) { } protected MockVotoService getMockVotoService() { - // Create a very simple Retrofit adapter which points the GitHub API. Retrofit retrofit = new Retrofit.Builder() .baseUrl("http://www.demo.com") .build(); @@ -86,4 +86,12 @@ protected MockVotoService getMockVotoService() { .create(VotoService.class); return new MockVotoService(votoServiceBehaviorDelegate, gsonDeserializer); } + + private static class Synchronous implements Executor { + + @Override + public void execute(Runnable command) { + command.run(); + } + } } \ No newline at end of file