@Test
  public void testBuilder_copyKeyset_originalHasNoPrimary_throws() throws Exception {
    KeysetHandle original =
        KeysetHandle.newBuilder()
            .addEntry(
                KeysetHandle.generateEntryFromParametersName("AES256_CMAC")
                    .makePrimary()
                    .withFixedId(778))
            .build();
    Keyset keyset = original.getKeyset();
    Keyset keysetWithoutPrimary = keyset.toBuilder().setPrimaryKeyId(3843).build();

    KeysetHandle.Builder builder =
        KeysetHandle.newBuilder(KeysetHandle.fromKeyset(keysetWithoutPrimary));
    GeneralSecurityException thrown = assertThrows(GeneralSecurityException.class, builder::build);
    assertThat(thrown).hasMessageThat().contains("No primary was set");
  }
Tests that key parsing via the serialization registry works as expected.

<p>NOTE: This adds a parser to the MutableSerializationRegistry, which no other test uses.
java_src/src/test/java/com/google/crypto/tink/KeysetHandleTest.java