@Test public void shouldWriteContentToResponse() throws ServletException, IOException { when(contentProvider.getContent()).thenReturn("JSON"); when(resp.getWriter()).thenReturn(responseWriter); servlet.doGet(req, resp); verify(resp).getWriter(); verify(responseWriter).write(eq("JSON")); }
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { String result = contentProvider.getContent(); resp.setContentType("application/json"); resp.getWriter().write(result); } catch (IOException e) { resp.setStatus(500); resp.setContentType("application/json"); resp.getWriter().write("{\"error\":\"" + e.getMessage() + "\"}"); } }
MaintenanceStatusServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { String result = contentProvider.getContent(); resp.setContentType("application/json"); resp.getWriter().write(result); } catch (IOException e) { resp.setStatus(500); resp.setContentType("application/json"); resp.getWriter().write("{\"error\":\"" + e.getMessage() + "\"}"); } } }
MaintenanceStatusServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { String result = contentProvider.getContent(); resp.setContentType("application/json"); resp.getWriter().write(result); } catch (IOException e) { resp.setStatus(500); resp.setContentType("application/json"); resp.getWriter().write("{\"error\":\"" + e.getMessage() + "\"}"); } } @Inject  MaintenanceStatusServlet(StatusPageContentProvider contentProvider); }
MaintenanceStatusServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { String result = contentProvider.getContent(); resp.setContentType("application/json"); resp.getWriter().write(result); } catch (IOException e) { resp.setStatus(500); resp.setContentType("application/json"); resp.getWriter().write("{\"error\":\"" + e.getMessage() + "\"}"); } } @Inject  MaintenanceStatusServlet(StatusPageContentProvider contentProvider);  }
MaintenanceStatusServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { String result = contentProvider.getContent(); resp.setContentType("application/json"); resp.getWriter().write(result); } catch (IOException e) { resp.setStatus(500); resp.setContentType("application/json"); resp.getWriter().write("{\"error\":\"" + e.getMessage() + "\"}"); } } @Inject  MaintenanceStatusServlet(StatusPageContentProvider contentProvider);   }