@Test public void findById_TodoEntryNotFound_ShouldReturnHttpStatusCodeNotFound() throws Exception { when(todoCrudServiceMock.findById(ID)).thenThrow(new TodoNotFoundException("")); mockMvc.perform(get("/api/todo/{id}", ID)) .andExpect(status().isNotFound()); verify(todoCrudServiceMock, times(1)).findById(ID); verifyNoMoreInteractions(todoCrudServiceMock); verifyZeroInteractions(todoSearchServiceMock); }
@RequestMapping(value = "/{id}", method = RequestMethod.GET) public TodoDTO findById(@PathVariable("id") Long id) { LOGGER.info("Finding todo entry with id: {}", id); TodoDTO found = crudService.findById(id); LOGGER.info("Found todo entry: {}", found); return found; }
TodoController { @RequestMapping(value = "/{id}", method = RequestMethod.GET) public TodoDTO findById(@PathVariable("id") Long id) { LOGGER.info("Finding todo entry with id: {}", id); TodoDTO found = crudService.findById(id); LOGGER.info("Found todo entry: {}", found); return found; } }
TodoController { @RequestMapping(value = "/{id}", method = RequestMethod.GET) public TodoDTO findById(@PathVariable("id") Long id) { LOGGER.info("Finding todo entry with id: {}", id); TodoDTO found = crudService.findById(id); LOGGER.info("Found todo entry: {}", found); return found; } @Autowired  TodoController(TodoCrudService crudService, TodoSearchService searchService); }
TodoController { @RequestMapping(value = "/{id}", method = RequestMethod.GET) public TodoDTO findById(@PathVariable("id") Long id) { LOGGER.info("Finding todo entry with id: {}", id); TodoDTO found = crudService.findById(id); LOGGER.info("Found todo entry: {}", found); return found; } @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(value = "/{id}", method = RequestMethod.GET) public TodoDTO findById(@PathVariable("id") Long id) { LOGGER.info("Finding todo entry with id: {}", id); TodoDTO found = crudService.findById(id); LOGGER.info("Found todo entry: {}", found); return found; } @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);  }