### Question:
ServerReceiver implements Receiver { public Message waitForMessage() throws CommunicationException { try { return m_messageQueue.dequeue(true); } catch (MessageQueue.ShutdownException e) { return null; } }  void receiveFrom(Acceptor acceptor,
                          ConnectionType[] connectionTypes,
                          int numberOfThreads,
                          final long idleThreadPollDelay,
                          final long inactiveClientTimeOut); Message waitForMessage(); synchronized void shutdown();  }### Answer:
@Test public void testWaitForMessage() throws Exception { final Acceptor acceptor = new Acceptor("localhost", 0, 1, m_timeAuthority); final ServerReceiver serverReceiver = new ServerReceiver(); serverReceiver.receiveFrom( acceptor, new ConnectionType[] { ConnectionType.AGENT }, 3, 10, 99); final Socket[] socket = new Socket[5]; for (int i=0; i<socket.length; ++i) { socket[i] = new Connector(InetAddress.getByName(null).getHostName(), acceptor.getPort(), ConnectionType.AGENT) .connect(); } final ResourcePool socketSet = acceptor.getSocketSet(ConnectionType.AGENT); for (int i=0; socketSet.countActive() != 5 && i<10; ++i) { Thread.sleep(i * i * 10); } final SimpleMessage message1 = new SimpleMessage(); final SimpleMessage message2 = new SimpleMessage(); final SimpleMessage message3 = new SimpleMessage(); final ObjectOutputStream objectStream1 = new ObjectOutputStream(socket[0].getOutputStream()); objectStream1.writeObject(message1); objectStream1.flush(); final ObjectOutputStream objectStream2 = new ObjectOutputStream(socket[1].getOutputStream()); objectStream2.writeObject(message2); objectStream2.flush(); final ObjectOutputStream objectStream3 = new ObjectOutputStream(socket[0].getOutputStream()); objectStream3.writeObject(message3); objectStream3.flush(); Message receivedMessage1 = serverReceiver.waitForMessage(); Message receivedMessage2 = serverReceiver.waitForMessage(); Message receivedMessage3 = serverReceiver.waitForMessage(); assertEquals( UncheckedInterruptedException.class, new BlockingActionThread() { protected void blockingAction() throws CommunicationException { serverReceiver.waitForMessage(); } }.getException().getClass()); if (receivedMessage1.equals(message2)) { final Message temp = receivedMessage2; receivedMessage2 = receivedMessage1; receivedMessage1 = temp; } else if (receivedMessage3.equals(message2)) { final Message temp = receivedMessage3; receivedMessage3 = receivedMessage2; receivedMessage2 = temp; } else { assertEquals(message2, receivedMessage2); } assertEquals(message1, receivedMessage1); assertEquals(message2, receivedMessage2); assertEquals(message3, receivedMessage3); serverReceiver.shutdown(); acceptor.shutdown(); }