public synchronized String decrypt(String keyRingId, String keyId, String ciphertext) {

    CryptoKeyName keyName = CryptoKeyName.of(projectId, region, keyRingId, keyId);
    LOG.info("Decrypting given ciphertext using key {}.", keyName.toString());

    try (KeyManagementServiceClient client = clientFactory.getKMSClient()) {

      DecryptResponse response =
          client.decrypt(
              keyName,
              ByteString.copyFrom(
                  Base64.getDecoder().decode(ciphertext.getBytes(StandardCharsets.UTF_8))));

      LOG.info("Successfully decrypted ciphertext.");
      return response.getPlaintext().toStringUtf8();
    }
  }
@Test
  public void testDecryptShouldThrowErrorWhenClientFailsToConnect() {
    when(kmsClientFactory.getKMSClient()).thenThrow(KMSResourceManagerException.class);

    assertThrows(
        KMSResourceManagerException.class,
        () -> testManager.decrypt(KEYRING_ID, KEY_ID, "ciphertext"));
  }