@Test
public void testShouldFailIfMessageIsExpired() throws Exception {

  PaymentMethodTokenSender sender =
      new PaymentMethodTokenSender.Builder()
          .senderSigningKey(GOOGLE_SIGNING_EC_V1_PRIVATE_KEY_PKCS8_BASE64)
          .recipientId(RECIPIENT_ID)
          .rawUncompressedRecipientPublicKey(MERCHANT_PUBLIC_KEY_BASE64)
          .build();
  PaymentMethodTokenRecipient recipient =
      new PaymentMethodTokenRecipient.Builder()
          .senderVerifyingKeys(GOOGLE_VERIFYING_PUBLIC_KEYS_JSON)
          .recipientId(RECIPIENT_ID)
          .addRecipientPrivateKey(MERCHANT_PRIVATE_KEY_PKCS8_BASE64)
          .build();
  String ciphertext =
      sender.seal(
          new JSONObject()
              .put(
                  "messageExpiration",
                  // One day in the past
                  String.valueOf(Instant.now().minus(Duration.standardDays(1)).getMillis()))
              .toString());
  try {
    recipient.unseal(ciphertext);
    fail("Expected GeneralSecurityException");
  } catch (GeneralSecurityException e) {
    assertEquals("expired payload", e.getMessage());
  }
}