@Test
  public void testGetAt_multipleKeys_works() throws Exception {
    Keyset.Key key1 =
        TestUtil.createKey(
            TestUtil.createHmacKeyData("01234567890123456".getBytes(UTF_8), 16),
            42,
            KeyStatusType.DISABLED,
            OutputPrefixType.TINK);
    Keyset.Key key2 =
        TestUtil.createKey(
            TestUtil.createHmacKeyData("abcdefghijklmnopq".getBytes(UTF_8), 32),
            44,
            KeyStatusType.ENABLED,
            OutputPrefixType.CRUNCHY);
    Keyset.Key key3 =
        TestUtil.createKey(
            TestUtil.createHmacKeyData("ABCDEFGHIJKLMNOPQ".getBytes(UTF_8), 32),
            46,
            KeyStatusType.DESTROYED,
            OutputPrefixType.TINK);
    Keyset keyset = TestUtil.createKeyset(key1, key2, key3);
    KeysetHandle handle =
        KeysetHandle.fromKeyset(Keyset.newBuilder(keyset).setPrimaryKeyId(44).build());

    assertThat(handle.size()).isEqualTo(3);
    assertThat(handle.getAt(0).getId()).isEqualTo(42);
    assertThat(handle.getAt(0).getStatus()).isEqualTo(KeyStatus.DISABLED);
    assertThat(handle.getAt(0).isPrimary()).isFalse();

    assertThat(handle.getAt(1).getId()).isEqualTo(44);
    assertThat(handle.getAt(1).getStatus()).isEqualTo(KeyStatus.ENABLED);
    assertThat(handle.getAt(1).isPrimary()).isTrue();

    assertThat(handle.getAt(2).getId()).isEqualTo(46);
    assertThat(handle.getAt(2).getStatus()).isEqualTo(KeyStatus.DESTROYED);
    assertThat(handle.getAt(2).isPrimary()).isFalse();
  }
Tests that when encryption failed an exception is thrown.
java_src/src/test/java/com/google/crypto/tink/KeysetHandleTest.java