Search in sources :

Example 16 with BraintreeErrorListener

use of com.braintreepayments.api.interfaces.BraintreeErrorListener in project braintree_android by braintree.

the class BraintreeFragmentUnitTest method removeListener_noErrorCallbacksReceived.

@Test
public void removeListener_noErrorCallbacksReceived() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    BraintreeErrorListener listener = new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            fail("Listener was called");
        }
    };
    fragment.addListener(listener);
    fragment.removeListener(listener);
    fragment.postCallback(new Exception());
    fragment.postCallback(new ErrorWithResponse(400, ""));
}
Also used : ErrorWithResponse(com.braintreepayments.api.exceptions.ErrorWithResponse) 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)

Example 17 with BraintreeErrorListener

use of com.braintreepayments.api.interfaces.BraintreeErrorListener in project braintree_android by braintree.

the class BraintreeFragmentUnitTest method postCallback_exceptionIsPostedToListeners.

@Test
public void postCallback_exceptionIsPostedToListeners() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    fragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            assertEquals("Error!", error.getMessage());
            mCalled.set(true);
        }
    });
    fragment.postCallback(new Exception("Error!"));
    assertTrue(mCalled.get());
}
Also used : 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)

Example 18 with BraintreeErrorListener

use of com.braintreepayments.api.interfaces.BraintreeErrorListener in project braintree_android by braintree.

the class BraintreeFragmentUnitTest method postCallback_ErrorWithResponseIsPostedToListeners.

@Test
public void postCallback_ErrorWithResponseIsPostedToListeners() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    fragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            assertTrue(error instanceof ErrorWithResponse);
            assertEquals(422, ((ErrorWithResponse) error).getStatusCode());
            mCalled.set(true);
        }
    });
    fragment.postCallback(new ErrorWithResponse(422, ""));
    assertTrue(mCalled.get());
}
Also used : ErrorWithResponse(com.braintreepayments.api.exceptions.ErrorWithResponse) 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)

Example 19 with BraintreeErrorListener

use of com.braintreepayments.api.interfaces.BraintreeErrorListener in project braintree_android by braintree.

the class BraintreeFragmentUnitTest method postsAnErrorWhenFetchingConfigurationFails.

@Test
public void postsAnErrorWhenFetchingConfigurationFails() throws InvalidArgumentException {
    mockConfigurationManager(new Exception("Configuration error"));
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    final AtomicInteger calls = new AtomicInteger(0);
    fragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            assertEquals("Request for configuration has failed: Configuration error. Future requests will retry up to 3 times", error.getMessage());
            calls.getAndIncrement();
        }
    });
    fragment.setConfigurationErrorListener(new BraintreeResponseListener<Exception>() {

        @Override
        public void onResponse(Exception error) {
            assertEquals("Request for configuration has failed: Configuration error. Future requests will retry up to 3 times", error.getMessage());
            calls.getAndIncrement();
        }
    });
    assertEquals(2, calls.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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 20 with BraintreeErrorListener

use of com.braintreepayments.api.interfaces.BraintreeErrorListener in project braintree_android by braintree.

the class CardTest method tokenize_callsErrorCallbackForInvalidPostalCode.

@Test(timeout = 10000)
public void tokenize_callsErrorCallbackForInvalidPostalCode() throws Exception {
    CardBuilder cardBuilder = new CardBuilder().cardNumber(VISA).expirationDate("08/20").postalCode("20000");
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    BraintreeFragment fragment = setupBraintreeFragment(new TestClientTokenBuilder().withPostalCodeVerification().build());
    fragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            assertEquals("Postal code verification failed", ((ErrorWithResponse) error).errorFor("creditCard").errorFor("billingAddress").getFieldErrors().get(0).getMessage());
            countDownLatch.countDown();
        }
    });
    Card.tokenize(fragment, cardBuilder);
    countDownLatch.await();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) ErrorWithResponse(com.braintreepayments.api.exceptions.ErrorWithResponse) CountDownLatch(java.util.concurrent.CountDownLatch) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) JSONException(org.json.JSONException) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) Test(org.junit.Test)

Aggregations

BraintreeErrorListener (com.braintreepayments.api.interfaces.BraintreeErrorListener)27 Test (org.junit.Test)27 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)24 JSONException (org.json.JSONException)15 AuthorizationException (com.braintreepayments.api.exceptions.AuthorizationException)10 CardBuilder (com.braintreepayments.api.models.CardBuilder)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 CountDownLatch (java.util.concurrent.CountDownLatch)6 ErrorWithResponse (com.braintreepayments.api.exceptions.ErrorWithResponse)5 TestClientTokenBuilder (com.braintreepayments.api.test.TestClientTokenBuilder)5 Intent (android.content.Intent)4 BraintreePaymentResultListener (com.braintreepayments.api.interfaces.BraintreePaymentResultListener)3 PaymentMethodNoncesUpdatedListener (com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener)3 UnionPayListener (com.braintreepayments.api.interfaces.UnionPayListener)3 BraintreePaymentResult (com.braintreepayments.api.models.BraintreePaymentResult)3 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)3 UnionPayCapabilities (com.braintreepayments.api.models.UnionPayCapabilities)3 IdealRequest (com.braintreepayments.api.models.IdealRequest)2 UnionPayCardBuilder (com.braintreepayments.api.models.UnionPayCardBuilder)2 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)2