ExecutorServiceWorkRunner implements WorkRunner { @Override public void dispose() { try { List<Runnable> runnables = service.shutdownNow(); if (!runnables.isEmpty()) { LOGGER.warn( "Disposing ExecutorServiceWorkRunner with {} outstanding tasks.", runnables.size()); } if (!service.awaitTermination(100, TimeUnit.MILLISECONDS)) { LOGGER.error("ExecutorService shutdown timed out; there are still tasks executing"); } } catch (InterruptedException e) { LOGGER.error("Timeout when disposing work runner", e); } } ExecutorServiceWorkRunner(ExecutorService service); @SuppressWarnings("FutureReturnValueIgnored") @Override void post(Runnable runnable); @Override void dispose();  }
@Test public void disposingShouldStopUnderlyingExecutorService() throws Exception { ExecutorService service = Executors.newSingleThreadExecutor(); underTest = new ExecutorServiceWorkRunner(service); underTest.dispose(); assertThat(service.isTerminated(), is(true)); }