Search in sources :

Example 1 with PreferencesActivity

use of org.odk.collect.android.preferences.PreferencesActivity 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)

Aggregations

Intent (android.content.Intent)1 Menu (android.view.Menu)1 Test (org.junit.Test)1 PreferencesActivity (org.odk.collect.android.preferences.PreferencesActivity)1 ShadowActivity (org.robolectric.shadows.ShadowActivity)1 ShadowIntent (org.robolectric.shadows.ShadowIntent)1