DateTimeAgent extends AbstractAgent { @Override public AgentResponse process(AgentRequest request) { logger.debug("Handling the request: " + request.getText()); Date now = new Date(); AgentResponse response; String requestType = getRequestType(request.getText()); switch (requestType) { case DATE: response = new AgentResponse(getDate(now)); break; case DAY: response = new AgentResponse(getDay(now)); break; case TIME: response = new AgentResponse(getTime(now)); break; default: response = new AgentResponse(ResponseStatus.Code.AGENT_DID_NOT_UNDERSTAND_REQUEST); break; } return response; } DateTimeAgent(); @Override AgentResponse process(AgentRequest request);  }
@Test public void testBadRequest() { AgentResponse response = agent.process(new AgentRequest("where is pluto?")); assertNotNull(response); assertFalse(response.isSuccess()); assertEquals(ResponseStatus.Code.AGENT_DID_NOT_UNDERSTAND_REQUEST, response.getStatus().getCode()); }
@Test public void testProcessForDayOfWeek() { AgentResponse response = agent.process(new AgentRequest("what is today?")); assertNotNull(response); assertTrue(response.isSuccess()); Set<String> daysOfWeek = new HashSet<String>(Arrays.asList("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")); assertTrue(daysOfWeek.contains(response.getText())); }