AwsPrivateKeyStore implements PrivateKeyStore { @Override public String getApplicationSecret(final String appName, final String keyName) { return getDecryptedData(appName, keyName); } 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);  }
@Test public void testGetApplicationSecret() { 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"; 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); System.setProperty("athenz.aws.store_kms_decrypt", "true"); AwsPrivateKeyStore awsPrivateKeyStore = new AwsPrivateKeyStore(); AwsPrivateKeyStore spyAWS = Mockito.spy(awsPrivateKeyStore); doReturn(s3).when(spyAWS).getS3(); doReturn(kms).when(spyAWS).getKMS(); String actual = spyAWS.getApplicationSecret(bucketName, keyName); Assert.assertEquals(actual, expected); System.clearProperty("athenz.aws.s3.region"); System.clearProperty(ATHENZ_AWS_KMS_REGION); }