Search in sources :

Example 6 with TestConfigurationBuilder

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

the class BraintreeFragmentUnitTest method getGraphQLHttpClient_returnsGraphQLHttpClientWhenEnabled.

@Test
public void getGraphQLHttpClient_returnsGraphQLHttpClientWhenEnabled() throws InvalidArgumentException {
    Configuration configuration = new TestConfigurationBuilder().graphQL().buildConfiguration();
    mockConfigurationManager(configuration);
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    assertNotNull(fragment.getGraphQLHttpClient());
}
Also used : Configuration(com.braintreepayments.api.models.Configuration) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with TestConfigurationBuilder

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

the class BraintreeFragmentUnitTest method onStop_flushesAnalyticsEvents.

@Test
public void onStop_flushesAnalyticsEvents() throws JSONException, InvalidArgumentException {
    String configuration = new TestConfigurationBuilder().withAnalytics().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();
    ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
    verify(context).startService(intentCaptor.capture());
    Intent serviceIntent = intentCaptor.getValue();
    assertEquals(TOKENIZATION_KEY, serviceIntent.getStringExtra(AnalyticsIntentService.EXTRA_AUTHORIZATION));
    assertEquals(configuration, serviceIntent.getStringExtra(AnalyticsIntentService.EXTRA_CONFIGURATION));
}
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 8 with TestConfigurationBuilder

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

the class BraintreeFragmentUnitTest method flushAnalyticsEvents_fallsBackToSenderIfStartingServiceThrows.

@Test
public void flushAnalyticsEvents_fallsBackToSenderIfStartingServiceThrows() throws JSONException, InvalidArgumentException {
    mockStatic(AnalyticsSender.class);
    String configuration = new TestConfigurationBuilder().withAnalytics().build();
    mockConfigurationManager(Configuration.fromJson(configuration));
    Robolectric.getForegroundThreadScheduler().pause();
    Context context = spy(RuntimeEnvironment.application);
    doThrow(new RuntimeException()).when(context).startService(any(Intent.class));
    when(mActivity.getApplicationContext()).thenReturn(context);
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    Robolectric.getForegroundThreadScheduler().unPause();
    Robolectric.getForegroundThreadScheduler().advanceToLastPostedRunnable();
    fragment.onStop();
    verifyStatic();
    AnalyticsSender.send(eq(context), any(Authorization.class), any(BraintreeHttpClient.class), eq(Configuration.fromJson(configuration).getAnalytics().getUrl()), eq(false));
}
Also used : Context(android.content.Context) Authorization(com.braintreepayments.api.models.Authorization) Intent(android.content.Intent) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) BraintreeHttpClient(com.braintreepayments.api.internal.BraintreeHttpClient) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with TestConfigurationBuilder

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

the class BraintreeFragmentUnitTest method onResume_postsConfigurationToCallbackForNewActivity.

@Test
public void onResume_postsConfigurationToCallbackForNewActivity() throws InvalidArgumentException {
    Configuration configuration = new TestConfigurationBuilder().buildConfiguration();
    mockConfigurationManager(configuration);
    UnitTestListenerActivity activity = Robolectric.setupActivity(UnitTestListenerActivity.class);
    BraintreeFragment fragment = BraintreeFragment.newInstance(activity, TOKENIZATION_KEY);
    fragment.onAttach(null);
    fragment.onResume();
    assertEquals(2, activity.configurations.size());
    assertEquals(configuration, activity.configurations.get(0));
    assertEquals(configuration, activity.configurations.get(1));
}
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 10 with TestConfigurationBuilder

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

the class BraintreeFragmentUnitTest method sendEvent_addsEventToDatabase.

@Test
public void sendEvent_addsEventToDatabase() throws InvalidArgumentException {
    Configuration configuration = new TestConfigurationBuilder().withAnalytics().buildConfiguration();
    BraintreeFragment fragment = spy(BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY));
    when(fragment.getConfiguration()).thenReturn(configuration);
    fragment.sendAnalyticsEvent("test.event");
    verifyAnalyticsEvent(mActivity, "test.event");
}
Also used : Configuration(com.braintreepayments.api.models.Configuration) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) 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