Beispiel #1
0
  /** Test method for {@link it.reexon.lib.date.DateUtils#average(it.reexon.lib.date.DateRange)}. */
  @Test
  public final void testAverageDateRange() {
    try {
      DateRange dateRange = new DateRange(date01, date05);
      Date averageDate = DateUtils.average(dateRange);
      Assert.assertEquals(date03.getTime(), averageDate.getTime());

      try {
        dateRange.setDateFrom(null);
        DateUtils.average(Collections.emptyList());
        Assert.fail("Should have thrown an exception");
      } catch (Exception e) {
        Assert.assertEquals(e.getClass(), IllegalArgumentException.class);
      }
      try {
        dateRange.setDateFrom(null);
        dateRange.setDateTo(null);
        DateUtils.average(Collections.emptyList());
        Assert.fail("Should have thrown an exception");
      } catch (Exception e) {
        Assert.assertEquals(e.getClass(), IllegalArgumentException.class);
      }
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
      throw new RuntimeException(e);
    }
  }
Beispiel #2
0
  /** Test method for {@link it.reexon.lib.date.DateUtils#average(java.util.List)}. */
  @Test
  public final void testAverageListOfDate() {
    try {
      List<Date> dates =
          new LinkedList<Date>(ListUtils.createList(date01, date02, date03, date04, date05));
      Date averageDate = DateUtils.average(dates);
      Assert.assertEquals(date03.getTime(), averageDate.getTime());

      try {
        DateUtils.average(Collections.emptyList());
        Assert.fail("Should have thrown an exception");
      } catch (Exception e) {
        Assert.assertEquals(e.getClass(), IllegalArgumentException.class);
      }
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
      throw new RuntimeException(e);
    }
  }