### Question:
ContainerCredentialsFetcher extends BaseCredentialsFetcher { @Override public String toString() { return "ContainerCredentialsFetcher"; } ContainerCredentialsFetcher(CredentialsEndpointProvider credentialsEndpointProvider); @Override String toString();  }### Answer:
@Test public void testNoMetadataService() throws Exception { stubForErrorResponse(); TestCredentialsProvider credentialsProvider = new TestCredentialsProvider(); try { credentialsProvider.getCredentials(); fail("Expected an AmazonClientException, but wasn't thrown"); } catch (AmazonClientException ace) { assertNotNull(ace.getMessage()); } stubForSuccessResonseWithCustomExpirationDate(200, new Date(System.currentTimeMillis() + ONE_MINUTE * 4).toString()); credentialsProvider.getCredentials(); credentialsProvider.setLastInstanceProfileCheck(new Date(System.currentTimeMillis() - (ONE_MINUTE * 61))); stubForErrorResponse(); try { credentialsProvider.getCredentials(); fail("Expected an AmazonClientException, but wasn't thrown"); } catch (AmazonClientException ace) { assertNotNull(ace.getMessage()); } }
@Test public void testNeedsToLoadCredentialsMethod() throws Exception { TestCredentialsProvider credentialsProvider = new TestCredentialsProvider(); stubForSuccessResonseWithCustomExpirationDate(200, DateUtils.formatISO8601Date(new Date(System.currentTimeMillis() + ONE_MINUTE * 60 * 24)).toString()); credentialsProvider.getCredentials(); assertFalse(credentialsProvider.needsToLoadCredentials()); stubForSuccessResonseWithCustomExpirationDate(200, DateUtils.formatISO8601Date(new Date(System.currentTimeMillis() + ONE_MINUTE * 16)).toString()); credentialsProvider.getCredentials(); credentialsProvider.setLastInstanceProfileCheck(new Date(System.currentTimeMillis() - ONE_MINUTE * 61)); assertTrue(credentialsProvider.needsToLoadCredentials()); stubForSuccessResonseWithCustomExpirationDate(200, DateUtils.formatISO8601Date(new Date(System.currentTimeMillis() + ONE_MINUTE * 14)).toString()); credentialsProvider.getCredentials(); assertTrue(credentialsProvider.needsToLoadCredentials()); }
@Test public void testNoMetadataService() throws Exception { stubForErrorResponse(); TestCredentialsProvider credentialsProvider = new TestCredentialsProvider(); try { credentialsProvider.getCredentials(); fail("Expected an AmazonClientException, but wasn't thrown"); } catch (AmazonClientException ace) { assertNotNull(ace.getMessage()); } stubForSuccessResonseWithCustomExpirationDate(200, new Date(System.currentTimeMillis() + ONE_MINUTE * 4).toString()); AWSCredentials firstCredentials = credentialsProvider.getCredentials(); credentialsProvider.setLastInstanceProfileCheck(new Date(System.currentTimeMillis() - (ONE_MINUTE * 61))); stubForErrorResponse(); AWSCredentials secondCredentials = credentialsProvider.getCredentials(); assertSame(firstCredentials, secondCredentials); }