InitialInventoryActivity extends InventoryActivity { @Override public void onBackPressed() { if (isSearchViewActivity()) { searchView.onActionViewCollapsed(); return; } if (!isAddNewDrug) { ToastUtil.show(R.string.msg_save_before_exit); return; } super.onBackPressed(); }  @Override void initUI(); @Override void goToNextPage(); @Override void onBackPressed(); static Intent getIntentToMe(Context context, boolean isAddNewDrug); static Intent getIntentToMe(Context context);  }
@Test public void shouldShowMessageAndNeverBackWhenPressBackInInitInventory() { initialInventoryActivity.onBackPressed(); assertEquals(ShadowToast.getTextOfLatestToast(), initialInventoryActivity.getString(R.string.msg_save_before_exit)); initialInventoryActivity.onBackPressed(); assertFalse(initialInventoryActivity.isFinishing()); }