WindowedEventCounter { public int tally() { long currentTimeMillis = clock.currentTimeMillis(); final long removeTimesBeforeMillis = currentTimeMillis - windowMillis; synchronized (queue) { while (!queue.isEmpty() && queue.peek() < removeTimesBeforeMillis) { queue.removeFirst(); } return queue.size(); } } WindowedEventCounter(int capacity, long windowMillis); void mark(); int tally(); long getWindowMillis(); void setCapacity(int capacity); int getCapacity(); void setWindowMillis(long windowMillis);  }
@Test public void testStartsEmpty() { assertEquals(0, impl.tally()); }