@Test public void modelsWithParams() { String email = "foo@foo.bar"; List<Model> models = restApi.modelsWithParams(email, null); assertThat(models.size(), is(1)); assertThat(models.get(0).getS1(), is(Model.class.getName())); }
@Test public void modelsWithParamsFailsWhenInvalidEmail() { exception.expect(AssertionError.class); restApi.modelsWithParams("", null); }
@Test public void modelsWithParamsSync() throws IOException { RequestBody requestBody = RequestBody .create(MediaType.parse("text/plain"), "foo@foo.bar"); Response<List<Model>> responseModels = restApi.modelsWithParams(requestBody, null).execute(); assertTrue(responseModels.isSuccessful()); List<Model> models = responseModels.body(); assertThat(models.size(), is(1)); assertThat(models.get(0).getS1(), is(Model.class.getName())); }
@Test public void modelsWithParamsFailsWhenInvalidEmailSync() throws IOException { RequestBody requestBody = RequestBody .create(MediaType.parse("text/plain"), ""); Response<List<Model>> responseModels = restApi.modelsWithParams(requestBody, null).execute(); assertFalse(responseModels.isSuccessful()); ResponseBody responseBody = responseModels.errorBody(); assertThat(responseBody.string(), is("empty does not match with regex EMAIL")); }
@Test public void modelsWithParamsFailsWhenInvalidEmailAsync() throws Exception { RequestBody requestBody = RequestBody .create(MediaType.parse("text/plain"), ""); final AtomicReference<Response<List<Model>>> atomicReference = new AtomicReference<>(); final CountDownLatch latch = new CountDownLatch(1); restApi.modelsWithParams(requestBody, null) .enqueue(new Callback<List<Model>>() { @Override public void onResponse(Call<List<Model>> call, Response<List<Model>> response) { atomicReference.set(response); latch.countDown(); } @Override public void onFailure(Call<List<Model>> call, Throwable t) { t.printStackTrace(); } }); assertTrue(latch.await(10, SECONDS)); Response<List<Model>> responseModels = atomicReference.get(); assertFalse(responseModels.isSuccessful()); ResponseBody responseBody = responseModels.errorBody(); assertThat(responseBody.string(), is("empty does not match with regex EMAIL")); }
@Test public void modelsWithParamsAsync() throws Exception { RequestBody requestBody = RequestBody .create(MediaType.parse("text/plain"), "foo@foo.bar"); final AtomicReference<Response<List<Model>>> atomicReference = new AtomicReference<>(); final CountDownLatch latch = new CountDownLatch(1); restApi.modelsWithParams(requestBody, null) .enqueue(new Callback<List<Model>>() { @Override public void onResponse(Call<List<Model>> call, Response<List<Model>> response) { atomicReference.set(response); latch.countDown(); } @Override public void onFailure(Call<List<Model>> call, Throwable t) { t.printStackTrace(); } }); assertTrue(latch.await(10, SECONDS)); Response<List<Model>> responseModels = atomicReference.get(); assertTrue(responseModels.isSuccessful()); List<Model> models = responseModels.body(); assertThat(models.size(), is(1)); assertThat(models.get(0).getS1(), is(Model.class.getName())); }