MarcFeedback extends Thread { @Override public void run() { try { final byte[] buffer = new byte[BUFFER_SIZE]; final ByteArrayOutputStream out = new ByteArrayOutputStream(); while (true) { final DatagramPacket packet = new DatagramPacket(buffer, buffer.length); socket.receive(packet); out.write(buffer, 0, packet.getLength()); final String response = out.toString(); LOGGER.info("received from MARC: '" + response + "'"); try { final String id = parseId(response); if (isEndOfSpeech(id)) { output.playEnded(id); } } catch (TransformerException e) { LOGGER.warn("error parsing the response from MARC", e); } finally { out.reset(); } } } catch (IOException e) { LOGGER.error(e.getMessage(), e); } finally { if (socket != null) { socket.close(); } } } MarcFeedback(final MarcSynthesizedOutput marcOutput,
            final int portNumber); @Override void run();  }
@Test public void testRun() throws Exception, JVoiceXMLEvent { final MarcSynthesizedOutput output = new MarcSynthesizedOutput(); output.connect(null); output.addListener(this); final SpeakableText speakable = new SpeakableSsmlText("test", Locale.US); final String sessionId = UUID.randomUUID().toString(); output.queueSpeakable(speakable, sessionId, null); final MarcFeedback feedback = new MarcFeedback(output, 4011); final DatagramSocket server = new DatagramSocket(4012); feedback.start(); Thread.sleep(1000); final String msg = "<event id=\"JVoiceXMLTrack:end\"/>"; final byte[] buf = msg.getBytes(); final InetAddress address = Inet4Address.getLocalHost(); final DatagramPacket packet = new DatagramPacket(buf, buf.length, address, 4011); server.send(packet); final String msg2 = "<event id=\"SpeechCommand:end\"/>"; final byte[] buf2 = msg2.getBytes(); final DatagramPacket packet2 = new DatagramPacket(buf2, buf2.length, address, 4011); server.send(packet2); synchronized (lock) { lock.wait(); } Assert.assertTrue(event instanceof OutputEndedEvent); final OutputEndedEvent endedEvent = (OutputEndedEvent) event; Assert.assertEquals(speakable, endedEvent.getSpeakable()); }