@Test(timeout = 5000)
public void testEndProcess() throws Exception {

  // Instantiate a new executor and start a new 'null' task ...
  final ThreadAsyncExecutor executor = new ThreadAsyncExecutor();
  final Object result = new Object();
  final Callable<Object> task = mock(Callable.class);
  when(task.call()).thenAnswer(i -> {
    Thread.sleep(1500);
    return result;
  });
  final AsyncResult<Object> asyncResult = executor.startProcess(task);
  assertNotNull(asyncResult);
  assertFalse(asyncResult.isCompleted());
  try {
    asyncResult.getValue();
    fail("Expected IllegalStateException when calling AsyncResult#getValue on a non-completed task");
  } catch (IllegalStateException e) {
    assertNotNull(e.getMessage());
  }
  assertSame(result, executor.endProcess(asyncResult));
  verify(task, times(1)).call();
  assertTrue(asyncResult.isCompleted());
  // Calling end process a second time while already finished should give the same result
  assertSame(result, executor.endProcess(asyncResult));
  verifyNoMoreInteractions(task);
}