Search in sources :

Example 11 with ShadowIntent

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);
}
Also used : ShadowIntent(org.robolectric.shadows.ShadowIntent) PreferencesActivity(org.odk.collect.android.preferences.PreferencesActivity) ShadowActivity(org.robolectric.shadows.ShadowActivity) ShadowIntent(org.robolectric.shadows.ShadowIntent) Intent(android.content.Intent) Menu(android.view.Menu) Test(org.junit.Test)

Example 12 with ShadowIntent

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);
}
Also used : ShadowIntent(org.robolectric.shadows.ShadowIntent) Intent(android.content.Intent) ShadowIntent(org.robolectric.shadows.ShadowIntent) Test(org.junit.Test)

Example 13 with ShadowIntent

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);
}
Also used : ShadowIntent(org.robolectric.shadows.ShadowIntent) Intent(android.content.Intent) ShadowIntent(org.robolectric.shadows.ShadowIntent) Test(org.junit.Test)

Example 14 with ShadowIntent

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()));
}
Also used : FragmentActivity(android.support.v4.app.FragmentActivity) ShadowIntent(org.robolectric.shadows.ShadowIntent) TestMenuItem(org.robolectric.tester.android.view.TestMenuItem) ShadowActivity(org.robolectric.shadows.ShadowActivity) TestMenuItem(org.robolectric.tester.android.view.TestMenuItem) MenuItem(android.view.MenuItem) ShadowIntent(org.robolectric.shadows.ShadowIntent) Intent(android.content.Intent)

Example 15 with ShadowIntent

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();
}
Also used : ShadowIntent(org.robolectric.shadows.ShadowIntent) ShareIntentResolver(net.rdrei.android.scdl2.ShareIntentResolver) Test(org.junit.Test)

Aggregations

ShadowIntent (org.robolectric.shadows.ShadowIntent)20 Test (org.junit.Test)19 Intent (android.content.Intent)12 ShareIntentResolver (net.rdrei.android.scdl2.ShareIntentResolver)8 ShadowActivity (org.robolectric.shadows.ShadowActivity)7 Button (android.widget.Button)5 Bundle (android.os.Bundle)3 PendingDownload (net.rdrei.android.scdl2.api.PendingDownload)3 UserInfo (android.content.pm.UserInfo)1 FragmentActivity (android.support.v4.app.FragmentActivity)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 PreferencesActivity (org.odk.collect.android.preferences.PreferencesActivity)1 TestMenuItem (org.robolectric.tester.android.view.TestMenuItem)1