PendingResponse { public void waitDone() throws ResponseTimeoutException, InvalidResponseException { lock.lock(); try { if (!isDoneResponse()) { try { condition.await(timeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { } } if (illegalResponseException != null) { throw illegalResponseException; } if (!isDoneResponse()) { throw new ResponseTimeoutException("No response after " + timeout + " millis"); } } finally { lock.unlock(); } } PendingResponse(long timeout); void done(T response); void doneWithInvalidResponse(InvalidResponseException e); T getResponse(); void waitDone();  }
@Test(groups="checkintest") public void testReachTimeout() { try { notifyDone(1010, pendingResponse); pendingResponse.waitDone(); fail("Timeout should be reached"); } catch (ResponseTimeoutException e) { } catch (InvalidResponseException e) { fail("Timeout should be reached"); } }
@Test(groups="checkintest") public void testUnreachTimeout() { try { notifyDone(90, pendingResponse); pendingResponse.waitDone(); } catch (ResponseTimeoutException e) { fail("Should be done with valid response"); } catch (InvalidResponseException e) { fail("Should be done with valid response"); } }