本文整理匯總了Java中org.robolectric.shadows.ShadowActivity.IntentForResult方法的典型用法代碼示例。如果您正苦於以下問題:Java ShadowActivity.IntentForResult方法的具體用法?Java ShadowActivity.IntentForResult怎麽用?Java ShadowActivity.IntentForResult使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.robolectric.shadows.ShadowActivity
的用法示例。
在下文中一共展示了ShadowActivity.IntentForResult方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: checkOpenActivity
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
private void checkOpenActivity(ActivityController controller, int viewId, HashMap<String, Integer> items)
{
Activity activity = (Activity)controller.get();
activity.findViewById(viewId).performClick();
assertTrue(activity.isFinishing() == false);
ShadowActivity.IntentForResult next = shadowOf(activity).getNextStartedActivityForResult();
ComponentName componentName = next.intent.getComponent();
String name = componentName.flattenToShortString();
assertEquals("protect.rentalcalc/.ItemizeActivity", name);
Bundle extras = next.intent.getExtras();
assertNotNull(extras);
assertTrue(extras.containsKey("title"));
assertTrue(extras.getInt("title") > 0);
assertTrue(extras.containsKey("description"));
assertTrue(extras.getInt("description") > 0);
assertTrue(extras.containsKey("items"));
assertEquals(items, extras.getSerializable("items"));
// As the next activity is started, this activity is paused
controller.pause();
}
示例2: testSignInButton_validatesFields
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@Test
public void testSignInButton_validatesFields() {
WelcomeBackPasswordPrompt welcomeBack = createActivity();
Button signIn = welcomeBack.findViewById(R.id.button_done);
signIn.performClick();
TextInputLayout passwordLayout =
welcomeBack.findViewById(R.id.password_layout);
assertEquals(
welcomeBack.getString(R.string.fui_required_field),
passwordLayout.getError().toString());
// should block and not start a new activity
ShadowActivity.IntentForResult nextIntent =
Shadows.shadowOf(welcomeBack).getNextStartedActivityForResult();
assertNull(nextIntent);
}
示例3: testTwitterLoginFlowStarts
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@Test
@Config(shadows = {AuthHelperShadow.class})
public void testTwitterLoginFlowStarts() {
List<String> providers = Arrays.asList(AuthUI.TWITTER_PROVIDER);
AuthMethodPickerActivity authMethodPickerActivity = createActivity(providers);
when(AuthHelperShadow.getCurrentUser().getProviders())
.thenReturn(Arrays.asList(TwitterAuthProvider.PROVIDER_ID));
when(AuthHelperShadow.getFirebaseAuth().signInWithCredential(any(AuthCredential.class)))
.thenReturn(new AutoCompleteTask<>(FakeAuthResult.INSTANCE, true, null));
Button twitterButton =
authMethodPickerActivity.findViewById(R.id.twitter_button);
assertNotNull(twitterButton);
twitterButton.performClick();
ShadowActivity.IntentForResult nextIntent =
Shadows.shadowOf(authMethodPickerActivity).getNextStartedActivityForResult();
assertTrue(nextIntent.intent.getComponent().getClassName().contains("com.twitter.sdk"));
}
示例4: launchFormEntryForSavedForm
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
private static void launchFormEntryForSavedForm(ShadowActivity homeActivityShadow,
Intent savedFormsIntent,
FormRecordListActivity savedFormsActivity) {
ShadowEnvironment.setExternalStorageState(Environment.MEDIA_MOUNTED);
ShadowActivity formRecordShadow = Shadows.shadowOf(savedFormsActivity);
homeActivityShadow.receiveResult(savedFormsIntent,
formRecordShadow.getResultCode(),
formRecordShadow.getResultIntent());
ShadowActivity.IntentForResult formEntryIntent =
homeActivityShadow.getNextStartedActivityForResult();
Robolectric.buildActivity(FormEntryActivity.class)
.withIntent(formEntryIntent.intent)
.create().start().resume().get();
Robolectric.flushBackgroundThreadScheduler();
Robolectric.flushForegroundThreadScheduler();
assertNotNull(FormEntryActivity.mFormController);
}
示例5: captureBarcodeWithResult
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
/**
* Initiate and complete a barcode capture, either in success
* or in failure
*/
private void captureBarcodeWithResult(final Activity activity, final int buttonId, final boolean success) throws IOException
{
// Start image capture
final Button captureButton = (Button) activity.findViewById(buttonId);
captureButton.performClick();
ShadowActivity.IntentForResult intentForResult = shadowOf(activity).peekNextStartedActivityForResult();
assertNotNull(intentForResult);
Intent intent = intentForResult.intent;
assertNotNull(intent);
String action = intent.getAction();
assertNotNull(action);
assertEquals(Intents.Scan.ACTION, action);
Bundle bundle = intent.getExtras();
assertNotNull(bundle);
Intent resultIntent = new Intent(intent);
Bundle resultBuddle = new Bundle();
resultBuddle.putString(Intents.Scan.RESULT, BARCODE_DATA);
resultBuddle.putString(Intents.Scan.RESULT_FORMAT, BARCODE_TYPE);
resultIntent.putExtras(resultBuddle);
// Respond to image capture, success
shadowOf(activity).receiveResult(
intent,
success ? Activity.RESULT_OK : Activity.RESULT_CANCELED,
resultIntent);
}
示例6: shouldAuthenticateUsingWebView
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
@Test
public void shouldAuthenticateUsingWebView() throws Exception {
verifyNoMoreInteractions(customTabsController);
AuthenticationActivity.authenticateUsingWebView(callerActivity, uri, 123, "facebook", true);
verify(callerActivity).startActivityForResult(intentCaptor.capture(), eq(123));
createActivity(intentCaptor.getValue());
activityController.create().start().resume();
final ShadowActivity.IntentForResult webViewIntent = activityShadow.getNextStartedActivityForResult();
Bundle extras = webViewIntent.intent.getExtras();
assertThat(extras.containsKey(WebAuthActivity.CONNECTION_NAME_EXTRA), is(true));
assertThat(extras.getString(WebAuthActivity.CONNECTION_NAME_EXTRA), is("facebook"));
assertThat(extras.containsKey(WebAuthActivity.FULLSCREEN_EXTRA), is(true));
assertThat(extras.getBoolean(WebAuthActivity.FULLSCREEN_EXTRA), is(true));
assertThat(webViewIntent.intent, hasComponent(WebAuthActivity.class.getName()));
assertThat(webViewIntent.intent, hasData(uri));
assertThat(webViewIntent.requestCode, is(greaterThan(0)));
assertThat(activity.getDeliveredIntent(), is(nullValue()));
activityController.pause();
//WebViewActivity is shown
Intent authenticationResultIntent = new Intent();
authenticationResultIntent.setData(resultUri);
activityShadow.receiveResult(webViewIntent.intent, Activity.RESULT_OK, authenticationResultIntent);
assertThat(activity.getDeliveredIntent(), is(notNullValue()));
assertThat(activity.getDeliveredIntent().getData(), is(resultUri));
assertThat(activity.isFinishing(), is(true));
activityController.destroy();
}
示例7: shouldAuthenticateAfterRecreatedUsingWebView
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
@Test
public void shouldAuthenticateAfterRecreatedUsingWebView() throws Exception {
verifyNoMoreInteractions(customTabsController);
AuthenticationActivity.authenticateUsingWebView(callerActivity, uri, 123, "facebook", true);
verify(callerActivity).startActivityForResult(intentCaptor.capture(), eq(123));
createActivity(intentCaptor.getValue());
activityController.create().start().resume();
final ShadowActivity.IntentForResult webViewIntent = activityShadow.getNextStartedActivityForResult();
Bundle extras = webViewIntent.intent.getExtras();
assertThat(extras.containsKey(WebAuthActivity.CONNECTION_NAME_EXTRA), is(true));
assertThat(extras.getString(WebAuthActivity.CONNECTION_NAME_EXTRA), is("facebook"));
assertThat(extras.containsKey(WebAuthActivity.FULLSCREEN_EXTRA), is(true));
assertThat(extras.getBoolean(WebAuthActivity.FULLSCREEN_EXTRA), is(true));
assertThat(webViewIntent.intent, hasComponent(WebAuthActivity.class.getName()));
assertThat(webViewIntent.intent, hasData(uri));
assertThat(webViewIntent.requestCode, is(greaterThan(0)));
assertThat(activity.getDeliveredIntent(), is(nullValue()));
//WebViewActivity is shown
//Memory needed. Let's kill the activity
Intent authenticationResultIntent = new Intent();
authenticationResultIntent.setData(resultUri);
recreateAndCallActivityResult(123, authenticationResultIntent);
assertThat(activity.getDeliveredIntent(), is(notNullValue()));
assertThat(activity.getDeliveredIntent().getData(), is(resultUri));
assertThat(activity.isFinishing(), is(true));
activityController.destroy();
}
示例8: shouldCancelAuthenticationUsingWebView
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
@Test
public void shouldCancelAuthenticationUsingWebView() throws Exception {
verifyNoMoreInteractions(customTabsController);
AuthenticationActivity.authenticateUsingWebView(callerActivity, uri, 123, "facebook", true);
verify(callerActivity).startActivityForResult(intentCaptor.capture(), eq(123));
createActivity(intentCaptor.getValue());
activityController.create().start().resume();
final ShadowActivity.IntentForResult webViewIntent = activityShadow.getNextStartedActivityForResult();
Bundle extras = webViewIntent.intent.getExtras();
assertThat(extras.containsKey(WebAuthActivity.CONNECTION_NAME_EXTRA), is(true));
assertThat(extras.getString(WebAuthActivity.CONNECTION_NAME_EXTRA), is("facebook"));
assertThat(extras.containsKey(WebAuthActivity.FULLSCREEN_EXTRA), is(true));
assertThat(extras.getBoolean(WebAuthActivity.FULLSCREEN_EXTRA), is(true));
assertThat(webViewIntent.intent, hasComponent(WebAuthActivity.class.getName()));
assertThat(webViewIntent.intent, hasData(uri));
assertThat(webViewIntent.requestCode, is(greaterThan(0)));
assertThat(activity.getDeliveredIntent(), is(nullValue()));
activityController.pause().stop();
//WebViewActivity is shown
activityShadow.receiveResult(webViewIntent.intent, Activity.RESULT_CANCELED, null);
assertThat(activity.getDeliveredIntent(), is(nullValue()));
assertThat(activity.isFinishing(), is(true));
activityController.destroy();
}
示例9: testSelectPicVidIntent
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@Test
public void testSelectPicVidIntent(){
chatDispatcher.selectPicVidIntent();
ShadowActivity shadowActivity = Shadows.shadowOf(chatActivity);
ShadowActivity.IntentForResult intent = shadowActivity.getNextStartedActivityForResult();
assertTrue( intent.getClass().getName().equals(ChatActivity.class.getName()));
}
示例10: testSelectFileIntent
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@Test
public void testSelectFileIntent(){
chatDispatcher.selectFileIntent();
ShadowActivity shadowActivity = Shadows.shadowOf(chatActivity);
ShadowActivity.IntentForResult intent = shadowActivity.getNextStartedActivityForResult();
assertTrue(intent.getClass().getName().equals(ChatActivity.class.getName()));
}
示例11: testTakePictureIntent
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@Test
public void testTakePictureIntent(){
chatDispatcher.takePictureIntent();
ShadowActivity shadowActivity = Shadows.shadowOf(chatActivity);
ShadowActivity.IntentForResult intent = shadowActivity.getNextStartedActivityForResult();
assertTrue( intent.getClass().getName().equals(ChatActivity.class.getName()));
}
示例12: testTakeVideoIntent
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@Test
public void testTakeVideoIntent(){
chatDispatcher.takeVideoIntent();
ShadowActivity shadowActivity = Shadows.shadowOf(chatActivity);
ShadowActivity.IntentForResult intent = shadowActivity.getNextStartedActivityForResult();
assertTrue( intent.getClass().getName().equals(ChatActivity.class.getName()));
}
示例13: onStartActivityForResult_shouldStartAnActivityWithRelevantRequestCodeAndExtras
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@Test
public void onStartActivityForResult_shouldStartAnActivityWithRelevantRequestCodeAndExtras() throws Exception {
initializeSubjectWithMockViewController();
final Bundle expectedExtras = new Bundle();
expectedExtras.putString("hello", "goodbye");
subject.onStartActivityForResult(MoPubBrowser.class, 100, expectedExtras);
final ShadowActivity.IntentForResult intentForResult = shadowOf(subject).getNextStartedActivityForResult();
assertThat(intentForResult.intent.getComponent().getClassName()).isEqualTo("com.mopub.common.MoPubBrowser");
assertThat(intentForResult.intent.getExtras()).isEqualTo(expectedExtras);
assertThat(intentForResult.requestCode).isEqualTo(100);
}
示例14: onStartActivityForResult_withNullClass_shouldNotStartAnActivity
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@Test
public void onStartActivityForResult_withNullClass_shouldNotStartAnActivity() throws Exception {
initializeSubjectWithMockViewController();
subject.onStartActivityForResult(null, 100, new Bundle());
final ShadowActivity.IntentForResult intentForResult = shadowOf(subject).getNextStartedActivityForResult();
assertThat(intentForResult).isNull();
}
示例15: testEmailLoginFlow
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@Test
public void testEmailLoginFlow() {
List<String> providers = Arrays.asList(AuthUI.EMAIL_PROVIDER);
AuthMethodPickerActivity authMethodPickerActivity = createActivity(providers);
Button emailButton = authMethodPickerActivity.findViewById(R.id.email_button);
emailButton.performClick();
ShadowActivity.IntentForResult nextIntent =
Shadows.shadowOf(authMethodPickerActivity).getNextStartedActivityForResult();
assertEquals(
EmailActivity.class.getName(),
nextIntent.intent.getComponent().getClassName());
}