### Question:
DispensingService { public void addDispensing(Dispensing dispensing) { GenericDao<Dispensing> dispensingDao = new GenericDao<>(Dispensing.class, context); dispensingDao.create(dispensing); saveDispensingItems(dispensing.getDispensingItems()); }  void addDispensing(Dispensing dispensing); String getNextPrescriptionId(); int getDispensedTotalValue(Commodity commodity); List<UtilizationValue> getDispensedValues(Commodity commodity, Date startDate, Date endDate, boolean forVial);  }### Answer:
@Test public void testSaveDispensingSavesItsDispensingItems() throws Exception { commodityService.initialise(new User("test", "pass")); Commodity commodity = commodityService.all().get(0); Dispensing dispensing = new Dispensing(); DispensingItem newDispensingItem = new DispensingItem(commodity, 1); dispensing.addItem(newDispensingItem); dispensingService.addDispensing(dispensing); Long count = dbUtil.withDao(DispensingItem.class, new DbUtil.Operation<DispensingItem, Long>() { @Override public Long operate(Dao<DispensingItem, String> dao) throws SQLException { return dao.countOf(); } }); assertThat(count, is(1L)); }
@Test public void addDispensingShouldReduceTheStockLevels() { commodityService.initialise(new User("test", "pass")); Commodity commodity = commodityService.all().get(0); int stockLevel = stockService.getStockLevelFor(commodity); assertThat(stockLevel, is(10)); Dispensing dispensing = new Dispensing(); DispensingItem item1 = new DispensingItem(commodity, 1); item1.setDispensing(dispensing); assertThat(item1.getActivitiesValues().get(0).getCommodityAction().getActivityType(), is(DataElementType.DISPENSED.getActivity())); dispensing.addItem(item1); dispensingService.addDispensing(dispensing); stockLevel = stockService.getStockLevelFor(commodity); assertThat(stockLevel, is(9)); }