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