### Question:
UserController { @GetMapping("/{userId}") public User getUserById(@PathVariable("userId") final Long userId){ return userRepository.findOne(userId); } UserController(UserRepository userRepository); @GetMapping("/{userId}") User getUserById(@PathVariable("userId") final Long userId);  }### Answer:
@Test public void getUserByIdTest() throws Exception { long userId = 1; String userAlias = "john"; given(userRepository.findOne(userId)) .willReturn(new User(userId, userAlias)); MockHttpServletResponse response = mvc.perform( get("/users/" + userId) .accept(MediaType.APPLICATION_JSON)) .andReturn().getResponse(); assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value()); assertThat(response.getContentAsString()) .isEqualTo(json.write(new User(userId, userAlias)).getJson()); }