Search in sources :

Example 11 with TestConfigurationBuilder

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

the class BraintreeFragmentUnitTest method onCreate_restoresConfigurationAndHttpClients.

@Test
public void onCreate_restoresConfigurationAndHttpClients() throws Exception {
    Configuration configuration = new TestConfigurationBuilder().graphQL().buildConfiguration();
    mockConfigurationManager(configuration);
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    Bundle bundle = new Bundle();
    fragment.onSaveInstanceState(bundle);
    setField("mConfiguration", fragment, null);
    fragment.mHttpClient = null;
    fragment.onCreate(bundle);
    assertNotNull(fragment.getConfiguration());
    assertNotNull(fragment.mHttpClient);
    assertNotNull(fragment.mGraphQLHttpClient);
    assertEquals("client_api_url", getField("mBaseUrl", fragment.mHttpClient));
}
Also used : Configuration(com.braintreepayments.api.models.Configuration) Bundle(android.os.Bundle) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with TestConfigurationBuilder

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

the class BraintreeFragmentUnitTest method flushAnalyticsEvents_doesNotSendAnalyticsIfNotEnabled.

@Test
public void flushAnalyticsEvents_doesNotSendAnalyticsIfNotEnabled() throws JSONException, InvalidArgumentException {
    String configuration = new TestConfigurationBuilder().build();
    mockConfigurationManager(Configuration.fromJson(configuration));
    Robolectric.getForegroundThreadScheduler().pause();
    Context context = spy(RuntimeEnvironment.application);
    when(mActivity.getApplicationContext()).thenReturn(context);
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    Robolectric.getForegroundThreadScheduler().unPause();
    Robolectric.getForegroundThreadScheduler().advanceToLastPostedRunnable();
    fragment.onStop();
    verify(context, times(0)).startService(any(Intent.class));
    verifyZeroInteractions(AnalyticsSender.class);
}
Also used : Context(android.content.Context) Intent(android.content.Intent) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with TestConfigurationBuilder

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

the class BraintreeFragmentUnitTest method onResume_doesNotPostConfigurationToCallbackForTheSameActivity.

@Test
public void onResume_doesNotPostConfigurationToCallbackForTheSameActivity() throws InvalidArgumentException {
    Configuration configuration = new TestConfigurationBuilder().buildConfiguration();
    mockConfigurationManager(configuration);
    UnitTestListenerActivity activity = Robolectric.setupActivity(UnitTestListenerActivity.class);
    BraintreeFragment fragment = BraintreeFragment.newInstance(activity, TOKENIZATION_KEY);
    fragment.onResume();
    assertEquals(1, activity.configurations.size());
    assertEquals(configuration, activity.configurations.get(0));
}
Also used : Configuration(com.braintreepayments.api.models.Configuration) UnitTestListenerActivity(com.braintreepayments.api.test.UnitTestListenerActivity) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with TestConfigurationBuilder

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

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

the class ThreeDSecureTest method onActivityResult_postsUnrecoverableErrorsToListeners.

@Test(timeout = 2000)
public void onActivityResult_postsUnrecoverableErrorsToListeners() throws InterruptedException {
    BraintreeFragment fragment = getMockFragmentWithConfiguration(mActivity, new TestConfigurationBuilder().build());
    fragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            assertEquals("Error!", error.getMessage());
            mCountDownLatch.countDown();
        }
    });
    ThreeDSecureAuthenticationResponse authResponse = ThreeDSecureAuthenticationResponse.fromException("Error!");
    Intent data = new Intent().putExtra(ThreeDSecureWebViewActivity.EXTRA_THREE_D_SECURE_RESULT, authResponse);
    ThreeDSecure.onActivityResult(fragment, Activity.RESULT_OK, data);
    mCountDownLatch.await();
}
Also used : ThreeDSecureAuthenticationResponse(com.braintreepayments.api.models.ThreeDSecureAuthenticationResponse) Intent(android.content.Intent) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) JSONException(org.json.JSONException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) 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