@SuppressWarnings("deprecation")  // This is a test for the deprecated function
  @Test
  public void deprecated_primaryKey_shouldWork() throws Exception {
    KeysetHandle handle =
        KeysetHandle.newBuilder()
        .addEntry(
            KeysetHandle.generateEntryFromParametersName("AES128_EAX").withFixedId(123))
        .addEntry(
            KeysetHandle.generateEntryFromParametersName("HMAC_SHA256_256BITTAG")
                .withFixedId(234).makePrimary())
        .build();

    KeyHandle keyHandle = handle.primaryKey();
    assertThat(keyHandle.getId()).isEqualTo(234);
  }
Tests that when encryption failed an exception is thrown.
java_src/src/test/java/com/google/crypto/tink/KeysetHandleTest.java