@Test public void shouldReturnEmptyListForUsersWithoutAccess() throws Exception { when(motechUserService.getUsers()).thenThrow(new AccessDeniedException("denied")); controller.perform(get("/users")) .andExpect(status().isOk()) .andExpect(content().string("[]")); }
@RequestMapping(value = "/users", method = RequestMethod.GET) @ResponseBody public List<MotechUserProfile> getUsers() { try { return motechUserService.getUsers(); } catch (AccessDeniedException e) { LOGGER.debug("Access denied for user list retrieval, returning empty list", e); return Collections.emptyList(); } }
UserController { @RequestMapping(value = "/users", method = RequestMethod.GET) @ResponseBody public List<MotechUserProfile> getUsers() { try { return motechUserService.getUsers(); } catch (AccessDeniedException e) { LOGGER.debug("Access denied for user list retrieval, returning empty list", e); return Collections.emptyList(); } } }
UserController { @RequestMapping(value = "/users", method = RequestMethod.GET) @ResponseBody public List<MotechUserProfile> getUsers() { try { return motechUserService.getUsers(); } catch (AccessDeniedException e) { LOGGER.debug("Access denied for user list retrieval, returning empty list", e); return Collections.emptyList(); } }  }
UserController { @RequestMapping(value = "/users", method = RequestMethod.GET) @ResponseBody public List<MotechUserProfile> getUsers() { try { return motechUserService.getUsers(); } catch (AccessDeniedException e) { LOGGER.debug("Access denied for user list retrieval, returning empty list", e); return Collections.emptyList(); } }  @RequestMapping(value = "/users", method = RequestMethod.GET) @ResponseBody List<MotechUserProfile> getUsers(); }
UserController { @RequestMapping(value = "/users", method = RequestMethod.GET) @ResponseBody public List<MotechUserProfile> getUsers() { try { return motechUserService.getUsers(); } catch (AccessDeniedException e) { LOGGER.debug("Access denied for user list retrieval, returning empty list", e); return Collections.emptyList(); } }  @RequestMapping(value = "/users", method = RequestMethod.GET) @ResponseBody List<MotechUserProfile> getUsers();  }