ThreadImpl { void execute(final ITask task) throws TaskExecutionException { if (!setTaskRef.compareAndSet(null, task)) { throw new TaskExecutionException("Another task is being executed."); } if (!thread.isAlive()) { throw new TaskExecutionException("Thread is dead."); } synchronized (this.lock) { this.lock.notifyAll(); } } ThreadImpl(final ThreadPool pool);   }
@Test public void Should_executeTaskInSeparateThread() throws Exception { ITask taskMock = mock(ITask.class); thread.execute(taskMock); verify(taskMock, timeout(1000)).execute(); }
@Test public void Should_ignoreExceptionsFromTask() throws Exception { ITask taskMock1 = mock(ITask.class), taskMock2 = mock(ITask.class); doThrow(new TaskExecutionException("Whoops!")).when(taskMock1).execute(); thread.execute(taskMock1); verify(taskMock1, timeout(100)).execute(); Thread.sleep(100); thread.execute(taskMock2); verify(taskMock2, timeout(100)).execute(); }