### Question:
SystemConsole implements ConsoleDriver { public void write(String data) { System.out.print(data); }  String read(); void write(String data);  }### Answer:
@Test public void testWrite() throws Exception { PrintStream saveErr = System.err; PrintStream saveOut = System.out; ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = null; try { ps = new PrintStream(baos); System.setOut(ps); ConsoleDriver driver = new SystemConsole(); driver.write("The rain in Spain "); driver.write("falls mainly on the plain."); } finally { if (ps != null) { ps.close(); } System.setOut(saveErr); System.setOut(saveOut); } String text = new String(baos.toString()); assertEquals("wrong data", "The rain in Spain falls mainly on the plain.", text); }