### Question:
ConsoleHandler extends Handler { @Override public void publish(LogRecord record) { if (record.getLevel().intValue() >= Level.WARNING.intValue()) { stderrHandler.publish(record); stderrHandler.flush(); } else { stdoutHandler.publish(record); stdoutHandler.flush(); } } ConsoleHandler(); @Override synchronized void setFormatter(Formatter newFormatter); @Override synchronized void setEncoding(String encoding); @Override void publish(LogRecord record); @Override void flush(); @Override void close();  }### Answer:
@Test public void testPublish() { ByteArrayOutputStream baosOut = new ByteArrayOutputStream(); System.setOut(new PrintStream(baosOut)); ByteArrayOutputStream baosErr = new ByteArrayOutputStream(); System.setErr(new PrintStream(baosErr)); CspFormatter cspFormatter = new CspFormatter(); ConsoleHandler consoleHandler = new ConsoleHandler(); LogRecord logRecord; logRecord = new LogRecord(Level.INFO, "test info message"); consoleHandler.publish(logRecord); assertEquals(cspFormatter.format(logRecord), baosOut.toString()); assertEquals("", baosErr.toString()); baosOut.reset(); baosErr.reset(); logRecord = new LogRecord(Level.WARNING, "test warning message"); consoleHandler.publish(logRecord); assertEquals(cspFormatter.format(logRecord), baosErr.toString()); assertEquals("", baosOut.toString()); baosOut.reset(); baosErr.reset(); logRecord = new LogRecord(Level.FINE, "test fine message"); consoleHandler.publish(logRecord); assertEquals("", baosOut.toString()); assertEquals("", baosErr.toString()); baosOut.reset(); baosErr.reset(); logRecord = new LogRecord(Level.SEVERE, "test severe message"); consoleHandler.publish(logRecord); assertEquals(cspFormatter.format(logRecord), baosErr.toString()); assertEquals("", baosOut.toString()); baosOut.reset(); baosErr.reset(); }