### Question:
Console implements Runnable { @Override public void run() { try { boolean running = true; do { sendPrompt(); String consoleLine = getUserInput(); try { running = handleUserInput(consoleLine); } catch (Exception e) { if (e instanceof NullPointerException) throw new IOException(e); output.println("That command failed. Type help to see options."); e.printStackTrace(output); } } while (running); } catch (IOException e) { output.println("Client parse command failed"); e.printStackTrace(output); } communications.stop(); } Console(Communications communications, Screen screen); InputStream getInput(); OutputStream getOutput(); OutputStream getError(); @Override void run(); void redraw();  }### Answer:
@Test public void testExitCommand() throws Exception { input.substitute("exit\n"); console.run(); assertEquals("client> ", outputStream.toString()); }
@Test public void testHelpCommand() throws Exception { input.substitute("help\nexit\n"); console.run(); assertEquals("client> help : display help.\n" + "send <dest address> <port> : send a message to the server/client.\n" + "exit : quit the client.\n" + "client> ", outputStream.toString()); }
@Test public void testSend() throws Exception { input.substitute("send 127.0.0.1 8080\ntoWhom\nThis is a message\nEOM\nexit\n"); RequestPacket requestPacket = RequestPacket.newMessage((PrivateKey) randomKey(), ((PrivateKey)randomKey()).toPublicKey(), "toWhom", name); requestPacket.setCommunications(communications); requestPacket.setMessage("This is the response"); communications.sendMessage("127.0.0.1", "8080", "This is a message\n", "toWhom"); replay(communications); console.run(); doMatch(outputStream, "client> Enter the name of the receiver \\(max 62 bytes\\): Enter a message \\(max 4096 bytes\\) followed by EOM on a blank line:\n" + "client> "); verify(communications); }