TodoController { @RequestMapping(method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) public TodoDTO add(@RequestBody @Valid TodoDTO dto) { LOGGER.debug("Adding new todo entry with information: {}", dto); TodoDTO added = crudService.add(dto); LOGGER.info("Added todo entry: {}", added); return added; } @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);  }
@Test public void add_TodoEntryAdded_ShouldReturnAddedToEntryAsJsonDocument() throws Exception { TodoDTO addedTodoEntry = new TodoDTOBuilder() .description(DESCRIPTION) .title(TITLE) .build(); TodoDTO returnedTodoEntry = new TodoDTOBuilder() .creationTime(CREATION_TIME) .description(DESCRIPTION) .id(ID) .modificationTime(MODIFICATION_TIME) .title(TITLE) .build(); when(todoCrudServiceMock.add(isA(TodoDTO.class))).thenReturn(returnedTodoEntry); mockMvc.perform(post("/api/todo") .contentType(WebTestConstants.APPLICATION_JSON_UTF8) .content(objectMapper.writeValueAsBytes(addedTodoEntry)) ) .andExpect(status().isCreated()) .andExpect(content().contentType(WebTestConstants.APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.id", is(ID.intValue()))) .andExpect(jsonPath("$.creationTime", is(CREATION_TIME))) .andExpect(jsonPath("$.description", is(DESCRIPTION))) .andExpect(jsonPath("$.modificationTime", is(MODIFICATION_TIME))) .andExpect(jsonPath("$.title", is(TITLE))); ArgumentCaptor<TodoDTO> serviceMethodArgument = ArgumentCaptor.forClass(TodoDTO.class); verify(todoCrudServiceMock, times(1)).add(serviceMethodArgument.capture()); verifyNoMoreInteractions(todoCrudServiceMock); verifyZeroInteractions(todoSearchServiceMock); TodoDTO serviceMethodArgumentValue = serviceMethodArgument.getValue(); assertThatTodoDTO(serviceMethodArgumentValue) .hasNoId() .hasNoCreationTime() .hasDescription(DESCRIPTION) .hasNoModificationTime() .hasTitle(TITLE); }