BaseServlet extends SlingAllMethodsServlet { protected void writeResult(SlingHttpServletResponse response, String json, int status) throws IOException { response.setContentType("application/json"); response.setCharacterEncoding("utf-8"); response.setStatus(status); response.getWriter().write(json); }    }
@Test public void writeResult_ok() throws IOException { servlet.writeResult(response, "test"); verify(response, times(1)).setStatus(HttpServletResponse.SC_OK); verify(writer, times(1)).write("test"); }
@Test public void writeResult_status() throws IOException { servlet.writeResult(response, "test", HttpServletResponse.SC_BAD_GATEWAY); verify(response, times(1)).setStatus(HttpServletResponse.SC_BAD_GATEWAY); verify(writer, times(1)).write("test"); }