### Question:
UserServiceImpl implements UserService { @Transactional @Nonnull @Override public User getOrCreateUserForUuId(final String uuId) { assertUserUuIdNotNull(uuId); logger.debug("Getting or creating user for uuid - {}", uuId); Optional<User> user = userRepository.findByUuId(uuId); if (!user.isPresent()) { logger.debug("No user was found for uuid - {}, creating new one", uuId); return createUser(new UserDto(uuId)); } logger.debug("User for uuid already exists, using it, uuid - {}, user - {}", uuId, user); return user.get(); } 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 testGetOrCreateUserForUuIdWithInvalidArguments() { resetAll(); replayAll(); try { userService.getOrCreateUserForUuId(null); fail("Exception should be thrown"); } catch (final IllegalArgumentException ex) { } verifyAll(); }
@Test public void testGetOrCreateUserForUuIdWhenUserDoesNotExist() { final String userUuId = "JKIBOBPUHUPGGIO"; resetAll(); expect(userRepository.findByUuId(eq(userUuId))).andReturn(Optional.empty()).times(2); expect(userRepository.save(isA(User.class))).andAnswer(() -> (User) getCurrentArguments()[0]).once(); replayAll(); final User result = userService.getOrCreateUserForUuId(userUuId); getServicesImplTestHelper().assertUser(result, new UserDto(userUuId)); verifyAll(); }