### Question:
ListTasksAPIController { @RequestMapping(value = "/forUser/{user:.+}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public List<AcmTask> tasksForUser( @PathVariable("user") String user, Authentication authentication, HttpSession session) throws AcmListObjectsFailedException { if (log.isInfoEnabled()) { log.info("Finding tasks assigned to user '" + user + "'"); } String ipAddress = (String) session.getAttribute("acm_ip_address"); try { List<AcmTask> retval = getTaskDao().tasksForUser(user); for (AcmTask task : retval) { AcmApplicationTaskEvent event = new AcmApplicationTaskEvent(task, "searchResult", authentication.getName(), true, ipAddress); getTaskEventPublisher().publishTaskEvent(event); } return retval; } catch (Exception e) { log.error("List Tasks Failed: " + e.getMessage(), e); throw new AcmListObjectsFailedException("task", e.getMessage(), e); } }  @RequestMapping(value = "/forUser/{user:.+}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody List<AcmTask> tasksForUser(
            @PathVariable("user") String user,
            Authentication authentication,
            HttpSession session); TaskDao getTaskDao(); void setTaskDao(TaskDao taskDao); TaskEventPublisher getTaskEventPublisher(); void setTaskEventPublisher(TaskEventPublisher taskEventPublisher);  }### Answer:
@Test public void tasksForUser() throws Exception { String user = "user"; AcmTask userTask = new AcmTask(); userTask.setTaskId(500L); userTask.setDueDate(new Date()); String ipAddress = "ipAddress"; expect(mockTaskDao.tasksForUser(user)).andReturn(Arrays.asList(userTask)); mockTaskEventPublisher.publishTaskEvent(anyObject(AcmApplicationTaskEvent.class)); mockHttpSession.setAttribute("acm_ip_address", ipAddress); expect(mockAuthentication.getName()).andReturn("user").atLeastOnce(); replayAll(); MvcResult result = mockMvc.perform( get("/api/v1/plugin/task/forUser/{user}", user) .accept(MediaType.parseMediaType("application/json;charset=UTF-8")) .principal(mockAuthentication) .session(mockHttpSession)) .andReturn(); verifyAll(); assertEquals(HttpStatus.OK.value(), result.getResponse().getStatus()); assertTrue(result.getResponse().getContentType().startsWith(MediaType.APPLICATION_JSON_VALUE)); String returned = result.getResponse().getContentAsString(); log.info("results: " + returned); ObjectMapper objectMapper = new ObjectMapper(); List<AcmTask> foundTasks = objectMapper.readValue(returned, objectMapper.getTypeFactory().constructParametricType(List.class, AcmTask.class)); assertEquals(1, foundTasks.size()); AcmTask found = foundTasks.get(0); assertEquals(userTask.getTaskId(), found.getTaskId()); }
@Test public void tasksForUser_exception() throws Exception { String user = "user"; String ipAddress = "ipAddress"; expect(mockTaskDao.tasksForUser(user)).andThrow(new PersistenceException("testMessage")); mockHttpSession.setAttribute("acm_ip_address", ipAddress); expect(mockAuthentication.getName()).andReturn("user"); replayAll(); mockMvc.perform( get("/api/v1/plugin/task/forUser/{user}", user) .accept(MediaType.parseMediaType("application/json;charset=UTF-8")) .principal(mockAuthentication) .session(mockHttpSession)) .andExpect(status().isInternalServerError()) .andExpect(content().contentType(MediaType.TEXT_PLAIN)); verifyAll(); }