### Question:
AWSCredentialsProviderChain implements AWSCredentialsProvider { public AWSCredentials getCredentials() { if (reuseLastProvider && lastUsedProvider != null) { return lastUsedProvider.getCredentials(); } for (AWSCredentialsProvider provider : credentialsProviders) { try { AWSCredentials credentials = provider.getCredentials(); if (credentials instanceof IBMOAuthCredentials) { log.debug("Loading OAuth credentials from " + provider.toString()); lastUsedProvider = provider; return credentials; } if (credentials.getAWSAccessKeyId() != null && credentials.getAWSSecretKey() != null) { log.debug("Loading credentials from " + provider.toString()); lastUsedProvider = provider; return credentials; } } catch (Exception e) { log.debug("Unable to load credentials from " + provider.toString() + ": " + e.getMessage()); } } throw new SdkClientException("Unable to load AWS credentials from any provider in the chain"); } AWSCredentialsProviderChain(List<? extends AWSCredentialsProvider> credentialsProviders);  AWSCredentialsProviderChain(AWSCredentialsProvider... credentialsProviders); boolean getReuseLastProvider(); void setReuseLastProvider(boolean b); AWSCredentials getCredentials(); void refresh();  }### Answer:
@Test public void testReusingLastProvider() throws Exception { MockCredentialsProvider provider1 = new MockCredentialsProvider(); provider1.throwException = true; MockCredentialsProvider provider2 = new MockCredentialsProvider(); AWSCredentialsProviderChain chain = new AWSCredentialsProviderChain(provider1, provider2); assertEquals(0, provider1.getCredentialsCallCount); assertEquals(0, provider2.getCredentialsCallCount); chain.getCredentials(); assertEquals(1, provider1.getCredentialsCallCount); assertEquals(1, provider2.getCredentialsCallCount); chain.getCredentials(); assertEquals(1, provider1.getCredentialsCallCount); assertEquals(2, provider2.getCredentialsCallCount); chain.getCredentials(); assertEquals(1, provider1.getCredentialsCallCount); assertEquals(3, provider2.getCredentialsCallCount); }