use of com.braintreepayments.api.exceptions.InvalidArgumentException in project braintree_android by braintree.
the class IdealUnitTest method fetchIssuingBanks_postsConfigurationExceptionWhenBraintreeApiNotEnabled.
@Test
public void fetchIssuingBanks_postsConfigurationExceptionWhenBraintreeApiNotEnabled() throws InvalidArgumentException, InterruptedException {
Configuration configuration = new TestConfigurationBuilder().ideal(new TestIdealConfigurationBuilder().routeId("some-route-id")).buildConfiguration();
BraintreeFragment fragment = getMockFragment(stringFromFixture("client_token.json"), configuration);
Ideal.fetchIssuingBanks(fragment, new BraintreeResponseListener<List<IdealBank>>() {
@Override
public void onResponse(List<IdealBank> idealBanks) {
fail("Success listener called");
}
});
ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(Exception.class);
verify(fragment).postCallback(captor.capture());
Exception e = captor.getValue();
assertEquals("Your access is restricted and cannot use this part of the Braintree API.", e.getMessage());
}
use of com.braintreepayments.api.exceptions.InvalidArgumentException in project braintree_android by braintree.
the class IdealUnitTest method startPayment_callsExceptionListenerOnHttpError.
@Test
public void startPayment_callsExceptionListenerOnHttpError() throws InvalidArgumentException, JSONException {
final Exception expectedException = new Exception();
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[2];
callback.failure(expectedException);
return null;
}
}).when(mMockApiClient).post(eq("/ideal-payments"), any(String.class), any(HttpResponseCallback.class));
List<IdealBank> banks = IdealBank.fromJson(mConfiguration, stringFromFixture("payment_methods/ideal_issuing_banks.json"));
IdealRequest builder = new IdealRequest().issuerId(banks.get(0).getId()).amount("1.00").currency("EUR").orderId("abc-123");
Ideal.startPayment(mBraintreeFragment, builder, null);
verify(mBraintreeFragment).postCallback(eq(expectedException));
}
use of com.braintreepayments.api.exceptions.InvalidArgumentException in project braintree_android by braintree.
the class VenmoUnitTest method onActivityResult_withFailedVaultCall_postsCallbackToErrorListener.
@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());
}
use of com.braintreepayments.api.exceptions.InvalidArgumentException in project braintree_android by braintree.
the class BraintreeFragmentUnitTest method addListener_flushesExceptionCallbacks.
@Test
public void addListener_flushesExceptionCallbacks() throws InvalidArgumentException {
BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
fragment.postCallback(new Exception("Error!"));
fragment.addListener(new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
assertEquals("Error!", error.getMessage());
mCalled.set(true);
}
});
assertTrue(mCalled.get());
}
use of com.braintreepayments.api.exceptions.InvalidArgumentException in project braintree_android by braintree.
the class BraintreeFragmentUnitTest method startActivityForResult_doesNotPostExceptionWhenAttached.
@Test
public void startActivityForResult_doesNotPostExceptionWhenAttached() throws InvalidArgumentException {
BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
fragment.addListener(new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
fail("onError was called");
}
});
fragment.startActivityForResult(new Intent(), 1);
assertFalse(mCalled.get());
}
Aggregations