### Question:
AbstractServlet extends HttpServlet { protected ScheduledTime getRequestTime(HttpServletRequest req) { String t = req.getParameter(CelosClient.TIME_PARAM); if (t == null) { return new ScheduledTime(DateTime.now(DateTimeZone.UTC)); } else { return new ScheduledTime(t); } }  @Override void service(HttpServletRequest req, HttpServletResponse res); static final String SCHEDULER_ATTR; }### Answer:
@Test public void getRequestTimeParameterWorks() { @SuppressWarnings("serial") AbstractServlet srv = new AbstractServlet() {}; HttpServletRequest req = Mockito.mock(HttpServletRequest.class); String timeString = "2013-12-18T20:00Z"; Mockito.when(req.getParameter("time")).thenReturn(timeString); Assert.assertEquals(new ScheduledTime(timeString), srv.getRequestTime(req)); }
@Test public void getRequestTimeUsesCurrentTimeWhenNotSupplied() { @SuppressWarnings("serial") AbstractServlet srv = new AbstractServlet() {}; HttpServletRequest req = Mockito.mock(HttpServletRequest.class); ScheduledTime before = new ScheduledTime(DateTime.now(DateTimeZone.UTC)); Mockito.when(req.getParameter("time")).thenReturn(null); ScheduledTime t = srv.getRequestTime(req); ScheduledTime after = new ScheduledTime(DateTime.now(DateTimeZone.UTC)); Assert.assertTrue(before.compareTo(t) <= 0); Assert.assertTrue(t.compareTo(after) <= 0); }