@Test public void shouldSupportGetStartedActivitiesForResult() throws Exception { activity = Robolectric.setupActivity(DialogLifeCycleActivity.class); ShadowActivity shadowActivity = shadowOf(activity); Intent intent = new Intent().setClass(activity, DialogLifeCycleActivity.class); activity.startActivityForResult(intent, 142); ShadowActivity.IntentForResult intentForResult = shadowActivity.getNextStartedActivityForResult(); assertThat(intentForResult).isNotNull(); assertThat(shadowActivity.getNextStartedActivityForResult()).isNull(); assertThat(intentForResult.intent).isNotNull(); assertThat(intentForResult.intent).isSameAs(intent); assertThat(intentForResult.requestCode).isEqualTo(142); }
@Test public void shouldUseAnimationOverride() { Activity activity = Robolectric.setupActivity(Activity.class); Intent intent = new Intent(activity, OptionsMenuActivity.class); Bundle animationBundle = ActivityOptions.makeCustomAnimation(activity, R.anim.test_anim_1, R.anim.test_anim_1).toBundle(); activity.startActivity(intent, animationBundle); assertThat(shadowOf(activity).getNextStartedActivityForResult().options).isSameAs(animationBundle); }
@Test public void canStartActivityFromFragment() { final Activity activity = Robolectric.setupActivity(Activity.class); Intent intent = new Intent(Intent.ACTION_VIEW); activity.startActivityFromFragment(new Fragment(), intent, 4); ShadowActivity.IntentForResult intentForResult = shadowOf(activity).getNextStartedActivityForResult(); assertThat(intentForResult.intent).isSameAs(intent); assertThat(intentForResult.requestCode).isEqualTo(4); }
@Test public void canStartActivityFromFragment_withBundle() { final Activity activity = buildActivity(Activity.class).create().get(); Bundle options = new Bundle(); Intent intent = new Intent(Intent.ACTION_VIEW); activity.startActivityFromFragment(new Fragment(), intent, 5, options); ShadowActivity.IntentForResult intentForResult = shadowOf(activity).getNextStartedActivityForResult(); assertThat(intentForResult.intent).isSameAs(intent); assertThat(intentForResult.options).isSameAs(options); assertThat(intentForResult.requestCode).isEqualTo(5); }
@Test public void onClickAddSourceView_withoutPaymentSessoin_launchesAddSourceActivityWithoutLog() { Customer customer = Customer.fromString(CustomerSessionTest.FIRST_TEST_CUSTOMER_OBJECT); when(mCustomerSessionProxy.getCachedCustomer()).thenReturn(customer); mPaymentMethodsActivity.initializeCustomerSourceData(); mAddCardView.performClick(); ShadowActivity.IntentForResult intentForResult = mShadowActivity.getNextStartedActivityForResult(); assertNotNull(intentForResult); assertEquals(AddSourceActivity.class.getName(), intentForResult.intent.getComponent().getClassName()); assertFalse(intentForResult.intent.hasExtra(EXTRA_PAYMENT_SESSION_ACTIVE)); }
@Test public void onClickAddSourceView_whenStartedFromPaymentSession_launchesActivityWithLog() { Intent intent = PaymentMethodsActivity .newIntent(ApplicationProvider.getApplicationContext()) .putExtra(EXTRA_PROXY_DELAY, true) .putExtra(EXTRA_PAYMENT_SESSION_ACTIVE, true); mPaymentMethodsActivity = createActivity(intent); mPaymentMethodsActivity.setCustomerSessionProxy(mCustomerSessionProxy); mShadowActivity = Shadows.shadowOf(mPaymentMethodsActivity); mAddCardView = mPaymentMethodsActivity.findViewById(R.id.payment_methods_add_payment_container); Customer customer = Customer.fromString(CustomerSessionTest.FIRST_TEST_CUSTOMER_OBJECT); when(mCustomerSessionProxy.getCachedCustomer()).thenReturn(customer); mPaymentMethodsActivity.initializeCustomerSourceData(); mAddCardView.performClick(); ShadowActivity.IntentForResult intentForResult = mShadowActivity.getNextStartedActivityForResult(); assertNotNull(intentForResult); assertEquals(AddSourceActivity.class.getName(), intentForResult.intent.getComponent().getClassName()); assertTrue(intentForResult.intent.hasExtra(EXTRA_PAYMENT_SESSION_ACTIVE)); }
captureButton.performClick(); ShadowActivity.IntentForResult intentForResult = shadowOf(activity).getNextStartedActivityForResult(); assertNotNull(intentForResult);
@Test public void selectPaymentMethod_launchesPaymentMethodsActivityWithLog() { CustomerEphemeralKey firstKey = getCustomerEphemeralKey(FIRST_SAMPLE_KEY_RAW); assertNotNull(firstKey); mEphemeralKeyProvider.setNextRawEphemeralKey(FIRST_SAMPLE_KEY_RAW); CustomerSession.initCustomerSession( mEphemeralKeyProvider, mStripeApiProxy, null); PaymentSession.PaymentSessionListener mockListener = mock(PaymentSession.PaymentSessionListener.class); PaymentSession paymentSession = new PaymentSession(mActivity); paymentSession.init(mockListener, new PaymentSessionConfig.Builder().build()); paymentSession.presentPaymentMethodSelection(); ShadowActivity.IntentForResult intentForResult = Shadows.shadowOf(mActivity).getNextStartedActivityForResult(); assertNotNull(intentForResult); assertEquals(PaymentMethodsActivity.class.getName(), intentForResult.intent.getComponent().getClassName()); assertTrue(intentForResult.intent.hasExtra(EXTRA_PAYMENT_SESSION_ACTIVE)); }
ShadowActivity.IntentForResult intentForResult = shadowOf(activity).getNextStartedActivityForResult(); assertNotNull(intentForResult);
ShadowActivity.IntentForResult intentForResult = shadowOf(activity).getNextStartedActivityForResult(); assertNotNull(intentForResult);