@Test
  // Tests that withRandomId avoids collisions. We use 2^16 keys to make collision likely. The test
  // is about 4 seconds like this.
  public void testBuilder_withRandomId_doesNotHaveCollisions() throws Exception {
    // Test takes longer on Android; and a simple Java test suffices.
    assumeFalse(TestUtil.isAndroid());
    int numNonPrimaryKeys = 1 << 16;
    KeysetHandle.Builder builder = KeysetHandle.newBuilder();
    builder.addEntry(
        KeysetHandle.generateEntryFromParametersName("AES256_CMAC").withRandomId().makePrimary());
    for (int i = 0; i < numNonPrimaryKeys; i++) {
      builder.addEntry(KeysetHandle.generateEntryFromParametersName("AES256_CMAC").withRandomId());
    }
    KeysetHandle handle = builder.build();
    Set<Integer> idSet = new HashSet<>();
    for (int i = 0; i < handle.size(); ++i) {
      idSet.add(handle.getAt(i).getId());
    }
    assertThat(idSet).hasSize(numNonPrimaryKeys + 1);
  }
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