@Test public void test() throws ServletException, IOException { HttpServletResponse resp = Mockito.mock(HttpServletResponse.class); StringWriter sw = new StringWriter(); Mockito.when(resp.getWriter()).thenReturn(new PrintWriter(sw)); new PingServlet().doGet(null, resp); String s = sw.toString(); assertNotNull(s); long parsedTimestamp = Long.parseLong(s); assertTrue(new Date().getTime() >= parsedTimestamp); }
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.getWriter().write(String.valueOf(new Date().getTime())); }
PingServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.getWriter().write(String.valueOf(new Date().getTime())); } }
PingServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.getWriter().write(String.valueOf(new Date().getTime())); }  }
PingServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.getWriter().write(String.valueOf(new Date().getTime())); }   }
PingServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.getWriter().write(String.valueOf(new Date().getTime())); }    }