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());
}
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));
}
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));
}
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));
}
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");
}
Aggregations