com.braintreepayments.api.exceptions.InvalidArgumentException Java Examples

The following examples show how to use com.braintreepayments.api.exceptions.InvalidArgumentException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VenmoUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void onActivityResult_doesNotPerformRequestIfTokenizationKeyUsed()
        throws NoSuchAlgorithmException, InvalidArgumentException {
    Configuration configuration = getConfigurationFromFixture();

    mockStatic(TokenizationClient.class);
    BraintreeFragment fragment = new MockFragmentBuilder()
            .context(VenmoInstalledContextFactory.venmoInstalledContext(true, RuntimeEnvironment.application))
            .configuration(configuration)
            .authorization(Authorization.fromString("sandbox_tk_abcd"))
            .sessionId("another-session-id")
            .build();

    Venmo.authorizeAccount(fragment, true);
    Venmo.onActivityResult(fragment, AppCompatActivity.RESULT_OK, new Intent());

    verifyStatic(times(0));
    TokenizationClient.tokenize(eq(fragment), any(VenmoAccountBuilder.class), any(PaymentMethodNonceCallback.class));
}
 
Example #2
Source File: BraintreeFragmentUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void doesNotExecuteCallbackWhenShouldRunIsFalse() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mAppCompatActivity, TOKENIZATION_KEY);
    QueuedCallback callback = new QueuedCallback() {
        @Override
        public boolean shouldRun() {
            return false;
        }

        @Override
        public void run() {
            fail("Listener was called");
        }
    };

    fragment.postOrQueueCallback(callback);
}
 
Example #3
Source File: BraintreeFragmentUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void addListener_flushesErrorWithResponseCallback() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mAppCompatActivity, TOKENIZATION_KEY);
    fragment.postCallback(new ErrorWithResponse(422, ""));

    fragment.addListener(new BraintreeErrorListener() {
        @Override
        public void onError(Exception error) {
            assertTrue(error instanceof ErrorWithResponse);
            assertEquals(422, ((ErrorWithResponse) error).getStatusCode());
            mCalled.set(true);
        }
    });

    assertTrue(mCalled.get());
}
 
Example #4
Source File: DropInResultUnitTest.java    From braintree-android-drop-in with MIT License 6 votes vote down vote up
@Test
public void fetchDropInResult_callsListenerWithErrorWhenErrorIsPosted()
        throws InterruptedException, InvalidArgumentException {
    setupFragment(new BraintreeUnitTestHttpClient()
            .configuration(new TestConfigurationBuilder().build())
            .errorResponse(BraintreeUnitTestHttpClient.GET_PAYMENT_METHODS, 404,
                    "No payment methods found"));
    DropInResult.DropInResultListener listener = new DropInResult.DropInResultListener() {
        @Override
        public void onError(Exception exception) {
            assertEquals("No payment methods found", exception.getMessage());
            mCountDownLatch.countDown();
        }

        @Override
        public void onResult(DropInResult result) {
            fail("onResult called");
        }
    };

    DropInResult.fetchDropInResult(mActivity, base64EncodedClientTokenFromFixture("client_token.json"), listener);

    mCountDownLatch.await();
}
 
Example #5
Source File: ConfigurationManagerUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test(timeout = 1000)
public void getConfiguration_takesClientTokenIntoAccountForCache()
        throws InvalidArgumentException, InterruptedException {
    ClientToken clientToken = (ClientToken) Authorization.fromString(
            base64EncodedClientTokenFromFixture("client_token_with_authorization_fingerprint_options.json"));
    when(mBraintreeFragment.getAuthorization()).thenReturn(clientToken);
    writeMockConfiguration(RuntimeEnvironment.application, clientToken.getConfigUrl(),
            clientToken.getAuthorizationFingerprint(), stringFromFixture("configuration/configuration.json"),
            System.currentTimeMillis());

    ConfigurationManager.getConfiguration(mBraintreeFragment, new ConfigurationListener() {
        @Override
        public void onConfigurationFetched(Configuration configuration) {
            assertEquals(stringFromFixture("configuration/configuration.json"), configuration.toJson());
            mCountDownLatch.countDown();
        }
    }, new BraintreeResponseListener<Exception>() {
        @Override
        public void onResponse(Exception e) {
            fail(e.getMessage());
        }
    });

    mCountDownLatch.await();
}
 
Example #6
Source File: MainActivity.java    From braintree-android-drop-in with MIT License 6 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();

    if (mPurchased) {
        mPurchased = false;
        clearNonce();

        try {
            if (ClientToken.fromString(mAuthorization) instanceof ClientToken) {
                DropInResult.fetchDropInResult(this, mAuthorization, this);
            } else {
                mAddPaymentMethodButton.setVisibility(VISIBLE);
            }
        } catch (InvalidArgumentException e) {
            mAddPaymentMethodButton.setVisibility(VISIBLE);
        }
    }
}
 
Example #7
Source File: ThreeDSecureVerificationTest.java    From braintree_android with MIT License 6 votes vote down vote up
private BraintreeFragment getFragment(String authorization, String configuration) {
    try {
        Authorization auth = Authorization.fromString(authorization);
        writeMockConfiguration(getTargetContext(), auth.getConfigUrl(), auth.getBearer(), configuration);

        BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, authorization);

        while (!fragment.isAdded()) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException ignored) {}
        }

        return fragment;
    } catch (InvalidArgumentException e) {
        fail(e.getMessage());
        return new BraintreeFragment();
    }
}
 
Example #8
Source File: DropInResultUnitTest.java    From braintree-android-drop-in with MIT License 6 votes vote down vote up
@Test
public void fetchDropInResult_clearsListenersWhenErrorIsPosted()
        throws InvalidArgumentException, InterruptedException {
    BraintreeFragment fragment = setupFragment(new BraintreeUnitTestHttpClient()
            .configuration(new TestConfigurationBuilder().build())
            .errorResponse(BraintreeUnitTestHttpClient.GET_PAYMENT_METHODS, 404,
                    "No payment methods found"));
    DropInResult.DropInResultListener listener = new DropInResult.DropInResultListener() {
        @Override
        public void onError(Exception exception) {
            assertEquals("No payment methods found", exception.getMessage());
            mCountDownLatch.countDown();
        }

        @Override
        public void onResult(DropInResult result) {
            fail("onResult called");
        }
    };

    DropInResult.fetchDropInResult(mActivity, base64EncodedClientTokenFromFixture("client_token.json"), listener);

    mCountDownLatch.await();
    assertEquals(0, fragment.getListeners().size());
}
 
Example #9
Source File: DropInResultUnitTest.java    From braintree-android-drop-in with MIT License 6 votes vote down vote up
@Test
public void fetchDropInResult_callsListenerWithNullResultWhenThereAreNoPaymentMethods()
        throws InvalidArgumentException, InterruptedException {
    setupFragment(new BraintreeUnitTestHttpClient()
            .configuration(new TestConfigurationBuilder().build())
            .successResponse(BraintreeUnitTestHttpClient.GET_PAYMENT_METHODS,
                    stringFromFixture("responses/get_payment_methods_empty_response.json")));
    DropInResult.DropInResultListener listener = new DropInResult.DropInResultListener() {
        @Override
        public void onError(Exception exception) {
            fail("onError called");
        }

        @Override
        public void onResult(DropInResult result) {
            assertNull(result.getPaymentMethodType());
            assertNull(result.getPaymentMethodNonce());
            mCountDownLatch.countDown();
        }
    };

    DropInResult.fetchDropInResult(mActivity, base64EncodedClientTokenFromFixture("client_token.json"), listener);

    mCountDownLatch.await();
}
 
Example #10
Source File: DropInResultUnitTest.java    From braintree-android-drop-in with MIT License 6 votes vote down vote up
@Test
public void fetchDropInResult_clearsListenersWhenResultIsReturned()
        throws InvalidArgumentException, InterruptedException {
    BraintreeFragment fragment = setupFragment(new BraintreeUnitTestHttpClient()
            .configuration(new TestConfigurationBuilder().build())
            .successResponse(BraintreeUnitTestHttpClient.GET_PAYMENT_METHODS,
                    stringFromFixture("responses/get_payment_methods_two_cards_response.json")));
    DropInResult.DropInResultListener listener = new DropInResult.DropInResultListener() {
        @Override
        public void onError(Exception exception) {
            fail("onError called");
        }

        @Override
        public void onResult(DropInResult result) {
            assertEquals(PaymentMethodType.VISA, result.getPaymentMethodType());
            mCountDownLatch.countDown();
        }
    };

    DropInResult.fetchDropInResult(mActivity, base64EncodedClientTokenFromFixture("client_token.json"), listener);

    mCountDownLatch.await();
    List<BraintreeListener> listeners = fragment.getListeners();
    assertEquals(0, listeners.size());
}
 
Example #11
Source File: VenmoUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void performAppSwitch_whenProfileIdIsSpecified_appSwitchesWithProfileIdAndAccessToken() throws InvalidArgumentException, JSONException {
    Configuration configuration = getConfigurationFromFixture();

    Authorization clientToken = Authorization.fromString(stringFromFixture("base_64_client_token.txt"));
    disableSignatureVerification();

    BraintreeFragment fragment = new MockFragmentBuilder()
            .context(VenmoInstalledContextFactory.venmoInstalledContext(true, RuntimeEnvironment.application))
            .authorization(clientToken)
            .configuration(configuration)
            .build();

    when(fragment.getSessionId()).thenReturn("a-session-id");
    when(fragment.getIntegrationType()).thenReturn("custom");

    Venmo.authorizeAccount(fragment, false, "second-pwv-profile-id");

    ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
    verify(fragment).startActivityForResult(captor.capture(), eq(BraintreeRequestCodes.VENMO));
    assertEquals("com.venmo/com.venmo.controller.SetupMerchantActivity",
            captor.getValue().getComponent().flattenToString());
    Bundle extras = captor.getValue().getExtras();
    assertEquals("second-pwv-profile-id", extras.getString(Venmo.EXTRA_MERCHANT_ID));
    assertEquals("access-token", extras.getString(Venmo.EXTRA_ACCESS_TOKEN));
}
 
Example #12
Source File: BraintreeFragmentUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void removeListener_noErrorCallbacksReceived() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mAppCompatActivity, TOKENIZATION_KEY);
    BraintreeErrorListener listener = new BraintreeErrorListener() {
        @Override
        public void onError(Exception error) {
            fail("Listener was called");
        }
    };

    fragment.addListener(listener);
    fragment.removeListener(listener);

    fragment.postCallback(new Exception());
    fragment.postCallback(new ErrorWithResponse(400, ""));
}
 
Example #13
Source File: PaymentMethodUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void deletePaymentMethodNonce_throwsAnError()
        throws InvalidArgumentException {
    Authorization authorization = Authorization
            .fromString(base64EncodedClientTokenFromFixture("client_token.json"));
    BraintreeFragment fragment = new MockFragmentBuilder()
            .authorization(authorization)
            .graphQLErrorResponse(new UnexpectedException("Error"))
            .build();

    PaymentMethod.deletePaymentMethod(fragment, mCardNonce);

    ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(Exception.class);
    verify(fragment).postCallback(captor.capture());
    PaymentMethodDeleteException paymentMethodDeleteException = (PaymentMethodDeleteException)captor.getValue();
    PaymentMethodNonce paymentMethodNonce = paymentMethodDeleteException.getPaymentMethodNonce();
    assertEquals(mCardNonce, paymentMethodNonce);
}
 
Example #14
Source File: VenmoUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void onActivityResult_performsVaultRequestIfRequestPersisted()
        throws InvalidArgumentException, NoSuchAlgorithmException {
    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")
            .build();

    Venmo.authorizeAccount(fragment, true);

    mockStatic(TokenizationClient.class);
    Venmo.onActivityResult(fragment, AppCompatActivity.RESULT_OK, new Intent());

    verifyStatic();
    TokenizationClient.tokenize(eq(fragment), any(VenmoAccountBuilder.class), any(PaymentMethodNonceCallback.class));
}
 
Example #15
Source File: ThreeDSecure.java    From braintree_android with MIT License 6 votes vote down vote up
/**
 * @deprecated Use {{@link #performVerification(BraintreeFragment, ThreeDSecureRequest)}} for 3DS 2.0.
 *
 * Verification is associated with a transaction amount and your merchant account. To specify a
 * different merchant account (or, in turn, currency), you will need to specify the merchant
 * account id when <a href="https://developers.braintreepayments.com/android/sdk/overview/generate-client-token">
 * generating a client token</a>
 * <p>
 * During lookup the original payment method nonce is consumed and a new one is returned,
 * which points to the original payment method, as well as the 3D Secure verification.
 * Transactions created with this nonce will be 3D Secure, and benefit from the appropriate
 * liability shift if authentication is successful or fail with a 3D Secure failure.
 *
 * @param fragment    the {@link BraintreeFragment} backing the http request. This fragment will
 *                    also be responsible for handling callbacks to it's listeners
 * @param cardBuilder The cardBuilder created from raw details. Will be tokenized before
 *                    the 3D Secure verification if performed.
 * @param request     the {@link ThreeDSecureRequest} with information used for authentication.
 *                    Note that the nonce will be replaced with the nonce generated from the
 *                    cardBuilder.
 */
@Deprecated
public static void performVerification(final BraintreeFragment fragment,
                                       final CardBuilder cardBuilder,
                                       final ThreeDSecureRequest request) {
    if (request.getAmount() == null) {
        fragment.postCallback(new InvalidArgumentException("The ThreeDSecureRequest amount cannot be null"));
        return;
    }

    TokenizationClient.tokenize(fragment, cardBuilder, new PaymentMethodNonceCallback() {
        @Override
        public void success(PaymentMethodNonce paymentMethodNonce) {
            request.nonce(paymentMethodNonce.getNonce());

            performVerification(fragment, request);
        }

        @Override
        public void failure(Exception exception) {
            fragment.postCallback(exception);
        }
    });
}
 
Example #16
Source File: VenmoUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void performAppSwitch_persistsIfVaultTrue() 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)
            .build();

    Venmo.authorizeAccount(fragment, true);

    SharedPreferences prefs = SharedPreferencesHelper.getSharedPreferences(fragment.getApplicationContext());
    assertTrue(prefs.getBoolean("com.braintreepayments.api.Venmo.VAULT_VENMO_KEY", false));
}
 
Example #17
Source File: VenmoUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void performAppSwitch_persistsIfVaultFalse() 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)
            .build();

    Venmo.authorizeAccount(fragment, false);

    SharedPreferences prefs = SharedPreferencesHelper.getSharedPreferences(fragment.getApplicationContext());
    assertFalse(prefs.getBoolean("com.braintreepayments.api.Venmo.VAULT_VENMO_KEY", true));
}
 
Example #18
Source File: BraintreeFragmentUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void postCallback_ErrorWithResponseIsPostedToListeners() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mAppCompatActivity, TOKENIZATION_KEY);
    fragment.addListener(new BraintreeErrorListener() {
        @Override
        public void onError(Exception error) {
            assertTrue(error instanceof ErrorWithResponse);
            assertEquals(422, ((ErrorWithResponse) error).getStatusCode());
            mCalled.set(true);
        }
    });

    fragment.postCallback(new ErrorWithResponse(422, ""));

    assertTrue(mCalled.get());
}
 
Example #19
Source File: BraintreeHttpClientTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test(timeout = 1000)
public void get_includesAuthorizationFingerprintWhenPresent()
        throws InterruptedException, InvalidArgumentException {
    BraintreeHttpClient httpClient = new BraintreeHttpClient(Authorization
            .fromString(base64EncodedClientTokenFromFixture("client_token.json"))) {
        @Override
        protected HttpURLConnection init(String url) throws IOException {
            assertTrue(url.contains("authorization_fingerprint"));
            mCountDownLatch.countDown();

            return super.init(url);
        }
    };

    httpClient.get("/", null);

    mCountDownLatch.await();
}
 
Example #20
Source File: BraintreeFragmentUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void flushAnalyticsEvents_fallsBackToSenderIfStartingServiceThrows()
        throws JSONException, InvalidArgumentException {
    mockStatic(AnalyticsSender.class);
    String configuration = new TestConfigurationBuilder().withAnalytics().build();
    mockConfigurationManager(Configuration.fromJson(configuration));

    Robolectric.getForegroundThreadScheduler().pause();

    Context context = spy(RuntimeEnvironment.application);
    doThrow(new RuntimeException()).when(context).startService(any(Intent.class));
    when(mAppCompatActivity.getApplicationContext()).thenReturn(context);

    BraintreeFragment fragment = BraintreeFragment.newInstance(mAppCompatActivity, TOKENIZATION_KEY);

    Robolectric.getForegroundThreadScheduler().unPause();
    Robolectric.getForegroundThreadScheduler().advanceToLastPostedRunnable();

    fragment.onStop();

    verifyStatic();
    AnalyticsSender.send(eq(context), any(Authorization.class), any(BraintreeHttpClient.class),
            eq(Configuration.fromJson(configuration).getAnalytics().getUrl()), eq(false));
}
 
Example #21
Source File: BraintreeFragmentUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void postCancelCallback_postsRequestCodeToListener() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mAppCompatActivity, TOKENIZATION_KEY);
    final AtomicBoolean wasCalled = new AtomicBoolean(false);
    fragment.addListener(new BraintreeCancelListener() {
        @Override
        public void onCancel(int requestCode) {
            assertEquals(42, requestCode);
            wasCalled.set(true);
        }
    });

    fragment.postCancelCallback(42);

    assertTrue(wasCalled.get());
}
 
Example #22
Source File: PayPalUATUnitTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test
public void fromString_whenNoBraintreeMerchantID_throwsException() throws Exception {
    exceptionRule.expect(InvalidArgumentException.class);
    exceptionRule.expectMessage("PayPal UAT invalid: Missing Braintree merchant account ID.");

    PayPalUAT.fromString(encodeUAT("{\"iss\":\"paypal-url.com\", \"external_id\":[\"Faketree:my-merchant-id\"]}"));
}
 
Example #23
Source File: BraintreeHttpClientTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test(timeout = 1000)
public void sendsUserAgent() throws IOException, InvalidArgumentException {
    BraintreeHttpClient httpClient = new BraintreeHttpClient(
            TokenizationKey.fromString(TOKENIZATION_KEY));

    HttpURLConnection connection = httpClient.init("http://example.com/");

    assertEquals("braintree/android/" + BuildConfig.VERSION_NAME,
            connection.getRequestProperty("User-Agent"));
}
 
Example #24
Source File: BraintreeGraphQLHttpClientTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test
public void sendsAuthorizationFingerprintAsAuthorization() throws IOException, InvalidArgumentException {
    String baseUrl = "http://example.com/graphql";
    ClientToken clientToken = (ClientToken) Authorization.fromString(base64EncodedClientTokenFromFixture("client_token.json"));
    BraintreeGraphQLHttpClient httpClient = new BraintreeGraphQLHttpClient(baseUrl, clientToken.getBearer());

    HttpURLConnection connection = httpClient.init(baseUrl);

    assertEquals("Bearer " + clientToken.getAuthorizationFingerprint(), connection.getRequestProperty("Authorization"));
}
 
Example #25
Source File: AuthorizationUnitTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test
public void parcelable_parcelsPayPalUATCorrectly() throws InvalidArgumentException {
    Authorization authorization = Authorization.fromString(stringFromFixture("base_64_paypal_uat.txt"));
    Parcel parcel = Parcel.obtain();
    authorization.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);

    PayPalUAT parceled = PayPalUAT.CREATOR.createFromParcel(parcel);

    assertEquals(authorization.toString(), parceled.toString());
    assertEquals(authorization.getBearer(), parceled.getBearer());
    assertEquals(authorization.getConfigUrl(), parceled.getConfigUrl());
    assertEquals(((PayPalUAT) authorization).getPayPalURL(), parceled.getPayPalURL());
}
 
Example #26
Source File: PayPalActivity.java    From braintree_android with MIT License 5 votes vote down vote up
@Override
protected void onAuthorizationFetched() {
    try {
        mBraintreeFragment = BraintreeFragment.newInstance(this, mAuthorization);
    } catch (InvalidArgumentException e) {
        onError(e);
    }

    enableButtons(true);
}
 
Example #27
Source File: VenmoUnitTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test
public void getLaunchIntent_containsCorrectVenmoExtras() throws JSONException, InvalidArgumentException {
    Configuration configuration = getConfigurationFromFixture();

    BraintreeFragment fragment = new MockFragmentBuilder()
            .authorization(Authorization.fromString(base64EncodedClientTokenFromFixture("client_token.json")))
            .configuration(configuration)
            .sessionId("session-id")
            .build();
    when(fragment.getIntegrationType()).thenReturn("custom");

    Intent intent = Venmo.getLaunchIntent(configuration.getPayWithVenmo(),
            configuration.getPayWithVenmo().getMerchantId(), fragment);

    assertEquals(new ComponentName("com.venmo", "com.venmo.controller.SetupMerchantActivity"),
            intent.getComponent());
    assertEquals("merchant-id", intent.getStringExtra(Venmo.EXTRA_MERCHANT_ID));
    assertEquals("access-token", intent.getStringExtra(Venmo.EXTRA_ACCESS_TOKEN));
    assertEquals("environment", intent.getStringExtra(Venmo.EXTRA_ENVIRONMENT));

    JSONObject braintreeData = new JSONObject(intent.getStringExtra(Venmo.EXTRA_BRAINTREE_DATA));
    JSONObject meta = braintreeData.getJSONObject("_meta");
    assertNotNull(meta);
    assertEquals("session-id", meta.getString("sessionId"));
    assertEquals("custom", meta.getString("integration"));
    assertEquals(BuildConfig.VERSION_NAME, meta.getString("version"));
    assertEquals("android", meta.getString("platform"));
}
 
Example #28
Source File: BraintreeFragmentUnitTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test
public void onBrowserSwitchResult_callsOnActivityResultForErrorResult() throws InvalidArgumentException {
    BraintreeFragment fragment = spy(BraintreeFragment.newInstance(mAppCompatActivity, TOKENIZATION_KEY));

    fragment.onBrowserSwitchResult(42, BrowserSwitchResult.ERROR, Uri.parse("http://example.com"));

    ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
    verify(fragment).onActivityResult(eq(42), eq(AppCompatActivity.RESULT_FIRST_USER), captor.capture());
    assertEquals("http://example.com", captor.getValue().getData().toString());
}
 
Example #29
Source File: BraintreeFragmentUnitTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test
public void removeListener_noCancelReceived() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mAppCompatActivity, TOKENIZATION_KEY);
    BraintreeCancelListener listener = new BraintreeCancelListener() {
        @Override
        public void onCancel(int requestCode) {
            fail("Listener was called");
        }
    };

    fragment.addListener(listener);
    fragment.removeListener(listener);

    fragment.postCancelCallback(42);
}
 
Example #30
Source File: BraintreeFragmentUnitTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test
public void addListener_flushesPaymentMethodNonceCreatedCallback() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mAppCompatActivity, TOKENIZATION_KEY);
    fragment.postCallback(new CardNonce());

    fragment.addListener(new PaymentMethodNonceCreatedListener() {
        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            mCalled.set(true);
        }
    });

    assertTrue(mCalled.get());
}