AudioPlayerActivity extends RoboActionBarActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { onBackPressed(); } return super.onOptionsItemSelected(item); }  @Override boolean onOptionsItemSelected(MenuItem item); @Override boolean onTouchEvent(MotionEvent event); @Subscribe void onEvent(AudioPlayingEvent event); @Subscribe void onEvent(AudioStoppedEvent event);  }
@Test public void itReturnsToPreviousActivityOnPressHomeButton() { MenuItem homeButton = mock(MenuItem.class); when(homeButton.getItemId()).thenReturn(android.R.id.home); AudioPlayerActivity activity = spy(createActivity()); activity.onOptionsItemSelected(homeButton); verify(activity).onBackPressed(); }