Search in sources :

Example 21 with TestConfigurationBuilder

use of com.braintreepayments.testutils.TestConfigurationBuilder in project braintree_android by braintree.

the class PayPalTest method authorizeAccount_onBackPressed_callsCancelListenerOnlyOnce.

@Test
public void authorizeAccount_onBackPressed_callsCancelListenerOnlyOnce() {
    String configuration = new TestConfigurationBuilder().paypalEnabled(true).build();
    final BraintreeFragment fragment = getMockFragmentWithConfiguration(mActivityTestRule.getActivity(), configuration);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            fragment.onActivityResult(BraintreeRequestCodes.PAYPAL, Activity.RESULT_CANCELED, new Intent());
            return null;
        }
    }).when(fragment).browserSwitch(eq(BraintreeRequestCodes.PAYPAL), any(Intent.class));
    PayPal.authorizeAccount(fragment);
    verify(fragment, times(1)).postCancelCallback(BraintreeRequestCodes.PAYPAL);
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Intent(android.content.Intent) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) Test(org.junit.Test)

Example 22 with TestConfigurationBuilder

use of com.braintreepayments.testutils.TestConfigurationBuilder in project braintree_android by braintree.

the class IdealUnitTest method startPayment_failure_sendsAnalyticsEvent.

@Test
public void startPayment_failure_sendsAnalyticsEvent() throws JSONException, InvalidArgumentException {
    mConfiguration = new TestConfigurationBuilder().assetsUrl("http://assets.example.com").buildConfiguration();
    mBraintreeFragment = new MockFragmentBuilder().authorization(Authorization.fromString(stringFromFixture("client_token.json"))).configuration(mConfiguration).build();
    Ideal.startPayment(mBraintreeFragment, new IdealRequest(), null);
    verify(mBraintreeFragment).sendAnalyticsEvent(eq("ideal.start-payment.selected"));
    verify(mBraintreeFragment).sendAnalyticsEvent(eq("ideal.start-payment.invalid-configuration"));
}
Also used : IdealRequest(com.braintreepayments.api.models.IdealRequest) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 23 with TestConfigurationBuilder

use of com.braintreepayments.testutils.TestConfigurationBuilder in project braintree_android by braintree.

the class IdealUnitTest method pollForCompletion_pollsUntilMaxRetryCountExceeded.

@Test(timeout = 5000)
public void pollForCompletion_pollsUntilMaxRetryCountExceeded() throws InterruptedException, JSONException, InvalidArgumentException {
    Configuration configuration = new TestConfigurationBuilder().ideal(new TestIdealConfigurationBuilder().routeId("some-route-id")).braintreeApi(new TestBraintreeApiConfigurationBuilder().accessToken("access-token").url("http://api.braintree.com")).buildConfiguration();
    final BraintreeFragment fragment = new MockFragmentBuilder().authorization(Authorization.fromString(stringFromFixture("client_token.json"))).configuration(configuration).build();
    BraintreeApiHttpClient apiHttpClient = mock(BraintreeApiHttpClient.class);
    when(fragment.getBraintreeApiHttpClient()).thenReturn(apiHttpClient);
    final String resultFixture = stringFromFixture("payment_methods/pending_ideal_bank_payment.json");
    final CountDownLatch latch = new CountDownLatch(2);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[1];
            callback.success(resultFixture);
            latch.countDown();
            return null;
        }
    }).when(apiHttpClient).get(eq("/ideal-payments/ideal_payment_id/status"), any(HttpResponseCallback.class));
    IdealResult idealResult = IdealResult.fromJson(resultFixture);
    putResultIdInPrefs(idealResult.getId());
    Ideal.pollForCompletion(fragment, idealResult.getId(), 1, 1000);
    // Two retries = three calls to latch.countDown
    latch.await();
}
Also used : Configuration(com.braintreepayments.api.models.Configuration) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) BraintreeApiHttpClient(com.braintreepayments.api.internal.BraintreeApiHttpClient) Answer(org.mockito.stubbing.Answer) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) TestBraintreeApiConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestBraintreeApiConfigurationBuilder) TestIdealConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestIdealConfigurationBuilder) InvocationOnMock(org.mockito.invocation.InvocationOnMock) JSONObject(org.json.JSONObject) IdealResult(com.braintreepayments.api.models.IdealResult) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 24 with TestConfigurationBuilder

use of com.braintreepayments.testutils.TestConfigurationBuilder in project braintree_android by braintree.

the class IdealUnitTest method fetchIssuingBanks_postsConfigurationExceptionWhenIdealNotEnabled.

@Test
public void fetchIssuingBanks_postsConfigurationExceptionWhenIdealNotEnabled() throws InvalidArgumentException {
    Configuration configuration = new TestConfigurationBuilder().braintreeApi(new TestBraintreeApiConfigurationBuilder().accessToken("access-token").url("http://api.braintree.com")).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("iDEAL is not enabled for this merchant.", e.getMessage());
}
Also used : TestBraintreeApiConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestBraintreeApiConfigurationBuilder) Configuration(com.braintreepayments.api.models.Configuration) 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 25 with TestConfigurationBuilder

use of com.braintreepayments.testutils.TestConfigurationBuilder in project braintree_android by braintree.

the class IdealUnitTest method onActivityResult_checksPaymentStatusOnceBeforeInvokingCallback.

@Test(timeout = 10000)
public void onActivityResult_checksPaymentStatusOnceBeforeInvokingCallback() throws InvalidArgumentException, JSONException, InterruptedException {
    Configuration configuration = new TestConfigurationBuilder().ideal(new TestIdealConfigurationBuilder().routeId("some-route-id")).braintreeApi(new TestBraintreeApiConfigurationBuilder().accessToken("access-token").url("http://api.braintree.com")).buildConfiguration();
    final BraintreeFragment fragment = new MockFragmentBuilder().authorization(Authorization.fromString(stringFromFixture("client_token.json"))).configuration(configuration).build();
    BraintreeApiHttpClient apiHttpClient = mock(BraintreeApiHttpClient.class);
    when(fragment.getBraintreeApiHttpClient()).thenReturn(apiHttpClient);
    final String resultFixture = stringFromFixture("payment_methods/pending_ideal_bank_payment.json");
    final CountDownLatch latch = new CountDownLatch(1);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[1];
            callback.success(resultFixture);
            latch.countDown();
            return null;
        }
    }).when(apiHttpClient).get(eq("/ideal-payments/ideal_payment_id/status"), any(HttpResponseCallback.class));
    IdealResult idealResult = IdealResult.fromJson(resultFixture);
    putResultIdInPrefs(idealResult.getId());
    Ideal.onActivityResult(fragment, Activity.RESULT_OK);
    latch.await();
}
Also used : Configuration(com.braintreepayments.api.models.Configuration) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) BraintreeApiHttpClient(com.braintreepayments.api.internal.BraintreeApiHttpClient) Answer(org.mockito.stubbing.Answer) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) TestBraintreeApiConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestBraintreeApiConfigurationBuilder) TestIdealConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestIdealConfigurationBuilder) InvocationOnMock(org.mockito.invocation.InvocationOnMock) JSONObject(org.json.JSONObject) IdealResult(com.braintreepayments.api.models.IdealResult) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)39 Test (org.junit.Test)35 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)19 Configuration (com.braintreepayments.api.models.Configuration)12 JSONException (org.json.JSONException)9 JSONObject (org.json.JSONObject)9 Intent (android.content.Intent)8 CountDownLatch (java.util.concurrent.CountDownLatch)6 UnionPayCardBuilder (com.braintreepayments.api.models.UnionPayCardBuilder)5 TestBraintreeApiConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder.TestBraintreeApiConfigurationBuilder)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 Answer (org.mockito.stubbing.Answer)5 Context (android.content.Context)4 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)4 CardBuilder (com.braintreepayments.api.models.CardBuilder)4 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)4 TestAndroidPayConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder.TestAndroidPayConfigurationBuilder)4 TestIdealConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder.TestIdealConfigurationBuilder)4 TestKountConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder.TestKountConfigurationBuilder)4 Before (org.junit.Before)4