### Question:
FlatLogListener implements LogListener, Configurable, Destroyable { @Override public synchronized LogEvent log(LogEvent ev) { ev.dump(p, ""); byte[] result = mapper.apply(captureStream.toByteArray()); captureStream.reset(); return new FrozenLogEvent(new String(result)); }  @Override void setConfiguration(Configuration cfg); @Override synchronized LogEvent log(LogEvent ev); @Override void destroy();  }### Answer:
@Test void testLog() throws IOException { FlatLogListener listener = new FlatLogListener(); LogEvent ev = new LogEvent(); ev.setNoArmor(true); ev.addMessage("Test"); ev.addMessage("More"); LogEvent r = listener.log(ev); ByteArrayOutputStream captureStream = new ByteArrayOutputStream(); PrintStream capturePrintStream = new PrintStream(captureStream); r.dump(capturePrintStream, ""); BufferedReader reader = new BufferedReader( new InputStreamReader(new ByteArrayInputStream(captureStream.toByteArray()))); assertEquals(" <info> Test More </info>", reader.readLine()); capturePrintStream.close(); reader.close(); }
@Test void testLogCorrectlyMultipleEventsAKACaptureStreamResets() throws IOException { FlatLogListener listener = new FlatLogListener(); LogEvent ev = new LogEvent(); ev.setNoArmor(true); ev.addMessage("Test"); ev.addMessage("More"); LogEvent r = listener.log(ev); ByteArrayOutputStream captureStream = new ByteArrayOutputStream(); PrintStream capturePrintStream = new PrintStream(captureStream); r.dump(capturePrintStream, ""); BufferedReader reader = new BufferedReader( new InputStreamReader(new ByteArrayInputStream(captureStream.toByteArray()))); captureStream.reset(); assertEquals(" <info> Test More </info>", reader.readLine()); assertFalse(reader.ready()); reader.close(); r = listener.log(ev); r.dump(capturePrintStream, ""); reader = new BufferedReader( new InputStreamReader(new ByteArrayInputStream(captureStream.toByteArray()))); assertEquals(" <info> Test More </info>", reader.readLine()); assertFalse(reader.ready()); capturePrintStream.close(); reader.close(); }