Search in sources :

Example 1 with InvalidArgumentException

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());
}
Also used : Configuration(com.braintreepayments.api.models.Configuration) TestIdealConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestIdealConfigurationBuilder) IdealBank(com.braintreepayments.api.models.IdealBank) List(java.util.List) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) JSONException(org.json.JSONException) IOException(java.io.IOException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with InvalidArgumentException

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));
}
Also used : Answer(org.mockito.stubbing.Answer) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IdealRequest(com.braintreepayments.api.models.IdealRequest) IdealBank(com.braintreepayments.api.models.IdealBank) JSONObject(org.json.JSONObject) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) JSONException(org.json.JSONException) IOException(java.io.IOException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with InvalidArgumentException

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());
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) Configuration(com.braintreepayments.api.models.Configuration) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) Intent(android.content.Intent) AppSwitchNotAvailableException(com.braintreepayments.api.exceptions.AppSwitchNotAvailableException) JSONException(org.json.JSONException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with InvalidArgumentException

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());
}
Also used : JSONException(org.json.JSONException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with InvalidArgumentException

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());
}
Also used : Intent(android.content.Intent) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) JSONException(org.json.JSONException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)31 Test (org.junit.Test)27 JSONException (org.json.JSONException)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 AuthorizationException (com.braintreepayments.api.exceptions.AuthorizationException)12 BraintreeErrorListener (com.braintreepayments.api.interfaces.BraintreeErrorListener)12 IOException (java.io.IOException)12 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)10 Configuration (com.braintreepayments.api.models.Configuration)7 MalformedURLException (java.net.MalformedURLException)6 Intent (android.content.Intent)4 UnexpectedException (com.braintreepayments.api.exceptions.UnexpectedException)4 Authorization (com.braintreepayments.api.models.Authorization)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 ErrorWithResponse (com.braintreepayments.api.exceptions.ErrorWithResponse)3 ConfigurationListener (com.braintreepayments.api.interfaces.ConfigurationListener)3 PaymentMethodNoncesUpdatedListener (com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener)3 IdealBank (com.braintreepayments.api.models.IdealBank)3 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)3 List (java.util.List)3