### Question:
AWSHandler extends XRayHandler { @Override public void handleResponse(Event event) { ServiceResponseEvent responseEvent = (ServiceResponseEvent) event; Request awsReq = (Request) responseEvent.getRequest().getRequest(); Response awsResp = (Response) responseEvent.getResponse(); if (responseEvent.getThrown() == null) { tracingHandler.afterResponse(awsReq, awsResp); } else { Throwable exception = responseEvent.getThrown(); tracingHandler.afterError(awsReq, awsResp, (Exception) exception); } } AWSHandler();  AWSHandler(URL serviceHandlerManifest); @Override void handleRequest(Event event); @Override void handleResponse(Event event);  }### Answer:
@Test public void testHandleAWSResponse() { ServiceDownstreamRequestEvent awsRequestEvent = new ServiceDownstreamRequestEvent(ORIGIN, SERVICE, OPERATION); awsRequestEvent.withRequest(awsRequest); ServiceDownstreamResponseEvent awsResponseEvent = new ServiceDownstreamResponseEvent(ORIGIN, SERVICE, OPERATION, awsRequestEvent); awsResponseEvent.withResponse(awsResponse); Subsegment awsSubsegment = AWSXRay.beginSubsegment(SERVICE); awsSubsegment.setNamespace("aws"); awsHandler.handleResponse(awsResponseEvent); Map<String, Object> awsMap = awsSubsegment.getAws(); Assert.assertEquals(AWS_REQUEST_ID, awsMap.get("request_id")); Assert.assertEquals(SCAN_COUNT, awsMap.get("scanned_count")); Assert.assertEquals(COUNT, awsMap.get("count")); Map<String, Object> httpMap = awsSubsegment.getHttp(); Assert.assertEquals(200, ((Map<String, Integer>) httpMap.get("response")).get("status").intValue()); }
@Test public void testHandleEventFault() { ServiceDownstreamRequestEvent awsRequestEvent = new ServiceDownstreamRequestEvent(ORIGIN, SERVICE, OPERATION); awsRequestEvent.withRequest(awsRequest); ServiceDownstreamResponseEvent awsResponseEvent = new ServiceDownstreamResponseEvent(ORIGIN, SERVICE, OPERATION, awsRequestEvent); awsResponseEvent.withResponse(null); awsResponseEvent.withThrown(new AmazonDynamoDBException("Some error")); Subsegment awsSubsegment = AWSXRay.beginSubsegment(SERVICE); awsSubsegment.setNamespace("aws"); Assert.assertEquals(0, awsSubsegment.getCause().getExceptions().size()); awsHandler.handleResponse(awsResponseEvent); Assert.assertEquals(1, awsSubsegment.getCause().getExceptions().size()); Assert.assertTrue(awsSubsegment.isFault()); }