Search in sources :

Example 21 with Configuration

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

the class BraintreeFragmentUnitTest method waitForConfiguration_postsCallbackAfterConfigurationIsReceived.

@Test
public void waitForConfiguration_postsCallbackAfterConfigurationIsReceived() throws JSONException, InvalidArgumentException {
    final Configuration configuration = Configuration.fromJson(stringFromFixture("configuration/configuration.json"));
    mockConfigurationManager(configuration);
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    fragment.waitForConfiguration(new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration returnedConfiguration) {
            assertEquals(configuration, returnedConfiguration);
            mCalled.set(true);
        }
    });
    assertTrue(mCalled.get());
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) Configuration(com.braintreepayments.api.models.Configuration) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 22 with Configuration

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

the class BraintreeFragmentUnitTest method waitForConfiguration_doesNotPostCallbackWhenNotAttached.

@Test
public void waitForConfiguration_doesNotPostCallbackWhenNotAttached() throws JSONException, InvalidArgumentException {
    final Configuration configuration = Configuration.fromJson(stringFromFixture("configuration/configuration.json"));
    mockConfigurationManager(configuration);
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    mActivity.getFragmentManager().beginTransaction().detach(fragment).commit();
    mActivity.getFragmentManager().executePendingTransactions();
    fragment.waitForConfiguration(new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration returnedConfiguration) {
            fail("onConfigurationFetched was called");
        }
    });
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) Configuration(com.braintreepayments.api.models.Configuration) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 23 with Configuration

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

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

Example 25 with Configuration

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

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