@Test
  public void createPublicKey_failsWithMismatchedIdRequirement() throws Exception {
    HpkeParameters.Builder paramsBuilder =
        HpkeParameters.builder()
            .setKemId(HpkeParameters.KemId.DHKEM_X25519_HKDF_SHA256)
            .setKdfId(HpkeParameters.KdfId.HKDF_SHA256)
            .setAeadId(HpkeParameters.AeadId.AES_128_GCM);
    Bytes publicKeyBytes = Bytes.copyFrom(X25519.publicFromPrivate(X25519.generatePrivateKey()));

    HpkeParameters noPrefixParams =
        paramsBuilder.setVariant(HpkeParameters.Variant.NO_PREFIX).build();
    assertThrows(
        GeneralSecurityException.class,
        () -> HpkePublicKey.create(noPrefixParams, publicKeyBytes, /* idRequirement= */ 123));

    HpkeParameters tinkParams = paramsBuilder.setVariant(HpkeParameters.Variant.TINK).build();
    assertThrows(
        GeneralSecurityException.class,
        () -> HpkePublicKey.create(tinkParams, publicKeyBytes, /* idRequirement= */ null));

    HpkeParameters crunchyParams = paramsBuilder.setVariant(HpkeParameters.Variant.CRUNCHY).build();
    assertThrows(
        GeneralSecurityException.class,
        () -> HpkePublicKey.create(crunchyParams, publicKeyBytes, /* idRequirement= */ null));
  }
Copied from {@link EllipticCurves#pointEncode} to bypass point validation.
java_src/src/test/java/com/google/crypto/tink/hybrid/HpkePublicKeyTest.java