### Question:
UserServiceImpl implements UserService { @Nonnull @Override public User getUserById(@Nonnull final Long id) { Assert.notNull(id, "User id should not be null"); logger.debug("Getting user for id - {}", id); final User user = userRepository.findById(id).orElseThrow(() -> new UserNotFoundForIdException(id)); logger.debug("Successfully retrieved user for 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 testGetUserByIdWithInvalidArguments() { resetAll(); replayAll(); try { userService.getUserById(null); fail("Exception should be thrown"); } catch (final IllegalArgumentException ex) { } verifyAll(); }
@Test public void testGetUserByIdWithNotExistingUser() { final Long userId = 1L; resetAll(); expect(userRepository.findById(eq(userId))).andReturn(Optional.empty()).once(); replayAll(); try { userService.getUserById(userId); fail("Exception should be thrown"); } catch (final UserNotFoundForIdException ex) { assertUserNotFoundForIdException(ex, userId); } verifyAll(); }
@Test public void testGetUserById() { final Long userId = 1L; final User user = getServicesImplTestHelper().createUser(); user.setId(userId); resetAll(); expect(userRepository.findById(eq(userId))).andReturn(Optional.of(user)).once(); replayAll(); final User result = userService.getUserById(userId); assertEquals(user, result); verifyAll(); }