@Test
public void shouldProduceSenderIntermediateCertJson() throws Exception {

  String encoded =
      new SenderIntermediateCertFactory.Builder()
          .protocolVersion(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2)
          .senderIntermediateSigningKey(GOOGLE_SIGNING_EC_V2_INTERMEDIATE_PUBLIC_KEY_X509_BASE64)
          .addSenderSigningKey(GOOGLE_SIGNING_EC_V2_PRIVATE_KEY_PKCS8_BASE64)
          .expiration(123456)
          .build()
          .create();
  JSONObject decodedSignedIntermediateSigningKey = new JSONObject(encoded);
  assertTrue(decodedSignedIntermediateSigningKey.get("signedKey") instanceof String);
  assertTrue(decodedSignedIntermediateSigningKey.get("signatures") instanceof JSONArray);
  assertEquals(2, decodedSignedIntermediateSigningKey.length());
  JSONObject signedKey =
      new JSONObject(decodedSignedIntermediateSigningKey.getString("signedKey"));
  assertTrue(signedKey.get("keyValue") instanceof String);
  assertTrue(signedKey.get("keyExpiration") instanceof String);
  assertEquals(2, signedKey.length());
  assertEquals(
      GOOGLE_SIGNING_EC_V2_INTERMEDIATE_PUBLIC_KEY_X509_BASE64, signedKey.getString("keyValue"));
  assertEquals("123456", signedKey.getString("keyExpiration"));
  assertEquals(1, decodedSignedIntermediateSigningKey.getJSONArray("signatures").length());
  assertNotEquals(
      0, decodedSignedIntermediateSigningKey.getJSONArray("signatures").getString(0).length());
}