### Question:
TodoController { @GetMapping(path = "/users/{name}/todos/{id}") public Resource<Todo> retrieveTodo(@PathVariable String name, @PathVariable int id) { Todo todo = todoService.retrieveTodo(id); if (todo == null) { throw new TodoNotFoundException("Todo Not Found"); } Resource<Todo> todoResource = new Resource<com.mastering.spring.springboot.bean.Todo>(todo); ControllerLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveTodos(name)); todoResource.add(linkTo.withRel("parent")); return todoResource; }  @ApiOperation(value = "Retrieve all todos for a user by passing in his name", notes = "A list of matching todos is returned. Currently pagination is not supported.", response = Todo.class, responseContainer = "List", produces = "application/json") @GetMapping("/users/{name}/todos") List<Todo> retrieveTodos(@PathVariable String name); @GetMapping(path = "/users/{name}/todos/{id}") Resource<Todo> retrieveTodo(@PathVariable String name, @PathVariable int id); @DeleteMapping("/users/{name}/todos/{id}") ResponseEntity<Void> deleteTodo(@PathVariable String name, @PathVariable int id); @PutMapping("/users/{name}/todos/{id}") ResponseEntity<Todo> updateTodo(@PathVariable String name, @PathVariable int id, @RequestBody Todo todo); @GetMapping(path = "/users/dummy-service") Todo errorService();  }### Answer:
@Test public void retrieveTodo() throws Exception { Todo mockTodo = new Todo(1, "Jack", "Learn Spring MVC", new Date(), false); when(service.retrieveTodo(anyInt())).thenReturn(mockTodo); MvcResult result = mvc .perform(MockMvcRequestBuilders.get("/users/Jack/todos/1").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()).andReturn(); String expected = "{id:1,user:Jack,desc:\"Learn Spring MVC\",done:false}"; JSONAssert.assertEquals(expected, result.getResponse().getContentAsString(), false); }