### Question:
WrappingKeySerializingExecutor implements KeySerializingExecutor { @Override public <T> ListenableFuture<T> submit(String key, CheckedSupplier<T, Exception> task) { if (shutdown) { throw new RejectedExecutionException("WrappingKeySerializingExecutor already shut down"); } SettableFuture<T> taskFinishedFuture = SettableFuture.create(); Runnable taskRunner = createFutureSettingTaskRunner(task, taskFinishedFuture); enqueueOrRunTask(taskRunner, getQueueForKey(key)); return taskFinishedFuture; } WrappingKeySerializingExecutor(ExecutorService executorService); @Override ListenableFuture<T> submit(String key, CheckedSupplier<T, Exception> task); @Override void shutdownAndAwaitTermination(long timeout, TimeUnit unit);  }### Answer:
@Test public void runsTasksSubmittedToItAndReturnsTheirResult() throws Exception { KeySerializingExecutor keySerializingExecutor = new WrappingKeySerializingExecutor(sameThreadExecutor()); context.checking(new Expectations() {{ oneOf(task).get(); will(returnValue(3)); }}); assertThat(keySerializingExecutor.submit("key", task), resultsIn(equalTo(3))); }
@Test public void returnsFuturesSetWithTheExceptionsThrownBySubmittedTasks() throws Exception { KeySerializingExecutor keySerializingExecutor = new WrappingKeySerializingExecutor(sameThreadExecutor()); context.checking(new Expectations() {{ oneOf(task).get(); will(throwException(new ArithmeticException("Expected as part of test"))); }}); assertThat(keySerializingExecutor.submit("key", task), resultsInException(ArithmeticException.class)); }
@Test public void submitsTasksOnceEachToTheSuppliedExecutorService() throws Exception { KeySerializingExecutor keySerializingExecutor = new WrappingKeySerializingExecutor(executorService); context.checking(new Expectations() {{ allowSubmitOrExecuteOnce(context, executorService); }}); keySerializingExecutor.submit("key", task); }