@Test
  public void testDecryptionFailure() throws InstantiationException {
    String key = TestUtils.getRandomKey(DEFAULT_KEY_SIZE_IN_CHARS);
    Properties props = getKMSProperties(key, DEFAULT_KEY_SIZE_IN_CHARS);
    VerifiableProperties verifiableProperties = new VerifiableProperties((props));
    SecretKeySpec secretKeySpec = new SecretKeySpec(Hex.decode(key), "AES");
    CryptoService<SecretKeySpec> cryptoService =
        new GCMCryptoServiceFactory(verifiableProperties, REGISTRY).getCryptoService();
    int size = TestUtils.RANDOM.nextInt(MAX_DATA_SIZE);
    byte[] randomData = new byte[size];
    TestUtils.RANDOM.nextBytes(randomData);
    ByteBuffer toDecrypt = ByteBuffer.wrap(randomData);
    try {
      cryptoService.decrypt(toDecrypt, secretKeySpec);
      Assert.fail("Decryption should have failed as input data is not encrypted");
    } catch (GeneralSecurityException e) {
    }

    try {
      cryptoService.decryptKey(toDecrypt, secretKeySpec);
      Assert.fail("Decryption of key should have failed as input data is not encrypted");
    } catch (GeneralSecurityException e) {
    }
  }
Tests failure scenarios for decryption
@throws InstantiationException
ambry-router/src/test/java/com/github/ambry/router/GCMCryptoServiceTest.java