@Test
  public void shouldReturnReturnedToLGAUtilizationItemWithCorrectUtilizationValue()
      throws Exception {
    commodityService.initialise(new User("test", "pass"));
    categoryService.clearCache();

    Commodity commodity = categoryService.all().get(6).getCommodities().get(0);

    Calendar calendar = Calendar.getInstance();
    Date today = calendar.getTime();

    assertNotNull(commodity);
    adjust(commodity, 2, false, AdjustmentReason.RETURNED_TO_LGA, adjustmentService);
    adjust(commodity, 3, false, AdjustmentReason.RETURNED_TO_LGA, adjustmentService);

    List<UtilizationItem> utilizationItems =
        commodityService.getMonthlyUtilizationItems(commodity, today);

    int expectedValue = 5;
    int utilizationValueIndex = DateUtil.dayNumber(today) - 1;

    assertThat(
        utilizationItems.get(5).getUtilizationValues().get(utilizationValueIndex).getValue(),
        is(expectedValue));
  }
  @Test
  public void shouldReturnCorrectNumberOfUtilizationValuesForTheMonthInTheUtilizationItem()
      throws Exception {
    Commodity commodity = categoryService.all().get(0).getCommodities().get(0);

    Calendar calendar = Calendar.getInstance();
    Integer expectedItems = DateUtil.dayNumber(calendar.getTime());

    List<UtilizationItem> utilizationItems =
        commodityService.getMonthlyUtilizationItems(commodity, calendar.getTime());
    assertThat(utilizationItems.get(0).getUtilizationValues().size(), is(expectedItems));

    calendar.add(Calendar.MONTH, 2);
    utilizationItems = commodityService.getMonthlyUtilizationItems(commodity, calendar.getTime());
    assertThat(utilizationItems.size(), is(0));

    calendar = Calendar.getInstance();
    calendar.add(Calendar.MONTH, -1);
    expectedItems = DateUtil.maxMonthDate(calendar.getTime());
    utilizationItems = commodityService.getMonthlyUtilizationItems(commodity, calendar.getTime());
    assertThat(utilizationItems.get(0).getUtilizationValues().size(), is(expectedItems));
  }
  @Test
  public void shouldReturnOpeningBalanceUtilizationItemWithCorrectUtilizationValue()
      throws Exception {
    commodityService.initialise(new User("test", "pass"));
    categoryService.clearCache();
    Commodity commodity = categoryService.all().get(0).getCommodities().get(0);

    Calendar calendar = Calendar.getInstance();
    Date today = calendar.getTime();
    Date yesterday = DateUtil.addDayOfMonth(today, -1);
    int stockOnHand = commodity.getStockOnHand();
    dispense(commodity, 3, dispensingService, yesterday);

    List<UtilizationItem> utilizationItems =
        commodityService.getMonthlyUtilizationItems(commodity, today);

    int expectedOpeningStock = stockOnHand - 3;
    int utilizationValueIndex = DateUtil.dayNumber(today) - 1;

    assertThat(
        utilizationItems.get(1).getUtilizationValues().get(utilizationValueIndex).getValue(),
        is(expectedOpeningStock));
  }
  @Test
  public void shouldReturnReceivedUtilizationItemWithCorrectUtilizationValue() throws Exception {
    commodityService.initialise(new User("test", "pass"));
    categoryService.clearCache();

    Commodity commodity = categoryService.all().get(0).getCommodities().get(0);

    Calendar calendar = Calendar.getInstance();
    Date today = calendar.getTime();

    receive(commodity, 2, receiveService);
    receive(commodity, 3, receiveService);

    List<UtilizationItem> utilizationItems =
        commodityService.getMonthlyUtilizationItems(commodity, today);

    int expectedValue = 5;
    int utilizationValueIndex = DateUtil.dayNumber(today) - 1;

    assertThat(
        utilizationItems.get(2).getUtilizationValues().get(utilizationValueIndex).getValue(),
        is(expectedValue));
  }