DefaultHttpJsonResponse implements HttpJsonResponse { @Override public <T> T asDto(Class<T> dtoInterface) { requireNonNull(dtoInterface, "Required non-null dto interface"); return DtoFactory.getInstance().createDtoFromJson(responseBody, dtoInterface); } DefaultHttpJsonResponse(String response, int responseCode); @Override String asString(); @Override T asDto(Class<T> dtoInterface); @Override List<T> asList(Class<T> dtoInterface); @Override @SuppressWarnings("unchecked") Map<String, String> asProperties(); @Override T as(Class<T> clazz, Type genericType); @Override int getResponseCode();  }
@Test public void shouldReturnJsonSerializableInstanceIfItWasRequested() throws Exception { final Link testLink = createLink("POST", "http: final DefaultHttpJsonResponse response = new DefaultHttpJsonResponse(DtoFactory.getInstance().toJson(testLink), 200); assertEquals(response.asDto(Link.class), testLink); }
@Test(expectedExceptions = NullPointerException.class) public void shouldThrowNullPointerExceptionWhenDtoInterfaceIsNull() throws Exception { new DefaultHttpJsonResponse("{}", 200).asDto(null); }