@Test
public void testAverageSince() {

    item.setState(new DecimalType(3025));
    ZonedDateTime startStored = ZonedDateTime.of(2003, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault());
    ZonedDateTime endStored = ZonedDateTime.of(2012, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault());
    long storedInterval = endStored.toInstant().toEpochMilli() - startStored.toInstant().toEpochMilli();
    long recentInterval = Instant.now().toEpochMilli() - endStored.toInstant().toEpochMilli();
    double expected = (2007.4994 * storedInterval + 2518.5 * recentInterval) / (storedInterval + recentInterval);
    DecimalType average = PersistenceExtensions.averageSince(item, startStored, TestPersistenceService.ID);
    assertNotNull(average);
    assertEquals(expected, average.doubleValue(), 0.01);
    item.setState(new QuantityType<>(3025, SIUnits.CELSIUS));
    average = PersistenceExtensions.averageSince(item, startStored, TestPersistenceService.ID);
    assertNotNull(average);
    assertEquals(expected, average.doubleValue(), 0.01);
    // default persistence service
    average = PersistenceExtensions.averageSince(item, startStored);
    assertNull(average);
}