@Theory
  public void createSignVerify(@FromDataPoints("templates") String templateName)
      throws Exception {
    if (TestUtil.isTsan()) {
      // KeysetHandle.generateNew is too slow in Tsan.
      return;
    }
    KeysetHandle privateHandle = KeysetHandle.generateNew(KeyTemplates.get(templateName));
    KeysetHandle publicHandle = privateHandle.getPublicKeysetHandle();

    PublicKeySign signer = privateHandle.getPrimitive(PublicKeySign.class);
    PublicKeyVerify verifier = publicHandle.getPrimitive(PublicKeyVerify.class);

    byte[] data = "data".getBytes(UTF_8);
    byte[] sig = signer.sign(data);
    verifier.verify(sig, data);

    KeysetHandle otherPrivateHandle = KeysetHandle.generateNew(KeyTemplates.get(templateName));
    PublicKeyVerify otherVerifier =
        otherPrivateHandle.getPublicKeysetHandle().getPrimitive(PublicKeyVerify.class);
    assertThrows(
        GeneralSecurityException.class, () -> otherVerifier.verify(sig, data));

    byte[] invalid = "invalid".getBytes(UTF_8);
    byte[] empty = "".getBytes(UTF_8);
    assertThrows(GeneralSecurityException.class, () -> verifier.verify(sig, invalid));
    assertThrows(GeneralSecurityException.class, () -> verifier.verify(invalid, data));
    assertThrows(GeneralSecurityException.class, () -> verifier.verify(empty, data));
    verifier.verify(signer.sign(empty), empty);
  }
Unit tests for the Signature package. Uses only the public API.
java_src/src/test/java/com/google/crypto/tink/signature/SignatureTest.java