### Question:
UserController { @PostMapping public User register(@RequestBody User user) { return userService.register(user); } UserController(UserService userService); @PostMapping User register(@RequestBody User user);  }### Answer:
@Test public void register() throws Exception { UserCredentials userCredentials = new UserCredentials("user", "password", "USER_ROLE"); User user = new User(userCredentials); given(userService.register(user)) .willReturn(user); mvc.perform(post("/api/users") .with(csrf()) .contentType(MediaType.APPLICATION_JSON) .content(userJacksonTester.write(user).getJson())) .andExpect(status().isOk()) .andExpect(jsonPath("$.userCredentials.username", is(user.getUserCredentials().getUsername()))); }