Search in sources :

Example 1 with BraintreeCancelListener

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

the class BraintreeFragmentUnitTest method postCancelCallback_postsRequestCodeToListener.

@Test
public void postCancelCallback_postsRequestCodeToListener() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    final AtomicBoolean wasCalled = new AtomicBoolean(false);
    fragment.addListener(new BraintreeCancelListener() {

        @Override
        public void onCancel(int requestCode) {
            assertEquals(42, requestCode);
            wasCalled.set(true);
        }
    });
    fragment.postCancelCallback(42);
    assertTrue(wasCalled.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BraintreeCancelListener(com.braintreepayments.api.interfaces.BraintreeCancelListener) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with BraintreeCancelListener

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

the class BraintreeFragmentUnitTest method onActivityResult_postsCancelCallbackWhenResultCodeIsCanceled.

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

        @Override
        public void onCancel(int requestCode) {
            assertEquals(42, requestCode);
            mCalled.set(true);
        }
    });
    fragment.onActivityResult(42, Activity.RESULT_CANCELED, null);
    assertTrue(mCalled.get());
}
Also used : BraintreeCancelListener(com.braintreepayments.api.interfaces.BraintreeCancelListener) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with BraintreeCancelListener

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

the class BraintreeFragmentUnitTest method addAndRemoveListenersAddAndRemoveAllListeners.

@Test
public void addAndRemoveListenersAddAndRemoveAllListeners() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    ConfigurationListener configurationListener = new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
        }
    };
    BraintreeErrorListener braintreeErrorListener = new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
        }
    };
    PaymentMethodNoncesUpdatedListener paymentMethodNoncesUpdatedListener = new PaymentMethodNoncesUpdatedListener() {

        @Override
        public void onPaymentMethodNoncesUpdated(List<PaymentMethodNonce> paymentMethodNonces) {
        }
    };
    PaymentMethodNonceCreatedListener paymentMethodNonceCreatedListener = new PaymentMethodNonceCreatedListener() {

        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
        }
    };
    BraintreeCancelListener braintreeCancelListener = new BraintreeCancelListener() {

        @Override
        public void onCancel(int requestCode) {
        }
    };
    UnionPayListener unionPayListener = new UnionPayListener() {

        @Override
        public void onCapabilitiesFetched(UnionPayCapabilities capabilities) {
        }

        @Override
        public void onSmsCodeSent(String enrollmentId, boolean smsCodeRequired) {
        }
    };
    AmericanExpressListener americanExpressListener = new AmericanExpressListener() {

        @Override
        public void onRewardsBalanceFetched(AmericanExpressRewardsBalance rewardsBalance) {
        }
    };
    BraintreePaymentResultListener braintreePaymentResultListener = new BraintreePaymentResultListener() {

        @Override
        public void onBraintreePaymentResult(BraintreePaymentResult result) {
        }
    };
    fragment.addListener(configurationListener);
    fragment.addListener(braintreeErrorListener);
    fragment.addListener(paymentMethodNoncesUpdatedListener);
    fragment.addListener(paymentMethodNonceCreatedListener);
    fragment.addListener(braintreeCancelListener);
    fragment.addListener(unionPayListener);
    fragment.addListener(americanExpressListener);
    fragment.addListener(braintreePaymentResultListener);
    assertEquals(8, fragment.getListeners().size());
    fragment.removeListener(configurationListener);
    fragment.removeListener(braintreeErrorListener);
    fragment.removeListener(paymentMethodNoncesUpdatedListener);
    fragment.removeListener(paymentMethodNonceCreatedListener);
    fragment.removeListener(braintreeCancelListener);
    fragment.removeListener(unionPayListener);
    fragment.removeListener(americanExpressListener);
    fragment.removeListener(braintreePaymentResultListener);
    assertEquals(0, fragment.getListeners().size());
}
Also used : PaymentMethodNoncesUpdatedListener(com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener) UnionPayListener(com.braintreepayments.api.interfaces.UnionPayListener) Configuration(com.braintreepayments.api.models.Configuration) BraintreeCancelListener(com.braintreepayments.api.interfaces.BraintreeCancelListener) UnionPayCapabilities(com.braintreepayments.api.models.UnionPayCapabilities) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) JSONException(org.json.JSONException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) BraintreePaymentResult(com.braintreepayments.api.models.BraintreePaymentResult) AmericanExpressRewardsBalance(com.braintreepayments.api.models.AmericanExpressRewardsBalance) List(java.util.List) ArrayList(java.util.ArrayList) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) AmericanExpressListener(com.braintreepayments.api.interfaces.AmericanExpressListener) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) BraintreePaymentResultListener(com.braintreepayments.api.interfaces.BraintreePaymentResultListener) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with BraintreeCancelListener

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

the class ThreeDSecureVerificationTest method performVerification_callsCancelListenerWhenBackIsPressed.

@Test(timeout = 30000)
public void performVerification_callsCancelListenerWhenBackIsPressed() throws InterruptedException {
    CardBuilder cardBuilder = new CardBuilder().cardNumber(THREE_D_SECURE_VERIFICATON).expirationDate("12/30");
    BraintreeFragment fragment = getFragment();
    fragment.addListener(new BraintreeCancelListener() {

        @Override
        public void onCancel(int requestCode) {
            assertEquals(BraintreeRequestCodes.THREE_D_SECURE, requestCode);
            mCountDownLatch.countDown();
        }
    });
    ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);
    waitForView(withId(android.R.id.widget_frame));
    pressBack();
    mCountDownLatch.await();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) BraintreeCancelListener(com.braintreepayments.api.interfaces.BraintreeCancelListener) Test(org.junit.Test)

Example 5 with BraintreeCancelListener

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

the class BraintreeFragmentUnitTest method addListener_flushesCancelCallback.

@Test
public void addListener_flushesCancelCallback() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    fragment.postCancelCallback(42);
    fragment.addListener(new BraintreeCancelListener() {

        @Override
        public void onCancel(int requestCode) {
            assertEquals(42, requestCode);
            mCalled.set(true);
        }
    });
    assertTrue(mCalled.get());
}
Also used : BraintreeCancelListener(com.braintreepayments.api.interfaces.BraintreeCancelListener) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

BraintreeCancelListener (com.braintreepayments.api.interfaces.BraintreeCancelListener)7 Test (org.junit.Test)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 CardBuilder (com.braintreepayments.api.models.CardBuilder)2 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)1 AmericanExpressListener (com.braintreepayments.api.interfaces.AmericanExpressListener)1 BraintreeErrorListener (com.braintreepayments.api.interfaces.BraintreeErrorListener)1 BraintreePaymentResultListener (com.braintreepayments.api.interfaces.BraintreePaymentResultListener)1 ConfigurationListener (com.braintreepayments.api.interfaces.ConfigurationListener)1 PaymentMethodNonceCreatedListener (com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener)1 PaymentMethodNoncesUpdatedListener (com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener)1 UnionPayListener (com.braintreepayments.api.interfaces.UnionPayListener)1 AmericanExpressRewardsBalance (com.braintreepayments.api.models.AmericanExpressRewardsBalance)1 BraintreePaymentResult (com.braintreepayments.api.models.BraintreePaymentResult)1 Configuration (com.braintreepayments.api.models.Configuration)1 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)1 UnionPayCapabilities (com.braintreepayments.api.models.UnionPayCapabilities)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1