### Question:
AWSCredentialUtils { static String getKey(Configuration conf, String keyType) { checkNotNull(conf, "conf cannot be null"); checkNotNull(keyType, "KeyType cannot be null"); try { char[] key = conf.getPassword(keyType); if (key == null) { throw new IllegalStateException(format("Unable to get value of '%s'", keyType)); } return new String(key); } catch (IOException e) { throw new RuntimeException(format("Error getting key for '%s' from credential provider", keyType), e); } } private  AWSCredentialUtils(); static Configuration configureCredentialProvider(String credentialProviderPath); static Configuration configureCredentialProvider(String credentialProviderPath, Configuration conf);  }### Answer:
@Test public void getAccessKeyFromConfTest() throws Exception { Configuration conf = new Configuration(); conf.set(AWSConstants.ACCESS_KEY, "access"); conf.set(AWSConstants.SECRET_KEY, "secret"); String access = AWSCredentialUtils.getKey(conf, AWSConstants.ACCESS_KEY); assertThat(access, is("access")); }
@Test public void getSecretKeyFromConfTest() throws Exception { Configuration conf = new Configuration(); conf.set(AWSConstants.ACCESS_KEY, "access"); conf.set(AWSConstants.SECRET_KEY, "secret"); String secret = AWSCredentialUtils.getKey(conf, AWSConstants.SECRET_KEY); assertThat(secret, is("secret")); }
@Test(expected = IllegalStateException.class) public void getKeyFromConfWhichIsntSetThrowsExceptionTest() throws Exception { Configuration conf = new Configuration(); AWSCredentialUtils.getKey(conf, AWSConstants.SECRET_KEY); }
@Test(expected = RuntimeException.class) public void getKeyThrowsRuntimeExceptionTest() throws Exception { Configuration conf = mock(Configuration.class); when(conf.getPassword(anyString())).thenThrow(new IOException()); AWSCredentialUtils.getKey(conf, AWSConstants.SECRET_KEY); }