LoggingServlet extends HttpServlet { @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { log.info("An informational message."); log.warning("A warning message."); log.severe("An error message."); resp.setContentType("text/plain"); resp.getWriter().println("Check logs for results"); }  @Override void doGet(HttpServletRequest req, HttpServletResponse resp);  }
@Test public void testListLogs() throws Exception { servletUnderTest.doGet(mockRequest, mockResponse); String out = stderr.toString(); assertThat(out).contains("An informational message."); assertThat(out).contains("A warning message."); assertThat(out).contains("An error message."); }