ImagesRestApi extends ApiBase implements ImagesApi { @Override public void getImageAsync(final String imageId, final FutureCallback<Image> responseCallback) throws IOException { final String path = String.format("%s/%s", getBasePath(), imageId); getObjectByPathAsync(path, responseCallback, new TypeReference<Image>() { }); } ImagesRestApi(RestClient restClient); @Override String getBasePath(); @Override Task uploadImage(String inputFileName); @Override Task uploadImage(String inputFileName, String replicationType); @Override Task uploadImage(FileBody fileBody, String replicationType); @Override Image getImage(String imageId); @Override void getImageAsync(final String imageId, final FutureCallback<Image> responseCallback); @Override ResourceList<Image> getImages(); @Override void getImagesAsync(final FutureCallback<ResourceList<Image>> responseCallback); @Override Task delete(String id); @Override void deleteAsync(final String id, final FutureCallback<Task> responseCallback);  }
@Test public void testGetImageAsync() throws IOException, InterruptedException { final Image image = new Image(); image.setId("image1"); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(image); setupMocks(serializedTask, HttpStatus.SC_OK); ImagesApi imagesApi = new ImagesRestApi(this.restClient); final CountDownLatch latch = new CountDownLatch(1); imagesApi.getImageAsync(image.getId(), new FutureCallback<Image>() { @Override public void onSuccess(@Nullable Image result) { assertEquals(result, image); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }