Search in sources :

Example 1 with TestKountConfigurationBuilder

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

the class DataCollectorUnitTest method collectDeviceData_sendsAnalyticsEventsWhenFailed.

@Test
public void collectDeviceData_sendsAnalyticsEventsWhenFailed() 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]).failed((String) invocation.getArguments()[0], null);
            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.failed");
            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 2 with TestKountConfigurationBuilder

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

the class DataCollectorTest method collectDeviceData_withListener.

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

        @Override
        public void onResponse(String deviceData) {
            try {
                JSONObject json = new JSONObject(deviceData);
                assertFalse(TextUtils.isEmpty(json.getString("device_session_id")));
                assertEquals("500000", 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)

Example 3 with TestKountConfigurationBuilder

use of com.braintreepayments.testutils.TestConfigurationBuilder.TestKountConfigurationBuilder 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 4 with TestKountConfigurationBuilder

use of com.braintreepayments.testutils.TestConfigurationBuilder.TestKountConfigurationBuilder 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)4 TestKountConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder.TestKountConfigurationBuilder)4 JSONObject (org.json.JSONObject)4 Test (org.junit.Test)4 CompletionHandler (com.kount.api.DataCollector.CompletionHandler)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 JSONException (org.json.JSONException)2 Matchers.anyString (org.mockito.Matchers.anyString)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 PowerMockito.doAnswer (org.powermock.api.mockito.PowerMockito.doAnswer)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2