### Question:
PendingTaskRunner { public Future<?> run() { return Executors.newSingleThreadScheduledExecutor() .scheduleWithFixedDelay(() -> { try { pendingTasks.take().run(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } }, 0, delay, MILLISECONDS); } PendingTaskRunner(BlockingQueue<Runnable> pendingTasks, int delay); Future<?> run();  }### Answer:
@Test public void burnsAllTasksInQueue() throws Exception { runnables.offer(() -> messages.add("hello")); runnables.offer(() -> messages.add("world")); taskRunner.run(); await().atMost(500, MILLISECONDS).until(runnables::isEmpty); assertThat(messages, contains("hello", "world")); }
@Test public void exitOnInterruption() throws Exception { taskRunner.run().cancel(true); runnables.offer(() -> messages.add("hello")); Thread.sleep(300); assertThat(runnables.isEmpty(), is(false)); assertThat(messages.isEmpty(), is(true)); }