@Test
public void testAutomaticStartStop() throws Exception {

    final TestRunnable task = new TestRunnable(500);
    e.execute(task);
    // Ensure the new thread has started.
    Thread thread = e.thread;
    assertThat(thread, is(not(nullValue())));
    assertThat(thread.isAlive(), is(true));
    Thread.sleep(1500);
    // Ensure the thread stopped itself after running the task.
    assertThat(thread.isAlive(), is(false));
    assertThat(task.ran.get(), is(true));
    // Ensure another new thread starts again.
    task.ran.set(false);
    e.execute(task);
    assertThat(e.thread, not(sameInstance(thread)));
    thread = e.thread;
    Thread.sleep(1500);
    // Ensure the thread stopped itself after running the task.
    assertThat(thread.isAlive(), is(false));
    assertThat(task.ran.get(), is(true));
}