use of org.robolectric.shadows.ShadowIntent in project collect by opendatakit.
the class MainActivityTest method optionsMenuTest.
/**
* {@link Test} to assert Options Menu's functioning.
*/
@Test
public void optionsMenuTest() throws Exception {
Menu menu = shadowOf(mainMenuActivity).getOptionsMenu();
assertNotNull(menu);
assertNotNull(mainMenuActivity.onCreateOptionsMenu(menu));
// Test for AboutActivity
mainMenuActivity.onOptionsItemSelected(menu.getItem(0));
ShadowActivity shadowActivity = shadowOf(mainMenuActivity);
Intent startedIntent = shadowActivity.getNextStartedActivity();
ShadowIntent shadowIntent = shadowOf(startedIntent);
assertEquals(AboutActivity.class.getName(), shadowIntent.getIntentClass().getName());
// Test for About Menu Title
String menuTitle = mainMenuActivity.getResources().getString(R.string.about_preferences);
String shadowTitle = menu.getItem(0).getTitle().toString();
assertEquals(shadowTitle, menuTitle);
// Test for PreferencesActivity
mainMenuActivity.onOptionsItemSelected(menu.getItem(1));
shadowActivity = shadowOf(mainMenuActivity);
startedIntent = shadowActivity.getNextStartedActivity();
shadowIntent = shadowOf(startedIntent);
assertEquals(PreferencesActivity.class.getName(), shadowIntent.getIntentClass().getName());
// Test for General Settings Menu Title
menuTitle = mainMenuActivity.getResources().getString(R.string.general_preferences);
shadowTitle = menu.getItem(1).getTitle().toString();
assertEquals(shadowTitle, menuTitle);
// Test for Admin Settings Menu Title
menuTitle = mainMenuActivity.getResources().getString(R.string.admin_preferences);
shadowTitle = menu.getItem(2).getTitle().toString();
assertEquals(shadowTitle, menuTitle);
}
use of org.robolectric.shadows.ShadowIntent in project easypermissions by googlesamples.
the class AppSettingsDialogTest method shouldShowExpectedSettingsDialog_whenBuildingFromActivity.
// ------ From Activity ------
@Test
public void shouldShowExpectedSettingsDialog_whenBuildingFromActivity() {
new AppSettingsDialog.Builder(spyActivity).setTitle(android.R.string.dialog_alert_title).setRationale(android.R.string.unknownName).setPositiveButton(android.R.string.ok).setNegativeButton(android.R.string.cancel).setThemeResId(R.style.Theme_AppCompat).build().show();
verify(spyActivity, times(1)).startActivityForResult(intentCaptor.capture(), integerCaptor.capture());
assertThat(integerCaptor.getValue()).isEqualTo(DEFAULT_SETTINGS_REQ_CODE);
assertThat(Objects.requireNonNull(intentCaptor.getValue().getComponent()).getClassName()).isEqualTo(AppSettingsDialogHolderActivity.class.getName());
Intent startedIntent = shadowApp.getNextStartedActivity();
ShadowIntent shadowIntent = shadowOf(startedIntent);
assertThat(shadowIntent.getIntentClass()).isEqualTo(AppSettingsDialogHolderActivity.class);
}
use of org.robolectric.shadows.ShadowIntent in project easypermissions by googlesamples.
the class AppSettingsDialogTest method shouldShowExpectedSettingsDialog_whenBuildingFromSupportFragment.
@Test
public void shouldShowExpectedSettingsDialog_whenBuildingFromSupportFragment() {
new AppSettingsDialog.Builder(spyFragment).setTitle(android.R.string.dialog_alert_title).setRationale(android.R.string.unknownName).setPositiveButton(android.R.string.ok).setNegativeButton(android.R.string.cancel).setThemeResId(R.style.Theme_AppCompat).build().show();
verify(spyFragment, times(1)).startActivityForResult(intentCaptor.capture(), integerCaptor.capture());
assertThat(integerCaptor.getValue()).isEqualTo(DEFAULT_SETTINGS_REQ_CODE);
assertThat(Objects.requireNonNull(intentCaptor.getValue().getComponent()).getClassName()).isEqualTo(AppSettingsDialogHolderActivity.class.getName());
Intent startedIntent = shadowApp.getNextStartedActivity();
ShadowIntent shadowIntent = shadowOf(startedIntent);
assertThat(shadowIntent.getIntentClass()).isEqualTo(AppSettingsDialogHolderActivity.class);
}
use of org.robolectric.shadows.ShadowIntent in project scdl by passy.
the class PreferencesMenuTest method shouldStartPreferencesInActivity.
private void shouldStartPreferencesInActivity(Fragment fragment) {
final ActivityController<FragmentActivity> controller = Robolectric.buildActivity(FragmentActivity.class);
controller.create().start().resume();
final FragmentActivity activity = controller.get();
activity.getSupportFragmentManager().beginTransaction().add(fragment, null).commit();
final MenuItem item = new TestMenuItem(R.id.preferences);
fragment.onOptionsItemSelected(item);
final ShadowActivity shadowActivity = Robolectric.shadowOf(activity);
final Intent startedActivity = shadowActivity.getNextStartedActivity();
// Intent was actually started
assertThat(startedActivity, notNullValue());
final ShadowIntent intent = Robolectric.shadowOf(startedActivity);
assertThat(intent.getComponent().getClassName(), equalTo(ApplicationPreferencesActivity.class.getName()));
}
use of org.robolectric.shadows.ShadowIntent in project scdl by passy.
the class ShareIntentResolverTest method testFailWithSuperInvalidUrl.
@Test(expected = ShareIntentResolverException.class)
public void testFailWithSuperInvalidUrl() throws ShareIntentResolverException {
ShadowIntent intent = Robolectric.shadowOf(mIntent);
intent.setData(Uri.parse("//nope"));
final ShareIntentResolver resolver = TestHelper.getInjector().getInstance(ShareIntentResolver.class);
resolver.resolve();
}
Aggregations