WorkerCounter implements Executor { @Override public void execute(Runnable command) { realExecutor.execute(new Worker(command)); } WorkerCounter(Executor realExecutor); @Override void execute(Runnable command); synchronized void afterPreviousWorkersFinished(ActorRef<WorkerListener> onFinished);  }
@Test(timeout = TIMEOUT) public void toString_of_commands_is_good_for_logging() { final StringBuilder loggerOutput = new StringBuilder(); Executor loggingExecutor = wrappedCommand -> loggerOutput.append(wrappedCommand.toString()); WorkerCounter counter = new WorkerCounter(loggingExecutor); Runnable originalCommand = mock(Runnable.class, "<the command's original toString>"); counter.execute(originalCommand); assertThat(loggerOutput.toString(), containsString(originalCommand.toString())); }