PingServlet extends HttpServlet { @Override protected void service(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException { httpServletResponse.setStatus(SC_OK); httpServletResponse.setContentType(TEXT_PLAIN); httpServletResponse.getWriter().append(Integer.toString(SC_OK)); }    }
@Test public void pingResponse() throws Exception { when(response.getWriter()).thenReturn(writer); PingServlet pingServlet = new PingServlet(); pingServlet.service(request, response); verify(response).setStatus(SC_OK); verify(response).setContentType(TEXT_PLAIN); verify(writer).append(Integer.toString(SC_OK)); }