### Question:
OcrExecutor extends ThreadPoolExecutor implements Executor { void setWaitingTime(long newTime) { waitingTimeInMillis = newTime; } OcrExecutor(int maxParallelThreads);   }### Answer:
@Test public void shouldWakeUpAfterClearingSpace() throws IOException, InterruptedException { when(processMock1.hasEnoughSpaceForExecution()).thenReturn(false, true); executorSut.setWaitingTime(10); executorSut.execute(processMock1); shutdownExecutor(); verify(processMock1).run(); }
@Test public void shouldWaitTooLong() throws IOException, InterruptedException { when(processMock1.hasEnoughSpaceForExecution()).thenReturn(false); executorSut.setWaitingTime(50); executorSut.execute(processMock1); shutdownExecutor(); verify(processMock1, never()).run(); }
@Test public void secondProcessShouldWakeTheFirst() throws IOException, InterruptedException { executorSut.setWaitingTime(VERY_LONG); when(processMock1.hasEnoughSpaceForExecution()).thenReturn(false, true); when(processMock2.hasEnoughSpaceForExecution()).thenReturn(true); executorSut.execute(processMock1); Thread.sleep(10); executorSut.execute(processMock2); shutdownExecutor(); verify(processMock1).run(); verify(processMock2).run(); }
@Test public void firstProcessShouldWakeTheSecond() throws IOException, InterruptedException { executorSut.setWaitingTime(VERY_LONG); when(processMock1.hasEnoughSpaceForExecution()).thenReturn(true); when(processMock2.hasEnoughSpaceForExecution()).thenReturn(false, true); doAnswer(withShortPause).when(processMock1).run(); executorSut.execute(processMock1); Thread.sleep(5); executorSut.execute(processMock2); shutdownExecutor(); verify(processMock1).run(); verify(processMock2).run(); }