@Test
public void fill() throws Exception {

    //
    // create a period of 4 hours
    //
    DateTime start = new DateTime(2009, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC);
    DateTimePeriod period = new DateTimeHour(start, start.plusHours(4));
    // fill an empty map
    TreeMap<DateTime, SampleData> emptyMap = new TreeMap<DateTime, SampleData>();
    DateTimePeriodDataUtil.fill(SampleData.class, emptyMap, period.toHours());
    SampleData[] result0 = emptyMap.values().toArray(new SampleData[0]);
    Assert.assertArrayEquals(new SampleData[] {
        new SampleData(DateTimePeriod.createHour(2009, 1, 1, 0, DateTimeZone.UTC), null),
        new SampleData(DateTimePeriod.createHour(2009, 1, 1, 1, DateTimeZone.UTC), null),
        new SampleData(DateTimePeriod.createHour(2009, 1, 1, 2, DateTimeZone.UTC), null),
        new SampleData(DateTimePeriod.createHour(2009, 1, 1, 3, DateTimeZone.UTC), null)
    }, result0);
    // fill a partially completed map
    SampleData hour0 = new SampleData(DateTimePeriod.createHour(2009, 1, 1, 0, DateTimeZone.UTC), "hour0");
    SampleData hour2 = new SampleData(DateTimePeriod.createHour(2009, 1, 1, 2, DateTimeZone.UTC), "hour2");
    TreeMap<DateTime, SampleData> partialMap = new TreeMap<DateTime, SampleData>();
    partialMap.put(hour0.getPeriod().getStart(), hour0);
    partialMap.put(hour2.getPeriod().getStart(), hour2);
    DateTimePeriodDataUtil.fill(SampleData.class, partialMap, period.toHours());
    result0 = partialMap.values().toArray(new SampleData[0]);
    Assert.assertArrayEquals(new SampleData[] {
        new SampleData(DateTimePeriod.createHour(2009, 1, 1, 0, DateTimeZone.UTC), "hour0"),
        new SampleData(DateTimePeriod.createHour(2009, 1, 1, 1, DateTimeZone.UTC), null),
        new SampleData(DateTimePeriod.createHour(2009, 1, 1, 2, DateTimeZone.UTC), "hour2"),
        new SampleData(DateTimePeriod.createHour(2009, 1, 1, 3, DateTimeZone.UTC), null)
    }, result0);
}