### Question:
AsyncCallback { public AsyncCallback(long timeout) { _logger.info("Setting time out to " + timeout + " ms"); _timeout = timeout; } AsyncCallback(long timeout);  AsyncCallback(); final void setTimeout(long timeout); List<Message> getMessageReplied(); boolean isInterrupted(); void setInterrupted(boolean b); synchronized final void onReply(Message message); boolean isDone(); boolean isTimedOut(); abstract void onTimeOut(); abstract void onReplyMessage(Message message);  }### Answer:
@Test() public void testAsyncCallback() throws Exception { System.out.println("START TestAsyncCallback at " + new Date(System.currentTimeMillis())); AsyncCallbackSample callback = new AsyncCallbackSample(); AssertJUnit.assertFalse(callback.isInterrupted()); AssertJUnit.assertFalse(callback.isTimedOut()); AssertJUnit.assertTrue(callback.getMessageReplied().size() == 0); int nMsgs = 5; List<Message> messageSent = new ArrayList<Message>(); for (int i = 0; i < nMsgs; i++) { messageSent.add(new Message("Test", UUID.randomUUID().toString())); } callback.setMessagesSent(messageSent); for (int i = 0; i < nMsgs; i++) { AssertJUnit.assertFalse(callback.isDone()); callback.onReply(new Message("TestReply", UUID.randomUUID().toString())); } AssertJUnit.assertTrue(callback.isDone()); AssertJUnit.assertTrue(callback._onTimeOutCalled == 0); sleep(50); callback = new AsyncCallbackSample(); callback.setMessagesSent(messageSent); callback.setTimeout(1000); sleep(50); callback.startTimer(); AssertJUnit.assertFalse(callback.isTimedOut()); for (int i = 0; i < nMsgs - 1; i++) { sleep(50); AssertJUnit.assertFalse(callback.isDone()); AssertJUnit.assertTrue(callback._onReplyMessageCalled == i); callback.onReply(new Message("TestReply", UUID.randomUUID().toString())); } sleep(1000); AssertJUnit.assertTrue(callback.isTimedOut()); AssertJUnit.assertTrue(callback._onTimeOutCalled == 1); AssertJUnit.assertFalse(callback.isDone()); callback = new AsyncCallbackSample(); callback.setMessagesSent(messageSent); callback.setTimeout(1000); callback.startTimer(); sleep(50); AssertJUnit.assertFalse(callback.isTimedOut()); for (int i = 0; i < nMsgs; i++) { AssertJUnit.assertFalse(callback.isDone()); sleep(50); AssertJUnit.assertTrue(callback._onReplyMessageCalled == i); callback.onReply(new Message("TestReply", UUID.randomUUID().toString())); } AssertJUnit.assertTrue(callback.isDone()); sleep(1300); AssertJUnit.assertFalse(callback.isTimedOut()); AssertJUnit.assertTrue(callback._onTimeOutCalled == 0); System.out.println("END TestAsyncCallback at " + new Date(System.currentTimeMillis())); }