### Question:
StockService { public int getStockLevelFor(Commodity commodity) { return commodity.getStockOnHand(); }  int getStockLevelFor(Commodity commodity); void reduceStockLevelFor(final Commodity commodity, int quantity, Date date); void increaseStockLevelFor(Commodity commodity, int quantity, Date date); @Inject
    public StockItemSnapshotService stockItemSnapshotService; }### Answer:
@Test public void shouldGetStockCorrespondingToCommodityFromStockTable() throws SQLException { Category category = new Category("test category"); Commodity commodity = new Commodity("test commodity"); commodity.setCategory(category); commodityDao.create(commodity); StockItem stockItem = new StockItem(commodity, 100); stockDao.create(stockItem); commodity = commodityDao.queryForSameId(commodity); int stockLevel = stockService.getStockLevelFor(commodity); stockDao.delete(stockItem); assertThat(stockLevel, is(100)); }
@Test(expected = LmisException.class) public void shouldThrowExceptionWhenAskedForStockLevelForNonPersistedCommodity() { Commodity notExistCommodity = new Commodity("Some Non-exist Commodity"); stockService.getStockLevelFor(notExistCommodity); }
@Test public void shouldCreateAStockItemRowForEachCommodityOnInitialise() throws SQLException { commodityService.initialise(new User("test", "pass")); for (Commodity commodity : commodityService.all()) { assertThat(stockService.getStockLevelFor(commodity), greaterThanOrEqualTo(0)); } }