@Test
  public void testGetAt_singleKeyWithoutRegisteredProtoSerialization_wrapsToLegacyProtoKey()
      throws Exception {
    HmacPrfKey key =
        HmacPrfKey.newBuilder()
            .setParams(HmacPrfParams.newBuilder().setHash(HashType.SHA256).build())
            .setKeyValue(ByteString.copyFromUtf8("01234567890123456"))
            .build();
    Keyset keyset =
        TestUtil.createKeyset(
            TestUtil.createKey(
                TestUtil.createKeyData(
                    key, "i.am.an.unregistered.key.type", KeyData.KeyMaterialType.SYMMETRIC),
                42,
                KeyStatusType.ENABLED,
                OutputPrefixType.RAW));
    KeysetHandle handle = KeysetHandle.fromKeyset(keyset);
    assertThat(handle.size()).isEqualTo(1);
    KeysetHandle.Entry entry = handle.getAt(0);
    assertThat(entry.getId()).isEqualTo(42);
    assertThat(entry.getStatus()).isEqualTo(KeyStatus.ENABLED);
    assertThat(entry.isPrimary()).isTrue();
    assertThat(entry.getKey().getClass()).isEqualTo(LegacyProtoKey.class);
  }
Tests that when encryption failed an exception is thrown.
java_src/src/test/java/com/google/crypto/tink/KeysetHandleTest.java