@Test
  public void testGetAt_singleKeyWithRegisteredProtoSerialization_works() throws Exception {
    // HmacKey's proto serialization HmacProtoSerialization is registed in HmacKeyManager.
    Keyset keyset =
        TestUtil.createKeyset(
            TestUtil.createKey(
                TestUtil.createHmacKeyData("01234567890123456".getBytes(UTF_8), 16),
                42,
                KeyStatusType.ENABLED,
                OutputPrefixType.TINK));
    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(HmacKey.class);
  }
Tests that when encryption failed an exception is thrown.
java_src/src/test/java/com/google/crypto/tink/KeysetHandleTest.java