### Question:
IncrementalSimonsPurger { public synchronized void start(long period, TimeUnit timeUnit) { if (scheduledFuture == null) { PurgerRunnable runnable = new PurgerRunnable(manager); scheduledFuture = executorService.scheduleWithFixedDelay(runnable, period, period, timeUnit); } else { throw new IllegalStateException("IncrementSimonPurger has already been started"); } } IncrementalSimonsPurger(Manager manager);   IncrementalSimonsPurger(Manager manager, ScheduledExecutorService executorService); synchronized void start(long period, TimeUnit timeUnit); synchronized void cancel();  }### Answer:
@Test(dataProvider = "managersProvider") public void testPeriodicalIncrementalSimonsPurge(Manager manager) { IncrementalSimonsPurger incrementalSimonsPurger = new IncrementalSimonsPurger(manager, executorService); long duration = 1; TimeUnit timeUnit = TimeUnit.SECONDS; incrementalSimonsPurger.start(duration, timeUnit); verify(executorService).scheduleWithFixedDelay( argThat(new PurgerRunnableMatcher(manager)), eq(duration), eq(duration), eq(timeUnit)); }
@Test(expectedExceptions = IllegalStateException.class) public void testStartWithoutCancel() { EnabledManager manager = new EnabledManager(); IncrementalSimonsPurger incrementalSimonsPurger = new IncrementalSimonsPurger(manager, executorService); incrementalSimonsPurger.start(1, TimeUnit.SECONDS); incrementalSimonsPurger.start(1, TimeUnit.SECONDS); }
@Test(dataProvider = "managersProvider") public void testPurging(Manager manager) { Stopwatch stopwatch = manager.getStopwatch("stopwatch"); stopwatch.sampleIncrement("key"); stopwatch.start().stop(); long timeInFuture = manager.milliTime() + 1000; IncrementalSimonsPurger.PurgerRunnable runnable = new IncrementalSimonsPurger.PurgerRunnable(manager, timeInFuture); runnable.run(); Assert.assertFalse(stopwatch.stopIncrementalSampling("key")); }