BlockLocalhostUsageStatusServlet extends HttpServlet { @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("application/json"); PrintWriter out = resp.getWriter(); boolean localhostModeSwitchedOn = localhostRequestProcessorToggle.isOn(); out.write("{\"localhostMode\":" + localhostModeSwitchedOn + "}"); out.flush(); out.close(); } @Autowired  BlockLocalhostUsageStatusServlet(LocalhostRequestProcessorToggle localhostRequestProcessorToggle);   }
@Test public void doGetShouldWriteJsonMessage() throws ServletException, IOException { given(resp.getWriter()).willReturn(printWriter); given(localhostRequestProcessorToggle.isOn()).willReturn(true); underTest.doGet(req, resp); verify(resp).setContentType("application/json"); verify(localhostRequestProcessorToggle).isOn(); verify(printWriter).write("{\"localhostMode\":true}"); }