### Question:
RecentActivityActivity extends Activity { @Override public boolean onPrepareOptionsMenu(Menu menu) { menu.clear(); addSignOutMenuItem(menu); return true; }  @Override boolean onPrepareOptionsMenu(Menu menu);  }### Answer:
@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")); }