LanguageSelectorActivity extends AbstractTranslationCardsActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case CANCEL_BUTTON_ID: selectedLanguage = ""; finish(); break; default: break; } return super.onOptionsItemSelected(item); }  @Override void inflateView(); @Override boolean onOptionsItemSelected(MenuItem item); @Override boolean onCreateOptionsMenu(Menu menu); @Override void finish(); @Override void setBitmapsForActivity(); static final String SELECTED_LANGUAGE_KEY; static final int CANCEL_BUTTON_ID; }
@Test public void shouldReturnCancelResultCodeWhenUserClicksCancel() throws Exception { ShadowActivity shadowActivity = shadowOf(activity); activity.onOptionsItemSelected(new RoboMenuItem(CANCEL_BUTTON_ID)); assertEquals(Activity.RESULT_CANCELED, shadowActivity.getResultCode()); assertTrue(shadowActivity.getResultIntent().getStringExtra(SELECTED_LANGUAGE_KEY).isEmpty()); }