@SuppressWarnings("deprecation") // This is a test for the deprecated function
  @Test
  public void deprecated_readNoSecretWithBytesInput_sameAs_parseKeysetWithoutSecret()
      throws Exception {
    // Public keyset should have the same output
    KeysetHandle privateHandle = KeysetHandle.generateNew(KeyTemplates.get("ECDSA_P256"));
    byte[] serializedPublicKeyset = privateHandle.getPublicKeysetHandle().getKeyset().toByteArray();

    KeysetHandle readNoSecretOutput = KeysetHandle.readNoSecret(serializedPublicKeyset);
    KeysetHandle parseKeysetWithoutSecretOutput =
        TinkProtoKeysetFormat.parseKeysetWithoutSecret(serializedPublicKeyset);
    expect
        .that(readNoSecretOutput.getKeyset())
        .isEqualTo(parseKeysetWithoutSecretOutput.getKeyset());

    // Symmetric Keyset should fail
    byte[] serializedSymmetricKeyset =
        TestUtil.createKeyset(
                TestUtil.createKey(
                    TestUtil.createHmacKeyData("01234567890123456".getBytes(UTF_8), 16),
                    42,
                    KeyStatusType.ENABLED,
                    OutputPrefixType.TINK))
            .toByteArray();
    assertThrows(
        GeneralSecurityException.class, () -> KeysetHandle.readNoSecret(serializedSymmetricKeyset));
    assertThrows(
        GeneralSecurityException.class,
        () -> TinkProtoKeysetFormat.parseKeysetWithoutSecret(serializedSymmetricKeyset));

    // Private Keyset should fail
    byte[] serializedPrivateKeyset = privateHandle.getKeyset().toByteArray();
    assertThrows(
        GeneralSecurityException.class, () -> KeysetHandle.readNoSecret(serializedPrivateKeyset));
    assertThrows(
        GeneralSecurityException.class,
        () -> TinkProtoKeysetFormat.parseKeysetWithoutSecret(serializedPrivateKeyset));

    // Empty Keyset should fail
    assertThrows(GeneralSecurityException.class, () -> KeysetHandle.readNoSecret(new byte[0]));
    assertThrows(
        GeneralSecurityException.class,
        () -> TinkProtoKeysetFormat.parseKeysetWithoutSecret(new byte[0]));

    // Invalid Keyset should fail
    byte[] proto = new byte[] {0x00, 0x01, 0x02};
    assertThrows(GeneralSecurityException.class, () -> KeysetHandle.readNoSecret(proto));
    assertThrows(
        GeneralSecurityException.class,
        () -> TinkProtoKeysetFormat.parseKeysetWithoutSecret(proto));
  }
Tests that when encryption failed an exception is thrown.
java_src/src/test/java/com/google/crypto/tink/KeysetHandleTest.java