### Question:
SingleThreadedForkChoiceExecutor implements ForkChoiceExecutor { @Override public <T> SafeFuture<T> performTask(final ForkChoiceTask<T> task) { final SafeFuture<T> result = new SafeFuture<>(); try { executor.execute(() -> syncPerformTask(task).propagateTo(result)); } catch (final RejectedExecutionException e) { if (stopped.get()) { LOG.debug("Ignoring fork choice task because shutdown is in progress"); } else { result.completeExceptionally(e); } } catch (final Throwable t) { result.completeExceptionally(t); } return result; } private  SingleThreadedForkChoiceExecutor(final ExecutorService executor); static ForkChoiceExecutor create(); @Override SafeFuture<T> performTask(final ForkChoiceTask<T> task); @Override void stop();  }### Answer:
@Test void shouldPerformTasks() throws Exception { final StubTask task = new StubTask(); final SafeFuture<String> result = executor.performTask(task); task.assertStarted(); assertThat(result).isNotDone(); task.result.complete("Done"); Waiter.waitFor(result); assertThat(result).isCompletedWithValue("Done"); }
@Test void shouldNotExecuteNextTaskUntilFirstIsComplete() throws Exception { final StubTask task1 = new StubTask(); final StubTask task2 = new StubTask(); final SafeFuture<String> result1 = executor.performTask(task1); final SafeFuture<String> result2 = executor.performTask(task2); task1.assertStarted(); assertThat(task2.started).isFalse(); task1.result.complete("Foo"); Waiter.waitFor(result1); task2.assertStarted(); task2.result.complete("Bar"); Waiter.waitFor(result2); assertThat(result1).isCompletedWithValue("Foo"); assertThat(result2).isCompletedWithValue("Bar"); }
@Test void shouldReportExceptionWhenTaskFails() { final StubTask task = new StubTask(); final SafeFuture<String> result = executor.performTask(task); final RuntimeException error = new RuntimeException("Failed"); task.result.completeExceptionally(error); Waiter.waitFor(result::isCompletedExceptionally); assertThatSafeFuture(result).isCompletedExceptionallyWith(error); }