### Question:
BurstDetector { public boolean invoke() { long now = System.currentTimeMillis(); long last = this.lastInvocationTime; this.lastInvocationTime = now; if (now - last < DELTA) { counter++; if (counter >= N) { counter = 0; return true; } else { return false; } } else { this.counter = 1; return false; } } BurstDetector(int n, long delta); boolean invoke();  }### Answer:
@Test public void shouldDetectBurst() { BurstDetector burstDetector = new BurstDetector(3, 100); assertFalse(burstDetector.invoke()); assertFalse(burstDetector.invoke()); assertTrue(burstDetector.invoke()); assertFalse(burstDetector.invoke()); assertFalse(burstDetector.invoke()); assertTrue(burstDetector.invoke()); assertFalse(burstDetector.invoke()); }
@Test public void shouldNotDetectBurst() throws InterruptedException { BurstDetector burstDetector = new BurstDetector(3, 10); assertFalse(burstDetector.invoke()); Thread.sleep(20); assertFalse(burstDetector.invoke()); Thread.sleep(20); assertFalse(burstDetector.invoke()); Thread.sleep(20); assertFalse(burstDetector.invoke()); Thread.sleep(20); assertFalse(burstDetector.invoke()); Thread.sleep(20); assertFalse(burstDetector.invoke()); Thread.sleep(20); assertFalse(burstDetector.invoke()); }