### Question:
JsonResponseHandler implements HttpResponseHandler<AmazonWebServiceResponse<T>> { @Override public AmazonWebServiceResponse<T> handle(HttpResponse response) throws Exception { log.trace("Parsing service response JSON"); final String crc32Checksum = response.getHeaders().get("x-amz-crc32"); InputStream content = response.getRawContent(); if (content == null) { content = new ByteArrayInputStream("{}".getBytes(StringUtils.UTF8)); } log.debug("CRC32Checksum = " + crc32Checksum); log.debug("content encoding = " + response.getHeaders().get("Content-Encoding")); boolean isGzipEncoded = "gzip".equals(response.getHeaders().get("Content-Encoding")); CRC32ChecksumCalculatingInputStream checksumCalculatingInputStream = null; if (crc32Checksum != null) { checksumCalculatingInputStream = new CRC32ChecksumCalculatingInputStream(content); content = checksumCalculatingInputStream; } if (isGzipEncoded) { content = new GZIPInputStream(content); } final AwsJsonReader jsonReader = JsonUtils.getJsonReader(new InputStreamReader(content, StringUtils.UTF8)); try { final AmazonWebServiceResponse<T> awsResponse = new AmazonWebServiceResponse<T>(); final JsonUnmarshallerContext unmarshallerContext = new JsonUnmarshallerContext(jsonReader, response); final T result = responseUnmarshaller.unmarshall(unmarshallerContext); if (checksumCalculatingInputStream != null) { final long serverSideCRC = Long.parseLong(crc32Checksum); final long clientSideCRC = checksumCalculatingInputStream.getCRC32Checksum(); if (clientSideCRC != serverSideCRC) { throw new CRC32MismatchException( "Client calculated crc32 checksum didn't match that calculated by server side"); } } awsResponse.setResult(result); final Map<String, String> metadata = new HashMap<String, String>(); metadata.put(ResponseMetadata.AWS_REQUEST_ID, response.getHeaders().get("x-amzn-RequestId")); awsResponse.setResponseMetadata(new ResponseMetadata(metadata)); log.trace("Done parsing service response"); return awsResponse; } finally { if (!needsConnectionLeftOpen) { try { jsonReader.close(); } catch (final IOException e) { log.warn("Error closing json parser", e); } } } } JsonResponseHandler(Unmarshaller<T, JsonUnmarshallerContext> responseUnmarshaller); @Override AmazonWebServiceResponse<T> handle(HttpResponse response); @Override boolean needsConnectionLeftOpen(); @SuppressWarnings({"checkstyle:constantname", "checkstyle:visibilitymodifier"})
    public boolean needsConnectionLeftOpen; }### Answer:
@Test public void testHandleWithNoCRC32() throws Exception { ByteArrayInputStream bais = new ByteArrayInputStream( "{\"key\" :\"Content\"}".getBytes(StringUtils.UTF8)); HttpResponse response = new HttpResponse.Builder().statusText("testResponse") .statusCode(200).header("testKey", "testValue").content(bais).build(); Unmarshaller<String, JsonUnmarshallerContext> unmarshaller = new Unmarshaller<String, JsonUnmarshallerContext>() { @Override public String unmarshall(JsonUnmarshallerContext in) throws Exception { in.getReader().beginObject(); in.getReader().nextName(); return in.getReader().nextString(); } }; JsonResponseHandler<String> toTest = new JsonResponseHandler<String>(unmarshaller); AmazonWebServiceResponse<String> awsResponse = toTest.handle(response); assertEquals(awsResponse.getResult(), "Content"); }
@Test public void testHandleWithNullContent() throws Exception { HttpResponse response = new HttpResponse.Builder().statusText("testResponse") .statusCode(200).header("testKey", "testValue").content(null).build(); Unmarshaller<String, JsonUnmarshallerContext> unmarshaller = new Unmarshaller<String, JsonUnmarshallerContext>() { @Override public String unmarshall(JsonUnmarshallerContext in) throws Exception { in.getReader().beginObject(); assertFalse(in.getReader().hasNext()); return "NullContent"; } }; JsonResponseHandler<String> toTest = new JsonResponseHandler<String>(unmarshaller); AmazonWebServiceResponse<String> awsResponse = toTest.handle(response); assertEquals(awsResponse.getResult(), "NullContent"); }