IntervalCount { public long resetIfExpiredAndTick() { if (isExpired()) { reset(); } tick(); return adder.sum(); } IntervalCount(long intervalDurationMs); long resetIfExpiredAndTick(); long silenceDuration(); long getCount();  }
@Test public void ticksInSameIntervalAreSummed() { IntervalCount intervalCount = new IntervalCount(100L); assertEquals(1L, intervalCount.resetIfExpiredAndTick()); Clock.shift(100); assertEquals(2L, intervalCount.resetIfExpiredAndTick()); }
@Test public void oldDataCleanedWhenIntervalExpired() { IntervalCount intervalCount = new IntervalCount(100L); assertEquals(1L, intervalCount.resetIfExpiredAndTick()); Clock.shift(101); assertEquals(1L, intervalCount.resetIfExpiredAndTick()); }