InvalidRequestServlet extends HttpServlet { @Override protected void service(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException { httpServletResponse.setStatus(SC_NOT_FOUND); httpServletResponse.setContentType(TEXT_PLAIN); httpServletResponse.setContentType(UTF_8.name()); httpServletResponse.getWriter().append(Integer.toString(SC_NOT_FOUND)); }    }
@Test public void testService() throws Exception { when(httpServletResponse.getWriter()).thenReturn(printWriter); invalidRequestServlet.service(httpServletRequest, httpServletResponse); verify(httpServletResponse).setStatus(SC_NOT_FOUND); verify(httpServletResponse).setContentType(MediaType.TEXT_PLAIN); verify(httpServletResponse).setContentType(UTF_8.name()); verify(printWriter).append(Integer.toString(SC_NOT_FOUND)); }