@Test public void authorizeAccount_postsExceptionWhenNotInstalled() { Configuration configuration = getConfigurationFromFixture(); BraintreeFragment fragment = new MockFragmentBuilder() .configuration(configuration) .build(); Venmo.authorizeAccount(fragment, false); ArgumentCaptor<AppSwitchNotAvailableException> captor = ArgumentCaptor.forClass(AppSwitchNotAvailableException.class); verify(fragment).postCallback(captor.capture()); assertEquals("Venmo is not installed", captor.getValue().getMessage()); }
@Override public void onConfigurationFetched(Configuration configuration) { fragment.sendAnalyticsEvent("pay-with-venmo.selected"); String venmoProfileId = profileId; if (TextUtils.isEmpty(venmoProfileId)) { venmoProfileId = configuration.getPayWithVenmo().getMerchantId(); } String exceptionMessage = ""; if (!configuration.getPayWithVenmo().isAccessTokenValid()) { exceptionMessage = "Venmo is not enabled"; } else if (!Venmo.isVenmoInstalled(fragment.getApplicationContext())) { exceptionMessage = "Venmo is not installed"; } if (!TextUtils.isEmpty(exceptionMessage)) { fragment.postCallback(new AppSwitchNotAvailableException(exceptionMessage)); fragment.sendAnalyticsEvent("pay-with-venmo.app-switch.failed"); } else { persistVenmoVaultOption(vault && fragment.getAuthorization() instanceof ClientToken, fragment.getApplicationContext()); fragment.startActivityForResult(getLaunchIntent(configuration.getPayWithVenmo(), venmoProfileId, fragment), BraintreeRequestCodes.VENMO); fragment.sendAnalyticsEvent("pay-with-venmo.app-switch.started"); } } });
@Test public void performAppSwitch_sendsAnalyticsEventWhenUnavailableAndPostException() { Configuration configuration = getConfigurationFromFixture(); BraintreeFragment fragment = new MockFragmentBuilder() .configuration(configuration) .build(); Venmo.authorizeAccount(fragment, false); ArgumentCaptor<AppSwitchNotAvailableException> captor = ArgumentCaptor.forClass(AppSwitchNotAvailableException.class); InOrder order = inOrder(fragment); order.verify(fragment).sendAnalyticsEvent("pay-with-venmo.selected"); order.verify(fragment).sendAnalyticsEvent("pay-with-venmo.app-switch.failed"); verify(fragment).postCallback(captor.capture()); assertEquals("Venmo is not installed", captor.getValue().getMessage()); }
@Test public void authorizeAccount_postsExceptionWhenNotEnabled() throws JSONException { Configuration configuration = new TestConfigurationBuilder().buildConfiguration(); BraintreeFragment fragment = new MockFragmentBuilder() .configuration(configuration) .build(); Venmo.authorizeAccount(fragment, false); ArgumentCaptor<AppSwitchNotAvailableException> captor = ArgumentCaptor.forClass(AppSwitchNotAvailableException.class); verify(fragment).postCallback(captor.capture()); assertEquals("Venmo is not enabled", captor.getValue().getMessage()); }