@Test(timeout = 5000) public void onActivityResult_doesNothingWhenResultCodeNotOk() { Intent intent = mock(Intent.class); ThreeDSecure.onActivityResult(mock(BraintreeFragment.class), Activity.RESULT_CANCELED, intent); verifyZeroInteractions(intent); } }
@Test(timeout = 1000) public void onActivityResult_postsPaymentMethodNonceToListener_fromUri() throws InterruptedException { BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, new TestClientTokenBuilder().withThreeDSecure().build()); fragment.addListener(new PaymentMethodNonceCreatedListener() { @Override public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) { assertIsANonce(paymentMethodNonce.getNonce()); assertEquals("11", ((CardNonce) paymentMethodNonce).getLastTwo()); assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified()); mCountDownLatch.countDown(); } }); Uri responseUri = Uri.parse("http://demo-app.com") .buildUpon() .appendQueryParameter("auth_response", stringFromFixture("three_d_secure/authentication_response.json")) .build(); Intent data = new Intent() .setData(responseUri); ThreeDSecure.onActivityResult(fragment, Activity.RESULT_OK, data); mCountDownLatch.await(); }
@Test public void onActivityResult_handlesThreeDSecureResult() throws InvalidArgumentException { BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY); mockStatic(ThreeDSecure.class); Intent intent = new Intent(); fragment.onActivityResult(BraintreeRequestCodes.THREE_D_SECURE, Activity.RESULT_OK, intent); verifyStatic(); ThreeDSecure.onActivityResult(fragment, Activity.RESULT_OK, intent); }
@Test(timeout = 2000) public void onActivityResult_postsPaymentMethodNonceToListener() throws JSONException, InterruptedException { BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, new TestClientTokenBuilder().withThreeDSecure().build()); fragment.addListener(new PaymentMethodNonceCreatedListener() { @Override public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) { assertIsANonce(paymentMethodNonce.getNonce()); assertEquals("11", ((CardNonce) paymentMethodNonce).getLastTwo()); assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified()); mCountDownLatch.countDown(); } }); JSONObject authResponse = new JSONObject( stringFromFixture("three_d_secure/authentication_response.json")); Intent data = new Intent() .putExtra(ThreeDSecureWebViewActivity.EXTRA_THREE_D_SECURE_RESULT, ThreeDSecureAuthenticationResponse.fromJson(authResponse.toString())); ThreeDSecure.onActivityResult(fragment, Activity.RESULT_OK, data); mCountDownLatch.await(); }
@Test(timeout = 2000) public void onActivityResult_postsUnrecoverableErrorsToListeners() throws InterruptedException { BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, new TestClientTokenBuilder().withThreeDSecure().build()); fragment.addListener(new BraintreeErrorListener() { @Override public void onError(Exception error) { assertEquals("Error!", error.getMessage()); mCountDownLatch.countDown(); } }); ThreeDSecureAuthenticationResponse authResponse = ThreeDSecureAuthenticationResponse.fromException("Error!"); Intent data = new Intent() .putExtra(ThreeDSecureWebViewActivity.EXTRA_THREE_D_SECURE_RESULT, authResponse); ThreeDSecure.onActivityResult(fragment, Activity.RESULT_OK, data); mCountDownLatch.await(); }
@Test(timeout = 2000) public void onActivityResult_postsRecoverableErrorsToListener() throws InterruptedException { BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, new TestClientTokenBuilder().withThreeDSecure().build()); fragment.addListener(new BraintreeErrorListener() { @Override public void onError(Exception error) { assertEquals("Failed to authenticate, please try a different form of payment", error.getMessage()); mCountDownLatch.countDown(); } }); Intent data = new Intent() .putExtra(ThreeDSecureWebViewActivity.EXTRA_THREE_D_SECURE_RESULT, ThreeDSecureAuthenticationResponse.fromJson( stringFromFixture("errors/three_d_secure_error.json"))); ThreeDSecure.onActivityResult(fragment, Activity.RESULT_OK, data); mCountDownLatch.await(); }
break; case BraintreeRequestCodes.THREE_D_SECURE: ThreeDSecure.onActivityResult(this, resultCode, data); break; case BraintreeRequestCodes.VENMO: