@Test public void findAll_NoTodoEntriesFound_ShouldReturnEmptyListAsJSonDocument() throws Exception { when(todoCrudServiceMock.findAll()).thenReturn(new ArrayList<TodoDTO>()); mockMvc.perform(get("/api/todo")) .andExpect(status().isOk()) .andExpect(content().contentType(WebTestConstants.APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$", hasSize(0))); verify(todoCrudServiceMock, times(1)).findAll(); verifyNoMoreInteractions(todoCrudServiceMock); verifyZeroInteractions(todoSearchServiceMock); }
@RequestMapping(method = RequestMethod.GET) public List<TodoDTO> findAll() { LOGGER.info("Finding all todo entries"); List<TodoDTO> todoEntries = crudService.findAll(); LOGGER.info("Found {} todo entries."); return todoEntries; }
TodoController { @RequestMapping(method = RequestMethod.GET) public List<TodoDTO> findAll() { LOGGER.info("Finding all todo entries"); List<TodoDTO> todoEntries = crudService.findAll(); LOGGER.info("Found {} todo entries."); return todoEntries; } }
TodoController { @RequestMapping(method = RequestMethod.GET) public List<TodoDTO> findAll() { LOGGER.info("Finding all todo entries"); List<TodoDTO> todoEntries = crudService.findAll(); LOGGER.info("Found {} todo entries."); return todoEntries; } @Autowired  TodoController(TodoCrudService crudService, TodoSearchService searchService); }
TodoController { @RequestMapping(method = RequestMethod.GET) public List<TodoDTO> findAll() { LOGGER.info("Finding all todo entries"); List<TodoDTO> todoEntries = crudService.findAll(); LOGGER.info("Found {} todo entries."); return todoEntries; } @Autowired  TodoController(TodoCrudService crudService, TodoSearchService searchService); @RequestMapping(method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) TodoDTO add(@RequestBody @Valid TodoDTO dto); @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) TodoDTO delete(@PathVariable("id") Long id); @RequestMapping(method = RequestMethod.GET) List<TodoDTO> findAll(); @RequestMapping(value = "/{id}", method = RequestMethod.GET) TodoDTO findById(@PathVariable("id") Long id); @RequestMapping(value = "/search", method = RequestMethod.GET) Page<TodoDTO> findBySearchTerm(@RequestParam("searchTerm") String searchTerm, Pageable pageable); @RequestMapping(value = "/{id}", method = RequestMethod.PUT) TodoDTO update(@PathVariable("id") Long id, @RequestBody @Valid TodoDTO dto); }
TodoController { @RequestMapping(method = RequestMethod.GET) public List<TodoDTO> findAll() { LOGGER.info("Finding all todo entries"); List<TodoDTO> todoEntries = crudService.findAll(); LOGGER.info("Found {} todo entries."); return todoEntries; } @Autowired  TodoController(TodoCrudService crudService, TodoSearchService searchService); @RequestMapping(method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) TodoDTO add(@RequestBody @Valid TodoDTO dto); @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) TodoDTO delete(@PathVariable("id") Long id); @RequestMapping(method = RequestMethod.GET) List<TodoDTO> findAll(); @RequestMapping(value = "/{id}", method = RequestMethod.GET) TodoDTO findById(@PathVariable("id") Long id); @RequestMapping(value = "/search", method = RequestMethod.GET) Page<TodoDTO> findBySearchTerm(@RequestParam("searchTerm") String searchTerm, Pageable pageable); @RequestMapping(value = "/{id}", method = RequestMethod.PUT) TodoDTO update(@PathVariable("id") Long id, @RequestBody @Valid TodoDTO dto);  }