SequenceResponseGuard { public void waitForResponses(final WilmaHttpRequest stubbedRequest, final WilmaSequence actualSequence) throws InterruptedException { String wilmaLoggerId = stubbedRequest.getWilmaMessageId(); boolean allResponsesArrived = actualSequence.checkIfAllResponsesArrived(wilmaLoggerId); int timeWaited = 0; getProperties(); int waitInterval = properties.getWaitInterval(); int timeout = properties.getTimeout(); while (!allResponsesArrived) { Thread.sleep(waitInterval); timeWaited += waitInterval; if (timeWaited > timeout) { throw new ResponseTimeoutException(TIMEOUT_ERROR_MESSAGE); } allResponsesArrived = actualSequence.checkIfAllResponsesArrived(wilmaLoggerId); } }  void waitForResponses(final WilmaHttpRequest stubbedRequest, final WilmaSequence actualSequence);  }
@Test(expectedExceptions = ResponseTimeoutException.class) public void testWhenResponsesCannotArriveInTimeThenExceptionIsThrown() throws InterruptedException { given(actualSequence.checkIfAllResponsesArrived(LOGGER_ID)).willReturn(false); underTest.waitForResponses(stubbedRequest, actualSequence); }
@Test public void testWaitForResponses() throws InterruptedException { given(actualSequence.checkIfAllResponsesArrived(LOGGER_ID)).willReturn(false, false, false, true); underTest.waitForResponses(stubbedRequest, actualSequence); verify(actualSequence, times(4)).checkIfAllResponsesArrived(LOGGER_ID); }