@Test
public void testEncryptShouldThrowExceptionIfRequestFailed() throws Exception {

  AmazonServiceException exception = mock(AmazonServiceException.class);
  when(mockKms.encrypt(isA(EncryptRequest.class)))
      .thenThrow(exception);
  Aead aead = new AwsKmsAead(mockKms, KEY_ID);
  byte[] aad = Random.randBytes(20);
  byte[] message = Random.randBytes(20);
  try {
    aead.encrypt(message, aad);
    fail("Expected GeneralSecurityException");
  } catch (GeneralSecurityException e) {
    // expected.
  }
}