public static void verifyExpectedContextData(ContextDataCollection contextDataCollection,
                                                 AmazonWebServiceRequest failedRequest,
                                                 AmazonClientException expectedException,
                                                 int expectedRetries) {
        
        Assert.assertEquals(expectedRetries, contextDataCollection.failedRequests.size());
        Assert.assertEquals(expectedRetries, contextDataCollection.exceptions.size());
        Assert.assertEquals(expectedRetries, contextDataCollection.retriesAttemptedValues.size());
        
        if (expectedRetries > 0 ) {
            if (failedRequest != null) {
                // It should keep getting the same original request instance
                for (AmazonWebServiceRequest seenRequest : contextDataCollection.failedRequests) {
                    Assert.assertTrue("seeRequest=" + seenRequest
                            + ", failedRequest=" + failedRequest,
                            seenRequest == failedRequest);
                }
            }
            
            // Verify the exceptions
            if (expectedException instanceof AmazonServiceException) {
                // It should get service exceptions with the expected error and status code
                AmazonServiceException ase = (AmazonServiceException)expectedException;
                for (AmazonClientException seenException : contextDataCollection.exceptions) {
                    Assert.assertTrue(seenException instanceof AmazonServiceException);
                    Assert.assertEquals(ase.getErrorCode(), ((AmazonServiceException)seenException).getErrorCode());
                    Assert.assertEquals(ase.getStatusCode(), ((AmazonServiceException)seenException).getStatusCode());
                }
            } else if (expectedException != null) {
                // Client exceptions should have the same expected cause (the same
                // throwable instance from the mock HttpClient).
                Throwable expectedCause = expectedException.getCause();
                for (AmazonClientException seenException : contextDataCollection.exceptions) {
                    Assert.assertTrue(expectedCause == seenException.getCause());
                }
            }
            
            // It should get "retriesAttempted" values starting from 0
            int expectedRetriesAttempted = 0;
            for (int seenRetriesAttempted : contextDataCollection.retriesAttemptedValues) {
                Assert.assertEquals(expectedRetriesAttempted++, seenRetriesAttempted);
            }
        }
        
    }
Verifies the RetryCondition has collected the expected context information.
aws-java-sdk-core/src/test/java/com/amazonaws/retry/RetryPolicyTestBase.java