@Test public void model() { Model model = restApi.model(); assertThat(model.getS1(), is(Model.class.getName())); }
@Test public void modelWithWrongDTO() { try { restApi.modelWithWrongDTO(); fail(); } catch (RuntimeException e) { assertThat(e.getMessage(), is("When checking DTOMockery on method RestApi#modelWithWrongDTO \n" + " an attempt to use it with class io.victoralbertos.mockery.internal.integration.Model was found. But it is not a supported type for DTOMockery.\n" + "To fix it, use DTOMockery with: [java.util.List<io.victoralbertos.mockery.internal.integration.Model>].\n")); } }
@Test public void modelWithWrongMockeryParam() { Model model = new Model(Model.class.getName()); exception.expect(RuntimeException.class); restApi.modelWithWrongMockeryParam(model); }
@Test public void modelWithParamsFailsWhenInvalidJson() { Model model = new Model(Model.class.getName()); exception.expect(AssertionError.class); restApi.modelWithParams(model, 0, "{\"s1\":\"\"}"); }
@Test public void modelWithoutDTO() { try { restApi.modelWithoutDTO(); fail(); } catch (RuntimeException e) { assertThat(e.getMessage(), is("When checking method RestApi#modelWithoutDTO \n" + "No @Mockery annotation for return method was found.\n" + "To fix it, annotate method with one.\n")); } }
@Test public void modelsWithParamWithoutMockery() { exception.expect(RuntimeException.class); restApi.modelsWithParamWithoutMockery(3); }
@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 models() { List<Model> models = restApi.models(); assertThat(models.size(), is(1)); assertThat(models.get(0).getS1(), is(Model.class.getName())); }
@Test public void integerAsync() throws Exception { final AtomicReference<Response<Integer>> atomicReference = new AtomicReference<>(); final CountDownLatch latch = new CountDownLatch(1); restApi.integer().enqueue(new Callback<Integer>() { @Override public void onResponse(Call<Integer> call, Response<Integer> response) { atomicReference.set(response); latch.countDown(); } @Override public void onFailure(Call<Integer> call, Throwable t) { t.printStackTrace(); } }); assertTrue(latch.await(10, SECONDS)); Response<Integer> integerResponse = atomicReference.get(); assertTrue(integerResponse.isSuccessful()); Integer integer = integerResponse.body(); assertThat(integer, is(30)); }
@Test public void modelWithParamsFailsWhenInvalidRequestBody() { RequestBody requestBody = RequestBody .create(MediaType.parse("text/plain"), "{\"s1\":\"\"}"); TestSubscriber<Model> subscriber = new TestSubscriber<>(); restApi.modelWithParams(requestBody, 0).subscribe(subscriber); subscriber.awaitTerminalEvent(); subscriber.assertNoValues(); subscriber.assertError(HttpException.class); Throwable error = subscriber.getOnErrorEvents().get(0); assertThat(error.getMessage(), is("HTTP 404 null")); }
@Test public void modelWithoutDTO() { try { restApi.modelWithoutDTO(); fail(); } catch (RuntimeException e) { assertThat(e.getMessage(), is("When checking method RestApi#modelWithoutDTO \n" + "No @Mockery annotation for return method was found.\n" + "To fix it, annotate method with one.\n")); } }
@Test public void modelsWithParamWithoutMockery() { exception.expect(RuntimeException.class); restApi.modelsWithParamWithoutMockery(3); }
@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 modelsSync() throws IOException { Response<List<Model>> responseModels = restApi.models("[{\"s1\":\"io.victoralbertos.mockery.internal.integration.Model\"}]").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 integerSync() throws IOException { Response<Integer> integerResponse = restApi.integer().execute(); assertTrue(integerResponse.isSuccessful()); Integer integer = integerResponse.body(); assertThat(integer, is(30)); }
@Test public void modelWithParamsSync() throws IOException { RequestBody requestBody = RequestBody .create(MediaType.parse("text/plain"), "{\"s1\":\"io.victoralbertos.mockery.internal.integration.Model\"}"); Response<Model> responseModel = restApi .modelWithParams(requestBody, 0).execute(); assertTrue(responseModel.isSuccessful()); Model model = responseModel.body(); assertThat(model.getS1(), is(Model.class.getName())); }
@Test public void modelAsync() throws Exception { final AtomicReference<Response<Model>> atomicReference = new AtomicReference<>(); final CountDownLatch latch = new CountDownLatch(1); restApi.model().enqueue(new Callback<Model>() { @Override public void onResponse(Call<Model> call, Response<Model> response) { atomicReference.set(response); latch.countDown(); } @Override public void onFailure(Call<Model> call, Throwable t) { t.printStackTrace(); } }); assertTrue(latch.await(10, SECONDS)); Response<Model> responseModel = atomicReference.get(); assertTrue(responseModel.isSuccessful()); Model model = responseModel.body(); assertThat(model.getS1(), is(Model.class.getName())); }
@Test public void modelWithWrongDTO() { try { restApi.modelWithWrongDTO(); fail(); } catch (RuntimeException e) { assertThat(e.getMessage(), is("When checking DTOMockery on method RestApi#modelWithWrongDTO \n" + " an attempt to use it with class io.victoralbertos.mockery.internal.integration.Model was found. But it is not a supported type for DTOMockery.\n" + "To fix it, use DTOMockery with: [java.util.List<io.victoralbertos.mockery.internal.integration.Model>].\n")); } }
@Test public void modelWithWrongMockeryParam() { Model model = new Model(Model.class.getName()); exception.expect(RuntimeException.class); restApi.modelWithWrongMockeryParam(model); }
@Test public void modelWithoutDTO() { try { restApi.modelWithoutDTO(); fail(); } catch (RuntimeException e) { assertThat(e.getMessage(), is("When checking method RestApi#modelWithoutDTO \n" + "No @Mockery annotation for return method was found.\n" + "To fix it, annotate method with one.\n")); } }