### Question:
RepositoryUserService implements UserService { @Override public User getUserById(@NonNull String userId) throws UserNotFoundException { return userRepo.findById(userId).orElseThrow(() -> new UserNotFoundException(userId)); } RepositoryUserService(UserRepository userRepo,
                                 UserDataRepository dataRepo,
                                 LdapAdapter ldapAdapter,
                                 HierarchyTreeNodeRepository hierarchyTreeNodeRepo,
                                 HibernateSearchService hibernateSearchService); @Override boolean userExists(@NonNull String userId); @Override boolean userIsManager(@NonNull User user); @Override HierarchyTreeNode getHierarchyForUser(@NonNull User user); @Override UserData getUserData(@NonNull User user); @Override User getUserById(@NonNull String userId); @Override boolean userHasStaffMember(@NonNull User user, @NonNull User staffMember); @Override User getManagerOfUser(@NonNull User user); @Override List<UserData> getStaffMemberUserDataOfUser(@NonNull User user, @NonNull Sort sort); @Override List<UserData> searchStaffMemberDataOfUser(User user, String query, Sort sort); @Override List<User> getStaffMembersOfUser(@NonNull User user); @Override User save(@NonNull User user); @Override void delete(User user); @Override void deleteUserById(String userId); @Override Map<User, Boolean> usersAreManagers(@NonNull Set<User> users); User getOrCreateUserById(@NonNull String userId); @Override void removeAllApplicationsOfUser(User user);  }### Answer:
@Test public void getUserByIdReturnsUserWhenUserIsPresent() { given(userRepoMock.findById("user")).willReturn(Optional.of(userMock)); var actualUser = repoUserService.getUserById(USER_ID); assertThat(actualUser).isEqualTo(userMock); }
@Test public void getUserByIdThrowsExceptionWhenUserNotPresent() { var expectedMessage = String.format("User with ID '%s' not found!", USER_ID); assertThatThrownBy(() -> repoUserService.getUserById(USER_ID)) .isInstanceOf(UserNotFoundException.class) .hasMessage(expectedMessage); }