Search in sources :

Example 31 with TestConfigurationBuilder

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

the class BraintreeFragmentUnitTest method getBraintreeApiHttpClient_returnsExistingClientIfOneExists.

@Test
public void getBraintreeApiHttpClient_returnsExistingClientIfOneExists() throws Exception {
    String configuration = new TestConfigurationBuilder().braintreeApi(new TestBraintreeApiConfigurationBuilder().accessToken("some-token").url("http://braintree-api.com")).build();
    mockConfigurationManager(Configuration.fromJson(configuration));
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    HttpClient client = fragment.getBraintreeApiHttpClient();
    HttpClient client2 = fragment.getBraintreeApiHttpClient();
    assertSame(client, client2);
}
Also used : TestBraintreeApiConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestBraintreeApiConfigurationBuilder) BraintreeHttpClient(com.braintreepayments.api.internal.BraintreeHttpClient) HttpClient(com.braintreepayments.api.internal.HttpClient) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 32 with TestConfigurationBuilder

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

the class BraintreeFragmentUnitTest method getBraintreeApiHttpClient_returnsNull_whenNotPresent.

@Test
public void getBraintreeApiHttpClient_returnsNull_whenNotPresent() throws InvalidArgumentException, JSONException {
    String configuration = new TestConfigurationBuilder().build();
    mockConfigurationManager(Configuration.fromJson(configuration));
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    assertNull(fragment.getBraintreeApiHttpClient());
}
Also used : TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 33 with TestConfigurationBuilder

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

the class DataCollectorUnitTest method collectDeviceData_sendsAnalyticsEventsWhenSuccessful.

@Test
public void collectDeviceData_sendsAnalyticsEventsWhenSuccessful() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final BraintreeFragment fragment = new MockFragmentBuilder().configuration(new TestConfigurationBuilder().kount(new TestKountConfigurationBuilder().kountMerchantId("600000")).build()).build();
    final com.kount.api.DataCollector mockDataCollector = mock(com.kount.api.DataCollector.class);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            ((CompletionHandler) invocation.getArguments()[1]).completed((String) invocation.getArguments()[0]);
            return null;
        }
    }).when(mockDataCollector).collectForSession(anyString(), any(CompletionHandler.class));
    mockStatic(com.kount.api.DataCollector.class);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return mockDataCollector;
        }
    }).when(com.kount.api.DataCollector.class);
    com.kount.api.DataCollector.getInstance();
    DataCollector.collectDeviceData(fragment, new BraintreeResponseListener<String>() {

        @Override
        public void onResponse(String s) {
            verify(fragment).sendAnalyticsEvent("data-collector.kount.started");
            verify(fragment).sendAnalyticsEvent("data-collector.kount.succeeded");
            latch.countDown();
        }
    });
    latch.await();
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) CountDownLatch(java.util.concurrent.CountDownLatch) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) TestKountConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestKountConfigurationBuilder) Answer(org.mockito.stubbing.Answer) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CompletionHandler(com.kount.api.DataCollector.CompletionHandler) JSONObject(org.json.JSONObject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 34 with TestConfigurationBuilder

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

the class VenmoUnitTest method authorizeAccount_postsExceptionWhenNotEnabled.

@Test
public void authorizeAccount_postsExceptionWhenNotEnabled() throws JSONException {
    Configuration configuration = new TestConfigurationBuilder().buildConfiguration();
    BraintreeFragment fragment = new MockFragmentBuilder().configuration(configuration).build();
    Venmo.authorizeAccount(fragment, false);
    ArgumentCaptor<AppSwitchNotAvailableException> captor = ArgumentCaptor.forClass(AppSwitchNotAvailableException.class);
    verify(fragment).postCallback(captor.capture());
    assertEquals("Venmo is not enabled", captor.getValue().getMessage());
}
Also used : AppSwitchNotAvailableException(com.braintreepayments.api.exceptions.AppSwitchNotAvailableException) Configuration(com.braintreepayments.api.models.Configuration) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 35 with TestConfigurationBuilder

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

the class DataCollectorTest method collectDeviceData_withListener_usesDirectMerchantId.

@Test(timeout = 10000)
public void collectDeviceData_withListener_usesDirectMerchantId() throws InterruptedException {
    String configuration = new TestConfigurationBuilder().kount(new TestKountConfigurationBuilder().kountMerchantId("600000")).build();
    BraintreeFragment fragment = getFragmentWithConfiguration(mActivity, configuration);
    DataCollector.collectDeviceData(fragment, "600001", new BraintreeResponseListener<String>() {

        @Override
        public void onResponse(String deviceData) {
            try {
                JSONObject json = new JSONObject(deviceData);
                assertFalse(TextUtils.isEmpty(json.getString("device_session_id")));
                assertEquals("600001", json.getString("fraud_merchant_id"));
                assertNotNull(json.getString("correlation_id"));
            } catch (JSONException e) {
                fail(e.getMessage());
            }
            mCountDownLatch.countDown();
        }
    });
    mCountDownLatch.await();
}
Also used : TestKountConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestKountConfigurationBuilder) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) 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