UserController { @RequestMapping(value = USER_REGISTER_URL, method = RequestMethod.POST) public UserDto register(@Valid @RequestBody RegisterDto registerDto) { User user = userService.register(registerDto); UserDto userDto = new UserDto(); userDto.setId(user.getId()); userDto.setUsername(user.getUsername()); return userDto; }  @RequestMapping(value = USER_REGISTER_URL, method = RequestMethod.POST) UserDto register(@Valid @RequestBody RegisterDto registerDto);  }
@Test public void testRegister() { RegisterDto registerDto = new RegisterDto(); registerDto.setUsername(RandomStringUtils.randomAlphanumeric(8)); registerDto.setPassword(RandomStringUtils.randomAlphanumeric(8)); UserDto userDto = restTemplate.postForObject(buildRequestUrl(UserUrl.USER_REGISTER_URL), createJsonEntity(registerDto), UserDto.class); assertThat(userDto, notNullValue()); assertThat(userDto.getId(), notNullValue()); assertThat(userDto.getUsername(), notNullValue()); }