MainActivity extends FragmentActivity implements Injector, MementoCallbacks { @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: getSupportFragmentManager().popBackStack(); return true; default: return super.onOptionsItemSelected(item); } }  @Override void onLaunch(); @Override void onBackPressed(); @Override boolean onOptionsItemSelected(MenuItem item);  }
@Test public void testOnOptionsItemSelected() throws Exception { MainActivity mainActivity = activityController.create().get(); FragmentManager fragmentManager = mainActivity.getSupportFragmentManager(); fragmentManager.beginTransaction() .replace(android.R.id.content, new Fragment()) .addToBackStack(null) .commit(); int oldStack = fragmentManager.getBackStackEntryCount(); assertTrue(mainActivity.onOptionsItemSelected(new TestMenuItem(android.R.id.home))); assertTrue(fragmentManager.getBackStackEntryCount() < oldStack); }