Java Code Examples for org.robolectric.shadows.ShadowActivity#IntentForResult
The following examples show how to use
org.robolectric.shadows.ShadowActivity#IntentForResult .
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: WelcomeBackPasswordPromptTest.java From FirebaseUI-Android with Apache License 2.0 | 6 votes |
@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_error_invalid_password), passwordLayout.getError().toString()); // should block and not start a new activity ShadowActivity.IntentForResult nextIntent = Shadows.shadowOf(welcomeBack).getNextStartedActivityForResult(); assertNull(nextIntent); }
Example 2
Source File: AuthMethodPickerActivityTest.java From FirebaseUI-Android with Apache License 2.0 | 6 votes |
@Test public void testCustomAuthMethodPickerLayout() { List<String> providers = Arrays.asList(EmailAuthProvider.PROVIDER_ID); AuthMethodPickerLayout customLayout = new AuthMethodPickerLayout .Builder(R.layout.fui_provider_button_email) .setEmailButtonId(R.id.email_button) .build(); AuthMethodPickerActivity authMethodPickerActivity = createActivityWithCustomLayout(providers, customLayout); Button emailButton = authMethodPickerActivity.findViewById(R.id.email_button); emailButton.performClick(); //Expected result -> Directing users to EmailActivity ShadowActivity.IntentForResult nextIntent = Shadows.shadowOf(authMethodPickerActivity).getNextStartedActivityForResult(); assertEquals( EmailActivity.class.getName(), nextIntent.intent.getComponent().getClassName()); }
Example 3
Source File: AuthMethodPickerActivityTest.java From FirebaseUI-Android with Apache License 2.0 | 6 votes |
@Test public void testCustomAuthMethodPickerLayoutWithEmailLink() { List<String> providers = Arrays.asList(EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD); AuthMethodPickerLayout customLayout = new AuthMethodPickerLayout .Builder(R.layout.fui_provider_button_email) .setEmailButtonId(R.id.email_button) .build(); AuthMethodPickerActivity authMethodPickerActivity = createActivityWithCustomLayout(providers, customLayout); Button emailButton = authMethodPickerActivity.findViewById(R.id.email_button); emailButton.performClick(); //Expected result -> Directing users to EmailActivity ShadowActivity.IntentForResult nextIntent = Shadows.shadowOf(authMethodPickerActivity).getNextStartedActivityForResult(); assertEquals( EmailActivity.class.getName(), nextIntent.intent.getComponent().getClassName()); }
Example 4
Source File: FormRecordListActivityTest.java From commcare-android with Apache License 2.0 | 6 votes |
private static void launchFormEntryForSavedForm(ShadowActivity homeActivityShadow, Intent savedFormsIntent, FormRecordListActivity savedFormsActivity) { ShadowActivity formRecordShadow = Shadows.shadowOf(savedFormsActivity); homeActivityShadow.receiveResult(savedFormsIntent, formRecordShadow.getResultCode(), formRecordShadow.getResultIntent()); ShadowActivity.IntentForResult formEntryIntent = homeActivityShadow.getNextStartedActivityForResult(); Robolectric.buildActivity(FormEntryActivity.class, formEntryIntent.intent) .create().start().resume().get(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); assertNotNull(FormEntryActivity.mFormController); }
Example 5
Source File: DropInActivityUnitTest.java From braintree-android-drop-in with MIT License | 5 votes |
@Test public void onVaultEditButtonClick_launchesVaultManagerActivity() { setup(mock(BraintreeFragment.class)); mActivity.onVaultEditButtonClick(null); ShadowActivity.IntentForResult intent = mShadowActivity.getNextStartedActivityForResult(); assertEquals(2, intent.requestCode); assertEquals(mActivity.mDropInRequest, intent.intent.getParcelableExtra(EXTRA_CHECKOUT_REQUEST)); assertEquals(mActivity.mBraintreeFragment.getCachedPaymentMethodNonces(), intent.intent.getParcelableArrayListExtra(EXTRA_PAYMENT_METHOD_NONCES)); }
Example 6
Source File: AuthenticationActivityTest.java From Auth0.Android with MIT License | 5 votes |
@Test public void shouldAuthenticateUsingWebView() { 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 = shadowOf(activity).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); shadowOf(activity).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(); }
Example 7
Source File: AuthenticationActivityTest.java From Auth0.Android with MIT License | 5 votes |
@Test public void shouldAuthenticateAfterRecreatedUsingWebView() { 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 = shadowOf(activity).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(); }
Example 8
Source File: AuthenticationActivityTest.java From Auth0.Android with MIT License | 5 votes |
@Test public void shouldCancelAuthenticationUsingWebView() { 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 = shadowOf(activity).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 shadowOf(activity).receiveResult(webViewIntent.intent, Activity.RESULT_CANCELED, null); activityController.resume(); assertThat(activity.getDeliveredIntent(), is(notNullValue())); assertThat(activity.getDeliveredIntent().getData(), is(nullValue())); assertThat(activity.isFinishing(), is(true)); activityController.destroy(); }
Example 9
Source File: AuthMethodPickerActivityTest.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
@Test public void testEmailLoginFlow() { List<String> providers = Arrays.asList(EmailAuthProvider.PROVIDER_ID); 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()); }
Example 10
Source File: AuthMethodPickerActivityTest.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
@Test public void testPhoneLoginFlow() { List<String> providers = Arrays.asList(PhoneAuthProvider.PROVIDER_ID); AuthMethodPickerActivity authMethodPickerActivity = createActivity(providers); Button phoneButton = authMethodPickerActivity.findViewById(R.id.phone_button); phoneButton.performClick(); ShadowActivity.IntentForResult nextIntent = Shadows.shadowOf(authMethodPickerActivity).getNextStartedActivityForResult(); assertEquals( PhoneActivity.class.getName(), nextIntent.intent.getComponent().getClassName()); }
Example 11
Source File: BaseFragmentActivityTest.java From edx-app-android with Apache License 2.0 | 5 votes |
/** * Generic method for asserting next started activity along with * the custom transition animation override * * @param currentActivity The current activity * @param nextActivityClass The class of the newly started activity * @param requestCode The request code */ protected Intent assertNextStartedActivityForResult( BaseFragmentActivity currentActivity, Class<? extends Activity> nextActivityClass, int requestCode) { ShadowActivity shadowActivity = Shadows.shadowOf(currentActivity); ShadowActivity.IntentForResult intentForResult = shadowActivity.getNextStartedActivityForResult(); assertNotNull(intentForResult); assertThat(intentForResult.intent).hasComponent( currentActivity, nextActivityClass); assertEquals(requestCode, intentForResult.requestCode); return intentForResult.intent; }
Example 12
Source File: MainActivityTest.java From video-transcoder with GNU General Public License v3.0 | 4 votes |
private void openFilePickerFromLoadSelectFile(Activity activity, MediaInfo mediaInfo) throws Exception { shadowOf(activity).grantPermissions(Manifest.permission.READ_EXTERNAL_STORAGE); shadowOf(activity).grantPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE); Button selectVideo = activity.findViewById(R.id.selectVideo); assertNotNull(selectVideo); selectVideo.performClick(); ShadowActivity.IntentForResult intentForResult = shadowOf(activity).getNextStartedActivityForResult(); assertNotNull(intentForResult); Intent intent = intentForResult.intent; assertNotNull(intent); ComponentName componentName = intent.getComponent(); assertNotNull(componentName); assertEquals("protect.videotranscoder/.picker.FastScrollerFilePickerActivity", componentName.flattenToShortString()); Intent resultIntent = new Intent(); resultIntent.setData(Uri.fromFile(mediaInfo.file)); final MediaInfo mediaInfoToUse = mediaInfo; // When the media details are queried for the selected file, capture the call and // return the passed (or stubbed) MediaInfo instead of calling ffprobe. PowerMockito.when(FFmpegUtil.class, "getMediaDetails", any(File.class), any(ResultCallbackHandler.class)).thenAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) { Object [] args = invocation.getArguments(); ResultCallbackHandler<MediaInfo> resultHandler = (ResultCallbackHandler<MediaInfo>) args[1]; resultHandler.onResult(mediaInfoToUse); return null; } }); shadowOf(activity).receiveResult( intent, Activity.RESULT_OK, resultIntent); }
Example 13
Source File: GiftCardViewActivityTest.java From gift-card-guard with GNU General Public License v3.0 | 4 votes |
/** * Initiate and complete an image capture, returning the * location of the resulting file if the capture was * a success. * * @param success * true if the image capture is a success, and a * file is to be created at the requested location, * false otherwise. * @param buttonId * id of the button to press to initiate the capture * @return The URI pointing to the image file location, * regardless if the operation was successful or not. */ private Uri captureImageWithResult(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(MediaStore.ACTION_IMAGE_CAPTURE, action); Bundle bundle = intent.getExtras(); assertNotNull(bundle); assertEquals(false, bundle.isEmpty()); Uri argument = bundle.getParcelable(MediaStore.EXTRA_OUTPUT); assertNotNull(argument); assertTrue(argument.toString().length() > 0); // Respond to image capture, success shadowOf(activity).receiveResult( intent, success ? Activity.RESULT_OK : Activity.RESULT_CANCELED, null); if(success) { File imageFile = new File(argument.getPath()); assertEquals(false, imageFile.exists()); boolean result = imageFile.createNewFile(); assertTrue(result); } return argument; }
Example 14
Source File: TransactionViewActivityTest.java From budget-watch with GNU General Public License v3.0 | 4 votes |
/** * Initiate and complete an image capture, returning the * location of the resulting file if the capture was * a success. * * @param success * true if the image capture is a success, and a * file is to be created at the requested location, * false otherwise. * @param buttonId * id of the button to press to initiate the capture * @return The URI pointing to the image file location, * regardless if the operation was successful or not. */ private Uri captureImageWithResult(final Activity activity, final int buttonId, final boolean success, final int jpegQuality) throws IOException { // Ensure that the application has permissions to ask to use the camera shadowOf(activity).grantPermissions(Manifest.permission.CAMERA); // Start image capture final Button captureButton = (Button) activity.findViewById(buttonId); captureButton.performClick(); ShadowActivity.IntentForResult intentForResult = shadowOf(activity).getNextStartedActivityForResult(); assertNotNull(intentForResult); Intent intent = intentForResult.intent; assertNotNull(intent); String action = intent.getAction(); assertNotNull(action); assertEquals(MediaStore.ACTION_IMAGE_CAPTURE, action); Bundle bundle = intent.getExtras(); assertNotNull(bundle); assertEquals(false, bundle.isEmpty()); Uri argument = bundle.getParcelable(MediaStore.EXTRA_OUTPUT); assertNotNull(argument); assertTrue(argument.toString().length() > 0); // Set the JPEG quality setting, which will determine if the fake jpeg // file is converted to a lower quality final SharedPreferences.Editor preferencesEditor = PreferenceManager.getDefaultSharedPreferences(activity).edit(); preferencesEditor.putString("jpegQuality", Integer.toString(jpegQuality)); preferencesEditor.apply(); // Respond to image capture, success shadowOf(activity).receiveResult( intent, success ? Activity.RESULT_OK : Activity.RESULT_CANCELED, null); // If any async tasks were created, run them now Robolectric.flushBackgroundThreadScheduler(); if(success) { File imageFile = new File(argument.getPath()); // No camera is actually invoked in the unit test to create a // file. If the original JPEG quality is used, nothing creates // a file. However, if a lower quality is used, an async task // will generate a file, even if the original file was empty. if(jpegQuality == ORIGINAL_JPEG_QUALITY) { assertEquals(false, imageFile.exists()); boolean result = imageFile.createNewFile(); assertTrue(result); } else { assertEquals(true, imageFile.exists()); } } return argument; }