### Question:
UserServiceImpl implements UserService { @Transactional @Nonnull @Override public User createUser(@Nonnull final UserDto userDto) { assertUserDto(userDto); logger.debug("Creating user for DTO - {}", userDto); assertNoUserExistsForUuId(userDto.getUuId()); User user = new User(); userDto.updateDomainEntityProperties(user); user = userRepository.save(user); logger.debug("Successfully created user with id - {}, user - {}", user.getId(), user); return user; } UserServiceImpl(); @Nonnull @Override User getUserById(@Nonnull final Long id); @Transactional @Nonnull @Override User createUser(@Nonnull final UserDto userDto); @Nonnull @Override boolean checkIfUserExistsForUuId(@Nonnull final String uuId); @Nonnull @Override User getUserByUuId(@Nonnull final String uuId); @Transactional @Nonnull @Override User getOrCreateUserForUuId(final String uuId); UserRepository getUserRepository(); void setUserRepository(final UserRepository userRepository);  }### Answer:
@Test public void testCreateUserWithInvalidArguments() { resetAll(); replayAll(); try { userService.createUser(null); fail("Exception should be thrown"); } catch (final IllegalArgumentException ex) { } try { userService.createUser(new UserDto(null)); fail("Exception should be thrown"); } catch (final IllegalArgumentException ex) { } verifyAll(); }
@Test public void testCreateUserWithExistingUuId() { final UserDto userDto = getServicesImplTestHelper().createUserDto(); final Long existingUserId = 1L; final User existingUser = getServicesImplTestHelper().createUser(); existingUser.setId(existingUserId); resetAll(); expect(userRepository.findByUuId(eq(userDto.getUuId()))).andReturn(Optional.of(existingUser)).once(); replayAll(); try { userService.createUser(userDto); fail("Exception should be thrown"); } catch (final UserAlreadyExistsForUuIdException ex) { assertUserAlreadyExistsForUuIdException(ex, userDto.getUuId(), existingUserId); } verifyAll(); }
@Test public void testCreateUser() { final UserDto userDto = getServicesImplTestHelper().createUserDto(); resetAll(); expect(userRepository.findByUuId(eq(userDto.getUuId()))).andReturn(Optional.empty()).once(); expect(userRepository.save(isA(User.class))).andAnswer(() -> (User) getCurrentArguments()[0]).once(); replayAll(); final User result = userService.createUser(userDto); getServicesImplTestHelper().assertUser(result, userDto); verifyAll(); }