@Test
  public void keysetRotationWithBuilder_works() throws Exception {
    KeysetHandle oldKeyset =
        KeysetHandle.newBuilder()
            .addEntry(
                KeysetHandle.generateEntryFromParametersName("AES256_CMAC_RAW")
                    .withRandomId()
                    .makePrimary())
            .build();

    // Add new key.
    KeysetHandle keysetWithNewKey =
        KeysetHandle.newBuilder(oldKeyset)
            .addEntry(
                KeysetHandle.generateEntryFromParametersName("AES256_CMAC_RAW").withRandomId())
            .build();

    // Make latest key primary.
    KeysetHandle.Builder builder = KeysetHandle.newBuilder(keysetWithNewKey);
    builder.getAt(builder.size() - 1).makePrimary();
    KeysetHandle keysetWithNewPrimary = builder.build();

    assertThat(oldKeyset.size()).isEqualTo(1);

    assertThat(keysetWithNewKey.size()).isEqualTo(2);
    assertThat(keysetWithNewKey.getAt(0).isPrimary()).isTrue();
    assertThat(keysetWithNewKey.getAt(1).isPrimary()).isFalse();

    assertThat(keysetWithNewPrimary.size()).isEqualTo(2);
    assertThat(keysetWithNewPrimary.getAt(0).isPrimary()).isFalse();
    assertThat(keysetWithNewPrimary.getAt(1).isPrimary()).isTrue();
  }
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