### Question:
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);  }### Answer:
@Test public void findById_TodoEntryFound_ShouldReturnTodoEntryAsJsonDocument() throws Exception { TodoDTO foundTodoEntry = new TodoDTOBuilder() .creationTime(CREATION_TIME) .description(DESCRIPTION) .id(ID) .modificationTime(MODIFICATION_TIME) .title(TITLE) .build(); when(todoCrudServiceMock.findById(ID)).thenReturn(foundTodoEntry); mockMvc.perform(get("/api/todo/{id}", ID)) .andExpect(status().isOk()) .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))); verify(todoCrudServiceMock, times(1)).findById(ID); verifyNoMoreInteractions(todoCrudServiceMock); verifyZeroInteractions(todoSearchServiceMock); }
@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); }