ThreadPool implements IThreadPool { @Override public boolean tryExecute(final ITask task) throws TaskExecutionException { ThreadImpl thread = threadsQueue.poll(); if (null != thread) { thread.execute(task); return true; } return false; } ThreadPool(final int threadCount); @Override boolean tryExecute(final ITask task); @Override void terminate();  }
@Test public void Should_executeTasksOnDifferentThreads() throws Exception { ITask sleepTask = new SleepingTask(); ITask task1 = spy(sleepTask), task2 = spy(sleepTask); ITask task3 = mock(ITask.class); assertTrue(threadPool.tryExecute(task1)); assertTrue(threadPool.tryExecute(task2)); assertFalse(threadPool.tryExecute(task3)); verify(task1, timeout(200)).execute(); verify(task1, timeout(100)).execute(); }