### Question:
DispenseActivity extends CommoditySelectableActivity { Dispensing getDispensing() { final Dispensing dispensing = new Dispensing(); dispensing.setPrescriptionId(textViewPrescriptionId.getText().toString()); for(int i=0; i< arrayAdapter.getCount(); i++ ){ BaseCommodityViewModel commodityViewMode = (BaseCommodityViewModel)arrayAdapter.getItem(i); dispensing.addItem(new DispensingItem(commodityViewMode.getCommodity(), commodityViewMode.getQuantityEntered())); } return dispensing; }    }### Answer:
@Test public void getDispensingShouldGetItemsInTheListView() throws Exception { String commodityName = "food"; DispenseActivity dispenseActivity = getDispenseActivity(); BaseCommodityViewModel commodityViewModel = new BaseCommodityViewModel(new Commodity(commodityName)); commodityViewModel.setQuantityEntered(12); CommodityToggledEvent commodityToggledEvent = new CommodityToggledEvent(commodityViewModel); EventBus.getDefault().post(commodityToggledEvent); Dispensing dispensing = dispenseActivity.getDispensing(); assertThat(dispensing.getDispensingItems().size(), is(1)); assertThat(dispensing.getDispensingItems().get(0).getQuantity(), is(12)); assertThat(dispensing.getDispensingItems().get(0).getCommodity().getName(), is(commodityName)); }
@Test public void getDispensingShouldHaveThePrescriptionId() throws Exception { String resultExpected = "0003-Jul"; when(dispenseService.getNextPrescriptionId()).thenReturn(resultExpected); DispenseActivity dispenseActivity = getDispenseActivity(); assertThat(dispenseActivity.getDispensing().getPrescriptionId(), is(resultExpected)); }