### Question:
AwsPrivateKeyStore implements PrivateKeyStore { public AwsPrivateKeyStore() { this(initAmazonS3(), initAWSKMS()); kmsDecrypt = Boolean.parseBoolean(System.getProperty(ATHENZ_PROP_AWS_KMS_DECRYPT, "false")); } AwsPrivateKeyStore();  AwsPrivateKeyStore(final AmazonS3 s3, final AWSKMS kms); @Override PrivateKey getPrivateKey(String service, String serverHostName,
            StringBuilder privateKeyId); @Override String getApplicationSecret(final String appName, final String keyName);  }### Answer:
@Test public void testAwsPrivateKeyStore() { System.setProperty("athenz.aws.s3.region", "us-east-1"); System.setProperty(ATHENZ_AWS_KMS_REGION, "us-east-1"); String bucketName = "my_bucket"; String keyName = "my_key"; String expected = "my_value"; System.setProperty(ATHENZ_PROP_ZTS_BUCKET_NAME, bucketName); System.setProperty("athenz.aws.zts.key_name", keyName); AmazonS3 s3 = mock(AmazonS3.class); AWSKMS kms = mock(AWSKMS.class); S3Object s3Object = mock(S3Object.class); Mockito.when(s3.getObject(bucketName, keyName)).thenReturn(s3Object); InputStream is = new ByteArrayInputStream( expected.getBytes() ); S3ObjectInputStream s3ObjectInputStream = new S3ObjectInputStream(is, null); Mockito.when(s3Object.getObjectContent()).thenReturn(s3ObjectInputStream); ByteBuffer buffer = ByteBuffer.wrap(expected.getBytes()); DecryptResult decryptResult = mock(DecryptResult.class); Mockito.when(kms.decrypt(Mockito.any(DecryptRequest.class))).thenReturn(decryptResult); Mockito.when(decryptResult.getPlaintext()).thenReturn(buffer); AwsPrivateKeyStore awsPrivateKeyStore = new AwsPrivateKeyStore(s3, kms); String actual = awsPrivateKeyStore.getApplicationSecret(bucketName, keyName); StringBuilder privateKeyId = new StringBuilder(keyName); awsPrivateKeyStore.getPrivateKey("zts", "testServerHostName", privateKeyId); Assert.assertEquals(actual, expected); Mockito.when(s3Object.getObjectContent()).thenAnswer(invocation -> { throw new IOException("test IOException"); }); awsPrivateKeyStore.getPrivateKey("zts", "testServerHostName", privateKeyId); System.clearProperty("athenz.aws.s3.region"); System.clearProperty(ATHENZ_AWS_KMS_REGION); }