### Question:
AWSUtils { public AWSError parseAWSErrorFromContent(HttpRequest request, HttpResponse response) { byte[] actualPayload = response.getPayload() != null ? closeClientButKeepContentStream(response) : null; if (actualPayload == null || actualPayload.length == 0) return null; if ("text/plain".equals(response.getPayload().getContentMetadata().getContentType())) return null; try { AWSError error = factory.create(errorHandlerProvider.get()).setContext(request).apply(response); if (error.getRequestId() == null) error.setRequestId(response.getFirstHeaderOrNull(requestId)); error.setRequestToken(response.getFirstHeaderOrNull(requestToken)); if ("SignatureDoesNotMatch".equals(error.getCode())) { error.setStringSigned(signer.createStringToSign(request)); error.setSignature(signer.sign(error.getStringSigned())); } return error; } catch (RuntimeException e) { logger.warn(e, "error parsing error"); return null; } } @Inject  AWSUtils(@Named(PROPERTY_HEADER_TAG) String headerTag, RequestSigner signer, Factory factory,
         Provider<ErrorHandler> errorHandlerProvider); AWSError parseAWSErrorFromContent(HttpRequest request, HttpResponse response); static R indexStringArrayToFormValuesWithStringFormat(R request, String format,
         Object input); static boolean isRegion(String regionName); static R indexIterableToFormValuesWithPrefix(R request, String prefix, Object input); static R indexStringArrayToFormValuesWithPrefix(R request, String prefix, Object input); static R indexMapToFormValuesWithPrefix(R request, String prefix, String keySuffix, String valueSuffix, Object input); static R indexMultimapToFormValuesWithPrefix(R request, String prefix, String keySuffix, String valueSuffix, Object input); static R indexMapOfIterableToFormValuesWithPrefix(R request, String prefix, String keySuffix, String valueSuffix, Object input); static String getRegionFromLocationOrNull(Location location); static String[] parseHandle(String id); static String findRegionInArgsOrNull(GeneratedHttpRequest gRequest);  }### Answer:
@Test public void testNoExceptionWhenNoPayload() { HttpResponse response = HttpResponse.builder().statusCode(BAD_REQUEST.getStatusCode()).build(); assertNull(utils.parseAWSErrorFromContent(command.getCurrentRequest(), response)); }
@Test public void testNoExceptionParsingTextPlain() { HttpResponse response = HttpResponse.builder().statusCode(BAD_REQUEST.getStatusCode()).payload("foo bar").build(); response.getPayload().getContentMetadata().setContentType(TEXT_PLAIN); assertNull(utils.parseAWSErrorFromContent(command.getCurrentRequest(), response)); }
@Test public void testNoExceptionEmptyPayload() { RequestSigner requestSigner = createMock(RequestSigner.class); ParseSax.Factory factory = createMock(ParseSax.Factory.class); Provider provider = createMock(Provider.class); replay(requestSigner, factory, provider); AWSUtils riggedUtil = new AWSUtils( "ignore", requestSigner, factory, provider ); HttpResponse response = HttpResponse.builder().statusCode(NOT_FOUND.getStatusCode()).payload(new StringPayload("")).build(); response.getPayload().getContentMetadata().setContentType("application/unknown"); assertNull(riggedUtil.parseAWSErrorFromContent(command.getCurrentRequest(), response)); }
@Test public void testParseAWSErrorFromContentHttpCommandHttpResponseInputStream() { AWSError error = utils.parseAWSErrorFromContent(command.getCurrentRequest(), response(getClass() .getResourceAsStream("/error.xml"))); assertEquals(error.getCode(), "NoSuchKey"); assertEquals(error.getMessage(), "The resource you requested does not exist"); assertEquals(error.getRequestToken(), "requesttoken"); assertEquals(error.getRequestId(), "4442587FB7D0A2F9"); assertEquals(error.getDetails().get("Resource"), "/mybucket/myfoto.jpg"); }