@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)); }
@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")); }
@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); }
@Test public void shouldFinishActivityOnOptionsItemHomeSelected() throws Exception { activity.onOptionsItemSelected(new TestMenuItem(android.R.id.home)); assertThat(activity).isFinishing(); }