### Question:
UserMapper { public User userDTOToUser(UserDTO userDTO) { if (userDTO == null) { return null; } else { User user = new User(); user.setId(userDTO.getId()); user.setLogin(userDTO.getLogin()); user.setFirstName(userDTO.getFirstName()); user.setLastName(userDTO.getLastName()); user.setEmail(userDTO.getEmail()); user.setImageUrl(userDTO.getImageUrl()); user.setActivated(userDTO.isActivated()); user.setLangKey(userDTO.getLangKey()); Set<Authority> authorities = this.authoritiesFromStrings(userDTO.getAuthorities()); user.setAuthorities(authorities); return user; } }  List<UserDTO> usersToUserDTOs(List<User> users); UserDTO userToUserDTO(User user); List<User> userDTOsToUsers(List<UserDTO> userDTOs); User userDTOToUser(UserDTO userDTO); User userFromId(Long id);  }### Answer:
@Test public void userDTOToUserMapWithAuthoritiesStringShouldReturnUserWithAuthorities() { Set<String> authoritiesAsString = new HashSet<>(); authoritiesAsString.add("ADMIN"); userDto.setAuthorities(authoritiesAsString); User user = userMapper.userDTOToUser(userDto); assertThat(user).isNotNull(); assertThat(user.getAuthorities()).isNotNull(); assertThat(user.getAuthorities()).isNotEmpty(); assertThat(user.getAuthorities().iterator().next().getName()).isEqualTo("ADMIN"); }
@Test public void userDTOToUserMapWithNullAuthoritiesStringShouldReturnUserWithEmptyAuthorities() { userDto.setAuthorities(null); User user = userMapper.userDTOToUser(userDto); assertThat(user).isNotNull(); assertThat(user.getAuthorities()).isNotNull(); assertThat(user.getAuthorities()).isEmpty(); }
@Test public void userDTOToUserMapWithNullUserShouldReturnNull() { assertThat(userMapper.userDTOToUser(null)).isNull(); }