StreamHttpLogWriter implements HttpLogWriter { @Override public void write(final Precorrelation precorrelation, final String request) throws IOException { stream.println(request); } StreamHttpLogWriter();  StreamHttpLogWriter(final PrintStream stream); @Override void write(final Precorrelation precorrelation, final String request); @Override void write(final Correlation correlation, final String response);  }
@Test void shouldLogRequestToStream() throws IOException { final PrintStream stream = mock(PrintStream.class); final HttpLogWriter unit = new StreamHttpLogWriter(stream); unit.write(new SimplePrecorrelation("", Clock.systemUTC()), "foo"); verify(stream).println("foo"); }
@Test void shouldLogResponseToStream() throws IOException { final PrintStream stream = mock(PrintStream.class); final HttpLogWriter unit = new StreamHttpLogWriter(stream); unit.write(new SimpleCorrelation("1", MIN, MIN), "bar"); verify(stream).println("bar"); }
@Test void shouldRequestToStdoutByDefault() throws IOException { final PrintStream original = System.out; final PrintStream stream = mock(PrintStream.class); System.setOut(stream); try { final HttpLogWriter unit = new StreamHttpLogWriter(); unit.write(new SimplePrecorrelation("", Clock.systemUTC()), "foo"); verify(stream).println("foo"); } finally { System.setOut(original); } }
@Test void shouldResponseToStdoutByDefault() throws IOException { final PrintStream original = System.out; final PrintStream stream = mock(PrintStream.class); System.setOut(stream); try { final HttpLogWriter unit = new StreamHttpLogWriter(); unit.write(new SimpleCorrelation("1", MIN, MIN), "bar"); verify(stream).println("bar"); } finally { System.setOut(original); } }