UserDaoImpl implements UserDao { @Override public List<User> findGroupsForUser(final String userUuid, final String quickFilterInput) { final Predicate<User> quickFilterPredicate = buildQuickFilterPredicate(quickFilterInput); return JooqUtil.contextResult(securityDbConnProvider, context -> context.select() .from(STROOM_USER) .join(STROOM_USER_GROUP) .on(STROOM_USER.UUID.eq(STROOM_USER_GROUP.GROUP_UUID)) .where(STROOM_USER_GROUP.USER_UUID.eq(userUuid)) .orderBy(STROOM_USER.NAME) .fetch() .stream() .map(RECORD_TO_USER_MAPPER) .filter(quickFilterPredicate) .collect(Collectors.toList())); } @Inject  UserDaoImpl(final ProcessingUserIdentityProvider processingUserIdentityProvider,
                       final SecurityDbConnProvider securityDbConnProvider); @Override User create(final User user); @Override Optional<User> getById(final int id); @Override Optional<User> getByUuid(final String uuid); @Override Optional<User> getByName(final String name); @Override User update(final User user); @Override void delete(final String uuid); @Override List<User> find(final String quickFilterInput, final Boolean group); @Override List<User> findUsersInGroup(final String groupUuid, final String quickFilterInput); @Override List<User> findGroupsForUser(final String userUuid, final String quickFilterInput); @Override Set<String> findGroupUuidsForUser(final String userUuid); @Override List<User> findGroupsForUserName(final String userName); @Override void addUserToGroup(final String userUuid,
                               final String groupUuid); @Override void removeUserFromGroup(final String userUuid,
                                    final String groupUuid);  }
@Test void findGroupsForUser() { final List<String> userNames = IntStream.range(0, 3) .mapToObj(i -> String.format("SomePerson_%s", UUID.randomUUID())) .collect(Collectors.toList()); final List<String> groupNames = IntStream.range(0, 3) .mapToObj(i -> String.format("SomeGroup_%s", UUID.randomUUID())) .collect(Collectors.toList()); final String userNameToTest = userNames.get(0); final List<User> users = userNames.stream() .map(name -> createUser(name, false)) .collect(Collectors.toList()); final User userToTest = users.stream() .filter(u -> userNameToTest.equals(u.getName())) .findFirst() .orElseThrow(() -> new AssertionError("Could not find user to test amongst created users")); final List<User> groups = groupNames.stream() .map(name -> createUser(name, true)) .peek(g -> users.forEach( u -> userDao.addUserToGroup(u.getUuid(), g.getUuid()))) .collect(Collectors.toList()); final List<User> groupsForUserToTest = userDao.findGroupsForUser(userToTest.getUuid(), null); groupNames.forEach(groupName -> assertThat(groupsForUserToTest.stream() .anyMatch(g -> groupName.equals(g.getName()))) .isTrue()); }