@Test public void getPaymentMethodNonces_throwsAnError() { BraintreeFragment fragment = new MockFragmentBuilder() .errorResponse(new UnexpectedException("Error")) .build(); PaymentMethod.getPaymentMethodNonces(fragment); ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(Exception.class); verify(fragment).postCallback(captor.capture()); assertTrue(captor.getValue() instanceof UnexpectedException); }
@Test public void fetchCapabilities_callsListenerWithErrorOnFailure() { RuntimeException expected = new RuntimeException("expected runtime exception"); BraintreeFragment fragment = new MockFragmentBuilder() .configuration(mConfigurationWithUnionPay) .errorResponse(expected) .build(); UnionPay.fetchCapabilities(fragment, UNIONPAY_CREDIT); verify(fragment).postCallback(expected); }
@Test public void fetchCapabilities_sendsAnalyticsEventOnFailure() { BraintreeFragment fragment = new MockFragmentBuilder() .configuration(mConfigurationWithUnionPay) .errorResponse(new RuntimeException("expected runtime exception")) .build(); UnionPay.fetchCapabilities(fragment, UNIONPAY_CREDIT); verify(fragment).sendAnalyticsEvent("union-pay.capabilities-failed"); }
@Test public void getRewardsBalance_sendsAnalyticsEventOnFailure() { BraintreeFragment fragment = new MockFragmentBuilder() .configuration(mConfiguration) .errorResponse(new AuthorizationException("Bad fingerprint")) .build(); AmericanExpress.getRewardsBalance(fragment, "fake-nonce", "USD"); verify(fragment).sendAnalyticsEvent("amex.rewards-balance.start"); verify(fragment).sendAnalyticsEvent("amex.rewards-balance.error"); }
@Test public void getPaymentMethodNonces_sendsAnAnalyticsEventForErrors() { BraintreeFragment fragment = new MockFragmentBuilder() .errorResponse(new UnexpectedException("Error")) .build(); PaymentMethod.getPaymentMethodNonces(fragment); verify(fragment).sendAnalyticsEvent("get-payment-methods.failed"); }
@Test public void onActivityResult_withFailedVaultCall_postsCallbackToErrorListener() throws InvalidArgumentException { Configuration configuration = getConfigurationFromFixture(); Authorization clientToken = Authorization.fromString(stringFromFixture("base_64_client_token.txt")); disableSignatureVerification(); BraintreeFragment fragment = new MockFragmentBuilder() .context(VenmoInstalledContextFactory.venmoInstalledContext(true, RuntimeEnvironment.application)) .configuration(configuration) .authorization(clientToken) .sessionId("session-id") .errorResponse(new AuthorizationException("Bad fingerprint")) .build(); ArgumentCaptor<Exception> responseCaptor = ArgumentCaptor.forClass(Exception.class); Venmo.authorizeAccount(fragment, true); Intent responseIntent = new Intent() .putExtra(Venmo.EXTRA_PAYMENT_METHOD_NONCE, "nonce"); Venmo.onActivityResult(fragment, Activity.RESULT_OK, responseIntent); verify(fragment).postCallback(responseCaptor.capture()); Exception exception = responseCaptor.getValue(); assertTrue(exception instanceof AuthorizationException); assertEquals("Bad fingerprint", exception.getMessage()); }
@Test public void enroll_sendsAnalyticsEventOnFailure() throws JSONException { UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder() .cardNumber("some-card-number"); BraintreeFragment braintreeFragment = new MockFragmentBuilder() .configuration(mConfigurationWithUnionPay) .errorResponse(new BraintreeException()) .build(); UnionPay.enroll(braintreeFragment, unionPayCardBuilder); verify(braintreeFragment).sendAnalyticsEvent("union-pay.enrollment-failed"); }
@Test public void onActivityResult_withFailedVaultCall_sendsAnalyticsEvent() throws InvalidArgumentException { Configuration configuration = getConfigurationFromFixture(); Authorization clientToken = Authorization.fromString(stringFromFixture("base_64_client_token.txt")); disableSignatureVerification(); BraintreeFragment fragment = new MockFragmentBuilder() .context(VenmoInstalledContextFactory.venmoInstalledContext(true, RuntimeEnvironment.application)) .configuration(configuration) .authorization(clientToken) .sessionId("session-id") .errorResponse(new AuthorizationException("Bad fingerprint")) .build(); Venmo.authorizeAccount(fragment, true); Intent responseIntent = new Intent() .putExtra(Venmo.EXTRA_PAYMENT_METHOD_NONCE, "nonce"); Venmo.onActivityResult(fragment, Activity.RESULT_OK, responseIntent); verify(fragment).sendAnalyticsEvent(endsWith("pay-with-venmo.vault.failed")); }