TextServer extends Thread { public void sendInput(final String input) throws IOException { final TextMessage message = TextMessage.newBuilder() .setType(TextMessageType.USER).setData(input) .setSequenceNumber(lastSequenceNumber++).build(); send(message); } TextServer(final String hostname, final int serverPort);  TextServer(final int serverPort); void setAutoAcknowledge(final boolean value); void addTextListener(final TextListener textListener); ConnectionInformation getConnectionInformation(); @Override void run(); boolean isStarted(); void acknowledge(final int seq); void waitStarted(); void waitConnected(); void sendInput(final String input); void stopServer(); boolean isConnected();  }
@Test(timeout = 5000) public void testSendInput() throws Exception { Assert.assertTrue(server.isStarted()); String input = "Test123"; final Thread thread = new Thread() { @Override public void run() { try { synchronized (lock) { lock.notifyAll(); } final InputStream in = socket.getInputStream(); System.out.println("1"); rcvd = TextMessage.parseDelimitedFrom(in); System.out.println(2); synchronized (lock) { lock.notifyAll(); } } catch (Exception e) { Assert.fail(e.getMessage()); } } }; thread.start(); synchronized (lock) { lock.wait(); } server.sendInput(input); if (thread.isAlive()) { synchronized (lock) { lock.wait(); } } final TextMessage message = TextMessage.newBuilder() .setType(TextMessageType.USER).setData(input) .setSequenceNumber(0).build(); Assert.assertEquals(message, rcvd); }