@Test
  public void testGetAt_indexOutOfBounds_throws() throws Exception {
    Keyset.Key key1 =
        TestUtil.createKey(
            TestUtil.createHmacKeyData("01234567890123456".getBytes(UTF_8), 16),
            42,
            KeyStatusType.ENABLED,
            OutputPrefixType.TINK);
    KeysetHandle handle = KeysetHandle.fromKeyset(TestUtil.createKeyset(key1));

    assertThrows(IndexOutOfBoundsException.class, () -> handle.getAt(-1));
    assertThrows(IndexOutOfBoundsException.class, () -> handle.getAt(1));
  }
Tests that when encryption failed an exception is thrown.
java_src/src/test/java/com/google/crypto/tink/KeysetHandleTest.java