Search in sources :

Example 26 with TestConfigurationBuilder

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

the class PayPalUnitTest method setup.

@Before
public void setup() throws Exception {
    spy(PayPal.class);
    doReturn(true).when(PayPal.class, "isManifestValid", any(Context.class));
    spy(Recipe.class);
    doReturn(true).when(Recipe.class, "isValidBrowserTarget", any(Context.class), anyString(), anyString());
    Authorization authorization = mock(Authorization.class);
    when(authorization.getBearer()).thenReturn("authorization");
    when(authorization.toString()).thenReturn("authorization");
    Configuration configuration = new TestConfigurationBuilder().withAnalytics().paypal(new TestPayPalConfigurationBuilder(true).environment("offline").billingAgreementsEnabled(false)).buildConfiguration();
    mMockFragmentBuilder = new MockFragmentBuilder().authorization(authorization).configuration(configuration);
}
Also used : Context(android.content.Context) Authorization(com.braintreepayments.api.models.Authorization) TestPayPalConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestPayPalConfigurationBuilder) Configuration(com.braintreepayments.api.models.Configuration) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) Before(org.junit.Before)

Example 27 with TestConfigurationBuilder

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

the class TokenizationClientUnitTest method tokenize_sendGraphQLAnalyticsEventOnFailure.

@Test
public void tokenize_sendGraphQLAnalyticsEventOnFailure() {
    BraintreeFragment fragment = new MockFragmentBuilder().configuration(new TestConfigurationBuilder().graphQL().build()).graphQLErrorResponse(ErrorWithResponse.fromGraphQLJson(stringFromFixture("errors/graphql/credit_card_error.json"))).build();
    CardBuilder cardBuilder = new CardBuilder();
    TokenizationClient.tokenize(fragment, cardBuilder, new PaymentMethodNonceCallback() {

        @Override
        public void success(PaymentMethodNonce paymentMethodNonce) {
        }

        @Override
        public void failure(Exception exception) {
        }
    });
    verify(fragment).sendAnalyticsEvent("card.graphql.tokenization.failure");
}
Also used : UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) CardBuilder(com.braintreepayments.api.models.CardBuilder) PaymentMethodNonceCallback(com.braintreepayments.api.interfaces.PaymentMethodNonceCallback) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) BraintreeException(com.braintreepayments.api.exceptions.BraintreeException) JSONException(org.json.JSONException) Test(org.junit.Test)

Example 28 with TestConfigurationBuilder

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

the class TokenizationClientUnitTest method tokenize_sendGraphQLAnalyticsEventWhenEnabled.

@Test
public void tokenize_sendGraphQLAnalyticsEventWhenEnabled() {
    BraintreeFragment fragment = new MockFragmentBuilder().configuration(new TestConfigurationBuilder().graphQL().build()).build();
    CardBuilder cardBuilder = new CardBuilder();
    TokenizationClient.tokenize(fragment, cardBuilder, null);
    verify(fragment).sendAnalyticsEvent("card.graphql.tokenization.started");
}
Also used : UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) CardBuilder(com.braintreepayments.api.models.CardBuilder) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) Test(org.junit.Test)

Example 29 with TestConfigurationBuilder

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

the class TokenizationClientUnitTest method tokenize_sendGraphQLAnalyticsEventOnSuccess.

@Test
public void tokenize_sendGraphQLAnalyticsEventOnSuccess() {
    BraintreeFragment fragment = new MockFragmentBuilder().configuration(new TestConfigurationBuilder().graphQL().build()).graphQLSuccessResponse(stringFromFixture("response/graphql/credit_card.json")).build();
    CardBuilder cardBuilder = new CardBuilder();
    TokenizationClient.tokenize(fragment, cardBuilder, new PaymentMethodNonceCallback() {

        @Override
        public void success(PaymentMethodNonce paymentMethodNonce) {
        }

        @Override
        public void failure(Exception exception) {
        }
    });
    verify(fragment).sendAnalyticsEvent("card.graphql.tokenization.success");
}
Also used : UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) CardBuilder(com.braintreepayments.api.models.CardBuilder) PaymentMethodNonceCallback(com.braintreepayments.api.interfaces.PaymentMethodNonceCallback) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) BraintreeException(com.braintreepayments.api.exceptions.BraintreeException) JSONException(org.json.JSONException) Test(org.junit.Test)

Example 30 with TestConfigurationBuilder

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

the class TokenizationClientUnitTest method tokenize_tokenizesCardsWithGraphQLWhenEnabled.

@Test
public void tokenize_tokenizesCardsWithGraphQLWhenEnabled() throws BraintreeException {
    BraintreeFragment fragment = new MockFragmentBuilder().configuration(new TestConfigurationBuilder().graphQL().build()).build();
    CardBuilder cardBuilder = new CardBuilder();
    TokenizationClient.tokenize(fragment, cardBuilder, null);
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verifyZeroInteractions(fragment.getHttpClient());
    verify(fragment.getGraphQLHttpClient()).post(captor.capture(), any(HttpResponseCallback.class));
    assertEquals(cardBuilder.buildGraphQL(fragment.getApplicationContext(), fragment.getAuthorization()), captor.getValue());
}
Also used : UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) CardBuilder(com.braintreepayments.api.models.CardBuilder) Matchers.anyString(org.mockito.Matchers.anyString) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) 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