### Question:
LossesActivity extends CommoditySelectableActivity { @Override protected Button getSubmitButton() { return buttonSubmitLosses; }    }### Answer:
@Test public void shouldOpenConfirmDialogIfLossesAreValid() throws Exception { Commodity mockCommodity = buildMockCommodity(); when(mockCommodity.getStockOnHand()).thenReturn(10); LossesCommodityViewModel lossesCommodityViewModel = new LossesCommodityViewModel(mockCommodity); lossesCommodityViewModel.setLoss(MISSING, 1); EventBus.getDefault().post(new CommodityToggledEvent(lossesCommodityViewModel)); Button submitButton = lossesActivity.getSubmitButton(); submitButton.performClick(); assertThat(submitButton.getVisibility(), is(View.VISIBLE)); Dialog latestDialog = ShadowDialog.getLatestDialog(); assertThat(latestDialog, is(notNullValue())); }
@Test public void shouldNotOpenConfirmDialogIfLossesAreInvalid() { LossesCommodityViewModel lossesCommodityViewModel = new LossesCommodityViewModel(buildMockCommodity()); EventBus.getDefault().post(new CommodityToggledEvent(lossesCommodityViewModel)); Button submitButton = lossesActivity.getSubmitButton(); submitButton.performClick(); assertThat(ShadowToast.getTextOfLatestToast(), is(application.getResources().getString(R.string.fillInSomeLosses))); assertThat(ShadowDialog.getLatestDialog(), is(nullValue())); }