OutputMessageBuffer implements TextListener { public SsmlDocument nextMessage() throws InterruptedException, JVoiceXMLEvent, IOException { final BufferedSsmlDocument buffer = documents.take(); if (event != null) { throw event; } final TextMessage message = buffer.getTextMessage(); acknowledge(message); if (message.getType() == TextMessageType.BYE) { throw new ConnectionDisconnectHangupEvent(); } return buffer.getDocument(); } OutputMessageBuffer(final TextServer textServer); SsmlDocument nextMessage(); SsmlDocument nextMessage(final long timeout); @Override void started(); @Override void connected(final InetSocketAddress remote); @Override void outputSsml(final TextMessageEvent evt,
            final SsmlDocument document); @Override void expectingInput(final TextMessageEvent evt); @Override void inputClosed(final TextMessageEvent evt); @Override void disconnected(final TextMessageEvent evt); boolean hasReceivedDisconnect(); void acknowledgeBye();  }
@Test public void testNextMessage() throws Exception, JVoiceXMLEvent { final TextServer server = new TextServer(9494); final OutputMessageBuffer buffer = new OutputMessageBuffer(server); final SsmlDocument document = new SsmlDocument(); final Speak speak = document.getSpeak(); speak.addText("hello world"); final Runnable runnable = new Runnable() { @Override public void run() { buffer.outputSsml(null, document); } }; final Thread thread = new Thread(runnable); thread.start(); final SsmlDocument next = buffer.nextMessage(); Assert.assertEquals(document, next); }