@Test public void update_TodoEntryNotFound_ShouldReturnHttpStatusCodeNotFound() throws Exception { TodoDTO updatedTodoEntry = new TodoDTOBuilder() .description(DESCRIPTION) .title(TITLE) .build(); when(todoCrudServiceMock.update(isA(TodoDTO.class))).thenThrow(new TodoNotFoundException("")); mockMvc.perform(put("/api/todo/{id}", ID) .contentType(WebTestConstants.APPLICATION_JSON_UTF8) .content(objectMapper.writeValueAsBytes(updatedTodoEntry)) ) .andExpect(status().isNotFound()); ArgumentCaptor<TodoDTO> serviceMethodArgument = ArgumentCaptor.forClass(TodoDTO.class); verify(todoCrudServiceMock, times(1)).update(serviceMethodArgument.capture()); verifyNoMoreInteractions(todoCrudServiceMock); verifyZeroInteractions(todoSearchServiceMock); TodoDTO serviceMethodArgumentValue = serviceMethodArgument.getValue(); assertThatTodoDTO(serviceMethodArgumentValue) .hasId(ID) .hasNoCreationTime() .hasDescription(DESCRIPTION) .hasNoModificationTime() .hasTitle(TITLE); }
@RequestMapping(value = "/{id}", method = RequestMethod.PUT) public TodoDTO update(@PathVariable("id") Long id, @RequestBody @Valid TodoDTO dto) { dto.setId(id); LOGGER.info("Updating todo entry with information: {}", dto); TodoDTO updated = crudService.update(dto); LOGGER.info("Updated todo entry: {}", updated); return updated; }
TodoController { @RequestMapping(value = "/{id}", method = RequestMethod.PUT) public TodoDTO update(@PathVariable("id") Long id, @RequestBody @Valid TodoDTO dto) { dto.setId(id); LOGGER.info("Updating todo entry with information: {}", dto); TodoDTO updated = crudService.update(dto); LOGGER.info("Updated todo entry: {}", updated); return updated; } }
TodoController { @RequestMapping(value = "/{id}", method = RequestMethod.PUT) public TodoDTO update(@PathVariable("id") Long id, @RequestBody @Valid TodoDTO dto) { dto.setId(id); LOGGER.info("Updating todo entry with information: {}", dto); TodoDTO updated = crudService.update(dto); LOGGER.info("Updated todo entry: {}", updated); return updated; } @Autowired  TodoController(TodoCrudService crudService, TodoSearchService searchService); }
TodoController { @RequestMapping(value = "/{id}", method = RequestMethod.PUT) public TodoDTO update(@PathVariable("id") Long id, @RequestBody @Valid TodoDTO dto) { dto.setId(id); LOGGER.info("Updating todo entry with information: {}", dto); TodoDTO updated = crudService.update(dto); LOGGER.info("Updated todo entry: {}", updated); return updated; } @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.PUT) public TodoDTO update(@PathVariable("id") Long id, @RequestBody @Valid TodoDTO dto) { dto.setId(id); LOGGER.info("Updating todo entry with information: {}", dto); TodoDTO updated = crudService.update(dto); LOGGER.info("Updated todo entry: {}", updated); return updated; } @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);  }