@Test
public void shouldReturnAverageIgnoringInfinitiesAndIncludingItemsBeforeCrash() {

    // given:
    SqlTimeHistory calculator;
    long l1 = 10L;
    long l2 = 20L;
    long l3 = 30L;
    long l4 = 40L;
    Average avg1;
    Average avg2;
    Average avg3;
    Average avg4;
    Average avg5;
    // when:
    calculator = new SqlTimeHistory(3, true, false);
    calculator.updateAverage(10L);
    calculator.updateAverage(20L);
    calculator.updateAverage(30L);
    calculator.updateAverage(Long.MAX_VALUE);
    calculator.updateAverage(Long.MAX_VALUE);
    avg1 = calculator.updateAverage(l1);
    avg2 = calculator.updateAverage(Long.MAX_VALUE);
    avg3 = calculator.updateAverage(l2);
    avg4 = calculator.updateAverage(l3);
    avg5 = calculator.updateAverage(l4);
    // then:
    assertEquals(l1, avg1.getValue());
    assertEquals(Long.MAX_VALUE, avg2.getValue());
    assertEquals((int)(l1 + l2)/2, avg3.getValue());
    assertEquals((int)(l2 + l3)/2, avg4.getValue());
    assertEquals((int)(l2 + l3 + l4)/3, avg5.getValue());
    assertEquals(1, avg1.getItemsCountIncludedInAverage());
    assertEquals(3, avg2.getItemsCountIncludedInAverage());
    assertEquals(2, avg3.getItemsCountIncludedInAverage());
    assertEquals(2, avg4.getItemsCountIncludedInAverage());
    assertEquals(3, avg5.getItemsCountIncludedInAverage());
}