### Question:
JceksAWSCredentialProvider implements AWSCredentialsProvider { @Override public AWSCredentials getCredentials() { if (credentials == null) { refresh(); } return credentials; } JceksAWSCredentialProvider(String credentialProviderPath);   JceksAWSCredentialProvider(Configuration conf); @Override AWSCredentials getCredentials(); @Override void refresh();  }### Answer:
@Test public void credentialsFromFile() throws IOException { String jceksPath = "jceks: JceksAWSCredentialProvider provider = new JceksAWSCredentialProvider(jceksPath); AWSCredentials credentials = provider.getCredentials(); assertThat(credentials.getAWSAccessKeyId(), is("access")); assertThat(credentials.getAWSSecretKey(), is("secret")); }
@Test public void credentialsFromConf() throws IOException { when(conf.getPassword(AWSConstants.ACCESS_KEY)).thenReturn("accessKey".toCharArray()); when(conf.getPassword(AWSConstants.SECRET_KEY)).thenReturn("secretKey".toCharArray()); JceksAWSCredentialProvider provider = new JceksAWSCredentialProvider(conf); AWSCredentials credentials = provider.getCredentials(); assertThat(credentials.getAWSAccessKeyId(), is("accessKey")); assertThat(credentials.getAWSSecretKey(), is("secretKey")); }
@Test(expected = IllegalStateException.class) public void secretKeyNotSetInConfThrowsException() throws Exception { when(conf.getPassword(AWSConstants.ACCESS_KEY)).thenReturn("accessKey".toCharArray()); new JceksAWSCredentialProvider(conf).getCredentials(); }
@Test(expected = IllegalStateException.class) public void accessKeyNotSetInConfThrowsException() throws Exception { when(conf.getPassword(AWSConstants.SECRET_KEY)).thenReturn("secretKey".toCharArray()); new JceksAWSCredentialProvider(conf).getCredentials(); }