@Test
public void testShouldFailIfIntermediateSigningKeyIsExpiredInECV2() throws Exception {

  PaymentMethodTokenRecipient recipient =
      new PaymentMethodTokenRecipient.Builder()
          .protocolVersion(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2)
          .senderVerifyingKeys(GOOGLE_VERIFYING_PUBLIC_KEYS_JSON)
          .recipientId(RECIPIENT_ID)
          .addRecipientPrivateKey(MERCHANT_PRIVATE_KEY_PKCS8_BASE64)
          .build();
  PaymentMethodTokenSender sender =
      new PaymentMethodTokenSender.Builder()
          .protocolVersion(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2)
          .senderIntermediateSigningKey(
              GOOGLE_SIGNING_EC_V2_INTERMEDIATE_PRIVATE_KEY_PKCS8_BASE64)
          .senderIntermediateCert(
              new SenderIntermediateCertFactory.Builder()
                  .protocolVersion(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2)
                  .addSenderSigningKey(GOOGLE_SIGNING_EC_V2_PRIVATE_KEY_PKCS8_BASE64)
                  .senderIntermediateSigningKey(
                      GOOGLE_SIGNING_EC_V2_INTERMEDIATE_PUBLIC_KEY_X509_BASE64)
                  // Expiration date in the past.
                  .expiration(Instant.now().minus(Duration.standardDays(1)).getMillis())
                  .build()
                  .create())
          .recipientId(RECIPIENT_ID)
          .rawUncompressedRecipientPublicKey(MERCHANT_PUBLIC_KEY_BASE64)
          .build();
  try {
    recipient.unseal(sender.seal(PLAINTEXT));
    fail("Expected GeneralSecurityException");
  } catch (GeneralSecurityException e) {
    assertEquals("expired intermediateSigningKey", e.getMessage());
  }
}