Search in sources :

Example 1 with TestConfigurationBuilder

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

the class IdealUnitTest method setUp.

@Before
public void setUp() throws InvalidArgumentException {
    mConfiguration = new TestConfigurationBuilder().assetsUrl("http://assets.example.com").ideal(new TestIdealConfigurationBuilder().routeId("some-route-id").assetsUrl("http://assets.example.com")).braintreeApi(new TestBraintreeApiConfigurationBuilder().accessToken("access-token").url("http://api.braintree.com")).buildConfiguration();
    mBraintreeFragment = getMockFragment(stringFromFixture("client_token.json"), mConfiguration);
    mMockApiClient = mock(BraintreeApiHttpClient.class);
    when(mBraintreeFragment.getBraintreeApiHttpClient()).thenReturn(mMockApiClient);
}
Also used : BraintreeApiHttpClient(com.braintreepayments.api.internal.BraintreeApiHttpClient) TestBraintreeApiConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestBraintreeApiConfigurationBuilder) TestIdealConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestIdealConfigurationBuilder) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) Before(org.junit.Before)

Example 2 with TestConfigurationBuilder

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

the class IdealUnitTest method fetchIssuingBanks_postsConfigurationExceptionWhenBraintreeApiNotEnabled.

@Test
public void fetchIssuingBanks_postsConfigurationExceptionWhenBraintreeApiNotEnabled() throws InvalidArgumentException, InterruptedException {
    Configuration configuration = new TestConfigurationBuilder().ideal(new TestIdealConfigurationBuilder().routeId("some-route-id")).buildConfiguration();
    BraintreeFragment fragment = getMockFragment(stringFromFixture("client_token.json"), configuration);
    Ideal.fetchIssuingBanks(fragment, new BraintreeResponseListener<List<IdealBank>>() {

        @Override
        public void onResponse(List<IdealBank> idealBanks) {
            fail("Success listener called");
        }
    });
    ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(Exception.class);
    verify(fragment).postCallback(captor.capture());
    Exception e = captor.getValue();
    assertEquals("Your access is restricted and cannot use this part of the Braintree API.", e.getMessage());
}
Also used : Configuration(com.braintreepayments.api.models.Configuration) TestIdealConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestIdealConfigurationBuilder) IdealBank(com.braintreepayments.api.models.IdealBank) List(java.util.List) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) JSONException(org.json.JSONException) IOException(java.io.IOException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with TestConfigurationBuilder

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

the class TokenizationClientUnitTest method tokenize_tokenizesNonCardPaymentMethodsWithRestWhenGraphQLIsEnabled.

@Test
public void tokenize_tokenizesNonCardPaymentMethodsWithRestWhenGraphQLIsEnabled() {
    BraintreeFragment fragment = new MockFragmentBuilder().configuration(new TestConfigurationBuilder().graphQL().build()).build();
    TokenizationClient.tokenize(fragment, new PayPalAccountBuilder(), null);
    TokenizationClient.tokenize(fragment, new UnionPayCardBuilder(), null);
    TokenizationClient.tokenize(fragment, new VenmoAccountBuilder(), null);
    verifyZeroInteractions(fragment.getGraphQLHttpClient());
}
Also used : VenmoAccountBuilder(com.braintreepayments.api.models.VenmoAccountBuilder) PayPalAccountBuilder(com.braintreepayments.api.models.PayPalAccountBuilder) UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) Test(org.junit.Test)

Example 4 with TestConfigurationBuilder

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

the class IdealRequestUnitTest method build_setsAllParams.

@Test
public void build_setsAllParams() throws NoSuchFieldException, IllegalAccessException, JSONException {
    Configuration configuration = new TestConfigurationBuilder().assetsUrl("http://assets.example.com").buildConfiguration();
    List<IdealBank> banks = IdealBank.fromJson(configuration, stringFromFixture("payment_methods/ideal_issuing_banks.json"));
    IdealRequest builder = new IdealRequest().issuerId(banks.get(0).getId()).orderId("some-order-id").amount("1.00").currency("USD");
    JSONObject json = new JSONObject(builder.build("http://example.com", "some-route-id"));
    assertEquals("some-route-id", json.getString("route_id"));
    assertEquals("some-order-id", json.getString("order_id"));
    assertEquals("ABNANL2A", json.getString("issuer"));
    assertEquals("1.00", json.getString("amount"));
    assertEquals("USD", json.getString("currency"));
    assertEquals("http://example.com", json.getString("redirect_url"));
}
Also used : JSONObject(org.json.JSONObject) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) Test(org.junit.Test)

Example 5 with TestConfigurationBuilder

use of com.braintreepayments.testutils.TestConfigurationBuilder 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)

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