private void printThreadStatus(Thread thread) {
    StackTraceElement[] frames = thread.getStackTrace();

    System.err.println(thread.getName() + ": " + thread.getState());

    for (StackTraceElement frame : frames) {
      System.err.println(frame);
    }

    System.err.println();
  }
  @Test
  public void execute_shouldCreateAndStartAThreadWithTheProvidedRunnableAndReturnAFuture()
      throws Exception {
    CountDownLatch latch = new CountDownLatch(1);

    Future<?> result = asyncExecutor.execute(latch::countDown);
    latch.await(5, TimeUnit.SECONDS); // give the new thread time to start to running

    verify(factory).newThread(any()); // The provided runnable will be wrapped, not passed directly
    assertEquals(0, latch.getCount()); // but the runnable will be executed
    assertNotNull(result);
    assertNotNull(createdThread);
    assertNotEquals(Thread.State.NEW, createdThread.getState());
  }
    public void mockAll() {
      mockedConfigurationUpdateThread = mock(Thread.class);
      when(mockedConfigurationUpdateThread.getState()).thenReturn(Thread.State.TERMINATED);

      eventManager = mock(EventService.class);
      when(powerApiServletContext.eventService()).thenReturn(eventManager);

      threadManager = mock(ThreadingService.class);
      when(threadManager.newThread(any(Runnable.class), anyString()))
          .thenReturn(mockedConfigurationUpdateThread);
      when(powerApiServletContext.threadingService()).thenReturn(threadManager);

      // Setup our context with the mocks
      when(context.getAttribute(ServletContextHelper.SERVLET_CONTEXT_ATTRIBUTE_NAME))
          .thenReturn(powerApiServletContext);
      when(context.getInitParameter(InitParameter.POWER_API_CONFIG_DIR.getParameterName()))
          .thenReturn("/etc/powerapi");
    }