Created
November 6, 2013 18:22
-
-
Save billy-bacon/7341420 to your computer and use it in GitHub Desktop.
AWSCredentialsFactoryTest snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@After | |
public void after() { | |
System.clearProperty("AWS_ACCESS_KEY_ID"); | |
System.clearProperty("AWS_SECRET_KEY"); | |
} | |
@Test | |
public void should_get_aws_credentials_in_local_environment() throws Exception { | |
// setup test | |
System.setProperty("AWS_ACCESS_KEY_ID", "foo"); | |
System.setProperty("AWS_SECRET_KEY", "bar"); | |
final AWSCredentialsProvider provider = mock(AWSCredentialsProvider.class); | |
final AWSCredentialsFactory factory = new AWSCredentialsFactory(provider); | |
// run test | |
final AWSCredentials credentials = factory.getCredentials(); | |
// describe and verify expected behavior | |
assertNotNull(credentials); | |
assertTrue(credentials instanceof BasicAWSCredentials); | |
} | |
@Test(expected = AmazonClientException.class) | |
public void should_get_aws_credentials_in_aws_environment_failure() throws Exception { | |
// setup test | |
AWSCredentialsProvider provider = mock(AWSCredentialsProvider.class); | |
when(provider.getCredentials()).thenThrow(new AmazonClientException("test - expected failure")); | |
final AWSCredentialsFactory factory = new AWSCredentialsFactory(provider); | |
// run test | |
// nothing to run here; since we aren't in an AWS environment, the constructor call above will throw an AmazonClientException | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment