@Test(expected = TodoNotFoundException.class) public void findById_TodoIsNotFound_ShouldThrowException() throws TodoNotFoundException { when(serviceMock.findById(TodoTestUtil.ID)).thenThrow(new TodoNotFoundException("")); controller.findById(TodoTestUtil.ID); verify(serviceMock, times(1)).findById(TodoTestUtil.ID); verifyNoMoreInteractions(serviceMock); verifyZeroInteractions(localeHolderWrapperMock, messageSourceMock); }
@RequestMapping(value = "/api/todo/{id}", method = RequestMethod.GET) @ResponseBody public TodoDTO findById(@PathVariable("id") Long id) throws TodoNotFoundException { LOGGER.debug("Finding to-do entry with id: {}", id); Todo found = service.findById(id); LOGGER.debug("Found to-do entry with information: {}", found); return createDTO(found); }
TodoController { @RequestMapping(value = "/api/todo/{id}", method = RequestMethod.GET) @ResponseBody public TodoDTO findById(@PathVariable("id") Long id) throws TodoNotFoundException { LOGGER.debug("Finding to-do entry with id: {}", id); Todo found = service.findById(id); LOGGER.debug("Found to-do entry with information: {}", found); return createDTO(found); } }
TodoController { @RequestMapping(value = "/api/todo/{id}", method = RequestMethod.GET) @ResponseBody public TodoDTO findById(@PathVariable("id") Long id) throws TodoNotFoundException { LOGGER.debug("Finding to-do entry with id: {}", id); Todo found = service.findById(id); LOGGER.debug("Found to-do entry with information: {}", found); return createDTO(found); }  }
TodoController { @RequestMapping(value = "/api/todo/{id}", method = RequestMethod.GET) @ResponseBody public TodoDTO findById(@PathVariable("id") Long id) throws TodoNotFoundException { LOGGER.debug("Finding to-do entry with id: {}", id); Todo found = service.findById(id); LOGGER.debug("Found to-do entry with information: {}", found); return createDTO(found); }  @RequestMapping(value = "/api/todo", method = RequestMethod.POST) @ResponseBody TodoDTO add(@RequestBody TodoDTO dto); @RequestMapping(value = "/api/todo/search/count/{searchTerm}", method = RequestMethod.GET) @ResponseBody long countSearchResults(@PathVariable("searchTerm") String searchTerm); @RequestMapping(value = "/api/todo/{id}", method = RequestMethod.DELETE) @ResponseBody TodoDTO deleteById(@PathVariable("id") Long id); @RequestMapping(value = "/api/todo", method = RequestMethod.GET) @ResponseBody List<TodoDTO> findAll(); @RequestMapping(value = "/api/todo/{id}", method = RequestMethod.GET) @ResponseBody TodoDTO findById(@PathVariable("id") Long id); @RequestMapping(value = "/api/todo/{id}", method = RequestMethod.PUT) @ResponseBody TodoDTO update(@RequestBody TodoDTO dto, @PathVariable("id") Long todoId); @ExceptionHandler(FormValidationError.class) @ResponseBody @ResponseStatus(HttpStatus.BAD_REQUEST) FormValidationErrorDTO handleFormValidationError(FormValidationError validationError); @RequestMapping(value = "/api/todo/search/{searchTerm}", method = RequestMethod.GET) @ResponseBody List<TodoDTO> search(@PathVariable("searchTerm") String searchTerm, Pageable page); @ExceptionHandler(TodoNotFoundException.class) @ResponseStatus(HttpStatus.NOT_FOUND) void handleTodoNotFoundException(TodoNotFoundException ex); }
TodoController { @RequestMapping(value = "/api/todo/{id}", method = RequestMethod.GET) @ResponseBody public TodoDTO findById(@PathVariable("id") Long id) throws TodoNotFoundException { LOGGER.debug("Finding to-do entry with id: {}", id); Todo found = service.findById(id); LOGGER.debug("Found to-do entry with information: {}", found); return createDTO(found); }  @RequestMapping(value = "/api/todo", method = RequestMethod.POST) @ResponseBody TodoDTO add(@RequestBody TodoDTO dto); @RequestMapping(value = "/api/todo/search/count/{searchTerm}", method = RequestMethod.GET) @ResponseBody long countSearchResults(@PathVariable("searchTerm") String searchTerm); @RequestMapping(value = "/api/todo/{id}", method = RequestMethod.DELETE) @ResponseBody TodoDTO deleteById(@PathVariable("id") Long id); @RequestMapping(value = "/api/todo", method = RequestMethod.GET) @ResponseBody List<TodoDTO> findAll(); @RequestMapping(value = "/api/todo/{id}", method = RequestMethod.GET) @ResponseBody TodoDTO findById(@PathVariable("id") Long id); @RequestMapping(value = "/api/todo/{id}", method = RequestMethod.PUT) @ResponseBody TodoDTO update(@RequestBody TodoDTO dto, @PathVariable("id") Long todoId); @ExceptionHandler(FormValidationError.class) @ResponseBody @ResponseStatus(HttpStatus.BAD_REQUEST) FormValidationErrorDTO handleFormValidationError(FormValidationError validationError); @RequestMapping(value = "/api/todo/search/{searchTerm}", method = RequestMethod.GET) @ResponseBody List<TodoDTO> search(@PathVariable("searchTerm") String searchTerm, Pageable page); @ExceptionHandler(TodoNotFoundException.class) @ResponseStatus(HttpStatus.NOT_FOUND) void handleTodoNotFoundException(TodoNotFoundException ex);  }