Java 类org.robolectric.tester.android.view.TestMenuItem 实例源码

项目:robolectric-ant-sample    文件:RecentActivityActivityTest.java   
@Test
public void shouldSignOutWhenTheSignOutButtonIsClicked() throws Exception {
    TestMenu menu = new TestMenu();
    menu.add("garbage that should be cleared upon onPrepareOptionsMenu");

    activity.onPrepareOptionsMenu(menu);

    TestMenuItem signOutMenuItem = (TestMenuItem) menu.getItem(0);
    assertThat(signOutMenuItem.isEnabled(), equalTo(true));
    assertThat(signOutMenuItem.getTitle().toString(), equalTo("Sign Out"));

    signOutMenuItem.click();
    assertThat(authenticationGateway.isAuthenticated(), equalTo(false));
    assertThat(shadowOf(activity).isFinishing(), equalTo(true));
}
项目:robolectric-ant-sample    文件:RecentActivityActivityTest.java   
@Test
public void signOutButtonShouldBeDisabledWhenNotSignedIn() throws Exception {
    authenticationGateway.signOut();
    TestMenu menu = new TestMenu();

    activity.onPrepareOptionsMenu(menu);

    TestMenuItem signOutMenuItem = (TestMenuItem) menu.getItem(0);
    assertThat(signOutMenuItem.isEnabled(), equalTo(false));
    assertThat(signOutMenuItem.getTitle().toString(), equalTo("Sign Out"));
}
项目:open    文件:BaseActivityTest.java   
@Test
public void onOptionsItemSelected_shouldStartListResultsActivity() throws Exception {
    final PagerResultsFragment pagerResultsFragment =
            PagerResultsFragment.newInstance(activity);
    activity.getSupportFragmentManager().beginTransaction()
            .replace(R.id.pager_results_container, pagerResultsFragment,
                    PagerResultsFragment.TAG).commit();
    activity.onOptionsItemSelected(new TestMenuItem(R.id.action_view_all));
    assertThat(getShadowApplication().getNextStartedActivity())
            .hasComponent(application.getPackageName(), ListResultsActivity.class);
}
项目:Inside_Android_Testing    文件:RecentActivityActivityTest.java   
@Test
public void shouldSignOutWhenTheSignOutButtonIsClicked() throws Exception {
    TestMenu menu = new TestMenu();
    menu.add("garbage that should be cleared upon onPrepareOptionsMenu");

    activity.onPrepareOptionsMenu(menu);

    TestMenuItem signOutMenuItem = (TestMenuItem) menu.getItem(0);
    assertThat(signOutMenuItem.isEnabled(), equalTo(true));
    assertThat(signOutMenuItem.getTitle().toString(), equalTo("Sign Out"));

    signOutMenuItem.click();
    assertThat(authenticationGateway.isAuthenticated(), equalTo(false));
    assertThat(shadowOf(activity).isFinishing(), equalTo(true));
}
项目:Inside_Android_Testing    文件:RecentActivityActivityTest.java   
@Test
public void signOutButtonShouldBeDisabledWhenNotSignedIn() throws Exception {
    authenticationGateway.signOut();
    TestMenu menu = new TestMenu();

    activity.onPrepareOptionsMenu(menu);

    TestMenuItem signOutMenuItem = (TestMenuItem) menu.getItem(0);
    assertThat(signOutMenuItem.isEnabled(), equalTo(false));
    assertThat(signOutMenuItem.getTitle().toString(), equalTo("Sign Out"));
}
项目:open    文件:ListResultsActivityTest.java   
@Test
public void shouldFinishActivityOnOptionsItemHomeSelected() throws Exception {
    activity.onOptionsItemSelected(new TestMenuItem(android.R.id.home));
    assertThat(activity).isFinishing();
}