BindRequestReceiver { BindRequest waitForRequest(long timeout) throws IllegalStateException, TimeoutException { lock.lock(); try { if (alreadyWaitForRequest) { throw new IllegalStateException("waitForRequest(long) method already invoked"); } else if (request == null) { try { requestCondition.await(timeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { } } if (request != null) { return request; } else { throw new TimeoutException("Wating for bind request take time too long"); } } finally { alreadyWaitForRequest = true; lock.unlock(); } } BindRequestReceiver(ServerResponseHandler responseHandler);   }
@Test(groups="checkintest") public void testWaitTimeout() { try { BindRequest request = requestReceiver.waitForRequest(1000); fail("Should fail since no request for 1000 millis"); } catch (IllegalStateException e) { e.printStackTrace(); fail("Should not fail waitForRequest"); } catch (TimeoutException e) { } }
@Test(groups="checkintest") public void testNonSingleWait() { try { BindRequest request = requestReceiver.waitForRequest(1000); fail("Should throw TimeoutException"); } catch (IllegalStateException e) { fail("Should throw TimeoutException"); } catch (TimeoutException e) { } try { requestReceiver.waitForRequest(1000); fail("Should throw IllegalStateException"); } catch (IllegalStateException e) { } catch (TimeoutException e) { fail("Should throw IllegalStateException"); } }