Search in sources :

Example 1 with AmericanExpressRewardsBalance

use of com.braintreepayments.api.models.AmericanExpressRewardsBalance 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 2 with AmericanExpressRewardsBalance

use of com.braintreepayments.api.models.AmericanExpressRewardsBalance in project braintree_android by braintree.

the class AmericanExpressUnitTest method getRewardsBalance_callsListenerWithRewardsBalanceOnIneligibleCard.

@Test
public void getRewardsBalance_callsListenerWithRewardsBalanceOnIneligibleCard() throws JSONException {
    BraintreeFragment fragment = new MockFragmentBuilder().configuration(mConfiguration).successResponse(stringFromFixture("response/amex_rewards_balance_ineligible_card.json")).build();
    AmericanExpress.getRewardsBalance(fragment, "fake-nonce", "USD");
    ArgumentCaptor<AmericanExpressRewardsBalance> argumentCaptor = ArgumentCaptor.forClass(AmericanExpressRewardsBalance.class);
    verify(fragment).postAmericanExpressCallback(argumentCaptor.capture());
    AmericanExpressRewardsBalance rewardsBalance = argumentCaptor.getValue();
    assertNotNull(rewardsBalance);
    assertNull(rewardsBalance.getConversionRate());
    assertNull(rewardsBalance.getCurrencyAmount());
    assertNull(rewardsBalance.getCurrencyIsoCode());
    assertNull(rewardsBalance.getRequestId());
    assertNull(rewardsBalance.getRewardsAmount());
    assertNull(rewardsBalance.getRewardsUnit());
    assertEquals("INQ2002", rewardsBalance.getErrorCode());
    assertEquals("Card is ineligible", rewardsBalance.getErrorMessage());
}
Also used : AmericanExpressRewardsBalance(com.braintreepayments.api.models.AmericanExpressRewardsBalance) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with AmericanExpressRewardsBalance

use of com.braintreepayments.api.models.AmericanExpressRewardsBalance in project braintree_android by braintree.

the class AmericanExpressUnitTest method getRewardsBalance_callsListenerWithRewardsBalanceOnInsufficientPoints.

@Test
public void getRewardsBalance_callsListenerWithRewardsBalanceOnInsufficientPoints() throws JSONException {
    BraintreeFragment fragment = new MockFragmentBuilder().configuration(mConfiguration).successResponse(stringFromFixture("response/amex_rewards_balance_insufficient_points.json")).build();
    AmericanExpress.getRewardsBalance(fragment, "fake-nonce", "USD");
    ArgumentCaptor<AmericanExpressRewardsBalance> argumentCaptor = ArgumentCaptor.forClass(AmericanExpressRewardsBalance.class);
    verify(fragment).postAmericanExpressCallback(argumentCaptor.capture());
    AmericanExpressRewardsBalance rewardsBalance = argumentCaptor.getValue();
    assertNotNull(rewardsBalance);
    assertNull(rewardsBalance.getConversionRate());
    assertNull(rewardsBalance.getCurrencyAmount());
    assertNull(rewardsBalance.getCurrencyIsoCode());
    assertNull(rewardsBalance.getRequestId());
    assertNull(rewardsBalance.getRewardsAmount());
    assertNull(rewardsBalance.getRewardsUnit());
    assertEquals("INQ2003", rewardsBalance.getErrorCode());
    assertEquals("Insufficient points on card", rewardsBalance.getErrorMessage());
}
Also used : AmericanExpressRewardsBalance(com.braintreepayments.api.models.AmericanExpressRewardsBalance) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with AmericanExpressRewardsBalance

use of com.braintreepayments.api.models.AmericanExpressRewardsBalance in project braintree_android by braintree.

the class AmericanExpressUnitTest method getRewardsBalance_callsListenerWithRewardsBalanceOnSuccess.

@Test
public void getRewardsBalance_callsListenerWithRewardsBalanceOnSuccess() throws JSONException {
    BraintreeFragment fragment = new MockFragmentBuilder().configuration(mConfiguration).successResponse(stringFromFixture("response/amex_rewards_balance_success.json")).build();
    AmericanExpress.getRewardsBalance(fragment, "fake-nonce", "USD");
    ArgumentCaptor<AmericanExpressRewardsBalance> argumentCaptor = ArgumentCaptor.forClass(AmericanExpressRewardsBalance.class);
    verify(fragment).postAmericanExpressCallback(argumentCaptor.capture());
    AmericanExpressRewardsBalance rewardsBalance = argumentCaptor.getValue();
    assertNotNull(rewardsBalance);
    assertEquals("0.0070", rewardsBalance.getConversionRate());
    assertEquals("316795.03", rewardsBalance.getCurrencyAmount());
    assertEquals("USD", rewardsBalance.getCurrencyIsoCode());
    assertEquals("715f4712-8690-49ed-8cc5-d7fb1c2d", rewardsBalance.getRequestId());
    assertEquals("45256433", rewardsBalance.getRewardsAmount());
    assertEquals("Points", rewardsBalance.getRewardsUnit());
    assertNull(rewardsBalance.getErrorCode());
    assertNull(rewardsBalance.getErrorMessage());
}
Also used : AmericanExpressRewardsBalance(com.braintreepayments.api.models.AmericanExpressRewardsBalance) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

AmericanExpressRewardsBalance (com.braintreepayments.api.models.AmericanExpressRewardsBalance)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)1 AmericanExpressListener (com.braintreepayments.api.interfaces.AmericanExpressListener)1 BraintreeCancelListener (com.braintreepayments.api.interfaces.BraintreeCancelListener)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 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 JSONException (org.json.JSONException)1