ServerFoundActivity extends BaseActivity implements ServerFoundView { @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: presenter.onClickCancel(); return true; default: return super.onOptionsItemSelected(item); } }  static Intent getCallingIntent(Context context, ServerModel serverModel); @Override boolean onOptionsItemSelected(MenuItem item); @Override void renderServer(@NonNull ServerModel serverModel); @Override void showError(@NonNull String errorMessage); @Override void navigateBack(boolean isSuccess, ServerModel serverModel); @OnClick(R.id.button_connect) void onConnectButtonClick(View view); static final String KEY_SERVER; }
@Test public void shouldCancelActivityWhenHomeButtonPressed() throws Exception { MenuItem mockMenuItem = mock(MenuItem.class); when(mockMenuItem.getItemId()).thenReturn(android.R.id.home); serverFoundActivity.onOptionsItemSelected(mockMenuItem); verify(mockServerFoundPresenter, times(1)).onClickCancel(); }
@Test public void shouldNotCancelActivityWhenHomeButtonNotPressed() throws Exception { MenuItem mockMenuItem = mock(MenuItem.class); when(mockMenuItem.getItemId()).thenReturn(-1); serverFoundActivity.onOptionsItemSelected(mockMenuItem); verify(mockServerFoundPresenter, never()).onClickCancel(); }