### Question:
SystemConsole implements ConsoleDriver { public String read() { StringBuilder sb = new StringBuilder(); try { char chr = (char)System.in.read(); while (chr != 13) { sb.append(chr); chr = (char)System.in.read(); } System.in.read(); } catch (IOException e) { } return sb.toString(); }  String read(); void write(String data);  }### Answer:
@Test public void testRead() throws Exception { InputStream saveIn = System.in; ByteArrayInputStream bais = new ByteArrayInputStream("Hello, world.\r".getBytes("utf-8")); String data = null; try { System.setIn(bais); ConsoleDriver driver = new SystemConsole(); data = driver.read(); } finally { System.setIn(saveIn); } assertNotNull("should have data", data); assertEquals("wrong data", "Hello, world.", data); }