WindowedEventCounter { public void setCapacity(int capacity) { if (capacity <= 0) { throw new IllegalArgumentException("capacity must be greater than 0"); } synchronized (queue) { if (capacity < this.capacity) { while (queue.size() > capacity) { queue.removeFirst(); } } } this.capacity = capacity; } WindowedEventCounter(int capacity, long windowMillis); void mark(); int tally(); long getWindowMillis(); void setCapacity(int capacity); int getCapacity(); void setWindowMillis(long windowMillis);  }
@Test public void testSettingBadCapacityThrowsException() { try { impl.setCapacity(0); fail("should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { } }