Search in sources :

Example 16 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class VenmoUnitTest method performAppSwitch_sendsAnalyticsEventWhenStarted.

@Test
public void performAppSwitch_sendsAnalyticsEventWhenStarted() {
    Configuration configuration = getConfigurationFromFixture();
    BraintreeFragment fragment = new MockFragmentBuilder().context(VenmoInstalledContextFactory.venmoInstalledContext(true, RuntimeEnvironment.application)).configuration(configuration).build();
    Venmo.authorizeAccount(fragment, false);
    verify(fragment).sendAnalyticsEvent("pay-with-venmo.selected");
    verify(fragment).sendAnalyticsEvent("pay-with-venmo.app-switch.started");
}
Also used : Configuration(com.braintreepayments.api.models.Configuration) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 17 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class VenmoUnitTest method onActivityResult_withSuccessfulVaultCall_returnsVenmoAccountNonce.

@Test
public void onActivityResult_withSuccessfulVaultCall_returnsVenmoAccountNonce() throws InvalidArgumentException {
    Configuration configuration = getConfigurationFromFixture();
    Authorization clientToken = Authorization.fromString(stringFromFixture("base_64_client_token.txt"));
    disableSignatureVerification();
    BraintreeFragment fragment = new MockFragmentBuilder().context(VenmoInstalledContextFactory.venmoInstalledContext(true, RuntimeEnvironment.application)).configuration(configuration).authorization(clientToken).sessionId("session-id").successResponse(stringFromFixture("payment_methods/venmo_account_response.json")).build();
    Venmo.authorizeAccount(fragment, true);
    ArgumentCaptor<PaymentMethodNonce> responseCaptor = ArgumentCaptor.forClass(PaymentMethodNonce.class);
    Intent responseIntent = new Intent().putExtra(Venmo.EXTRA_PAYMENT_METHOD_NONCE, "nonce");
    Venmo.onActivityResult(fragment, Activity.RESULT_OK, responseIntent);
    verify(fragment).postCallback(responseCaptor.capture());
    PaymentMethodNonce capturedNonce = responseCaptor.getValue();
    assertTrue(capturedNonce instanceof VenmoAccountNonce);
    VenmoAccountNonce venmoAccountNonce = (VenmoAccountNonce) capturedNonce;
    assertEquals("Venmo", venmoAccountNonce.getTypeLabel());
    assertEquals("fake-venmo-nonce", venmoAccountNonce.getNonce());
    assertEquals("venmojoe", venmoAccountNonce.getUsername());
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) Configuration(com.braintreepayments.api.models.Configuration) VenmoAccountNonce(com.braintreepayments.api.models.VenmoAccountNonce) Intent(android.content.Intent) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 18 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class VenmoUnitTest method performAppSwitch_sendsAnalyticsEvent.

@Test
public void performAppSwitch_sendsAnalyticsEvent() {
    Configuration configuration = getConfigurationFromFixture();
    BraintreeFragment fragment = new MockFragmentBuilder().configuration(configuration).build();
    Venmo.authorizeAccount(fragment);
    verify(fragment).sendAnalyticsEvent("pay-with-venmo.selected");
}
Also used : Configuration(com.braintreepayments.api.models.Configuration) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 19 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class BraintreeFragmentUnitTest method onSaveInstanceState_savesState.

@Test
public void onSaveInstanceState_savesState() throws InvalidArgumentException, JSONException {
    Configuration configuration = new TestConfigurationBuilder().buildConfiguration();
    mockConfigurationManager(configuration);
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    Bundle bundle = new Bundle();
    fragment.onSaveInstanceState(bundle);
    assertTrue(bundle.getParcelableArrayList(BraintreeFragment.EXTRA_CACHED_PAYMENT_METHOD_NONCES).isEmpty());
    assertFalse(bundle.getBoolean(BraintreeFragment.EXTRA_FETCHED_PAYMENT_METHOD_NONCES));
    assertEquals(configuration.toJson(), bundle.getString(BraintreeFragment.EXTRA_CONFIGURATION));
}
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 20 with Configuration

use of com.braintreepayments.api.models.Configuration 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)

Aggregations

Configuration (com.braintreepayments.api.models.Configuration)84 Test (org.junit.Test)66 ConfigurationListener (com.braintreepayments.api.interfaces.ConfigurationListener)36 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)35 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)19 JSONException (org.json.JSONException)19 Authorization (com.braintreepayments.api.models.Authorization)14 Intent (android.content.Intent)13 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)13 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)12 AuthorizationRequest (com.paypal.android.sdk.onetouch.core.AuthorizationRequest)11 BillingAgreementRequest (com.paypal.android.sdk.onetouch.core.BillingAgreementRequest)11 CheckoutRequest (com.paypal.android.sdk.onetouch.core.CheckoutRequest)11 JSONObject (org.json.JSONObject)11 UnexpectedException (com.braintreepayments.api.exceptions.UnexpectedException)10 SharedPreferencesHelper.writeMockConfiguration (com.braintreepayments.testutils.SharedPreferencesHelper.writeMockConfiguration)10 Request (com.paypal.android.sdk.onetouch.core.Request)10 Bundle (android.os.Bundle)9 BraintreeFragmentTestUtils.getMockFragmentWithConfiguration (com.braintreepayments.api.BraintreeFragmentTestUtils.getMockFragmentWithConfiguration)6 BraintreeFragmentTestUtils.getFragmentWithConfiguration (com.braintreepayments.api.BraintreeFragmentTestUtils.getFragmentWithConfiguration)5