示例#1
0
  @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());
  }