### Question:
UserHibernateDao extends GenericDao<PoulpeUser> implements UserDao { @Override public List<PoulpeUser> findUsersNotInGroups(String availableFilterText, List<Group> groups, Pagination paginate) { availableFilterText = SqlLikeEscaper.escapeControlCharacters(availableFilterText); Query query = session().getNamedQuery("findUnbannedUsersByLikeUsername"); query.setString("username", MessageFormat.format(FORMAT, availableFilterText)); ArrayList groupsIds = new ArrayList(); for (Group group : groups) { groupsIds.add(new BigInteger(group.getId() + "")); } query.setParameterList("bannedGroups", groupsIds, StandardBasicTypes.BIG_INTEGER); paginate.addPagination(query); return query.list(); } UserHibernateDao(SessionFactory sessionFactory); @Override List<PoulpeUser> findPoulpeUsersPaginated(String searchString, Pagination paginate); @Override List<PoulpeUser> findPoulpeUsersBySearchRequest(UserSearchRequest searchRequest); @Override int countUsernameMatches(String searchString); @Override PoulpeUser getByUsername(String username); @Override PoulpeUser getByEmail(String email); @Override PoulpeUser getByUUID(String uuid); @Override List<PoulpeUser> getUsersInGroups(List<Group> groups); @Override List<PoulpeUser> findUsersByUsernameAndPasswordHash(String username, String passwordHash); @Override List<PoulpeUser> findUsersNotInGroups(String availableFilterText,
                                                 List<Group> groups, Pagination paginate); @Override List<PoulpeUser> findUsersNotInList(String availableFilterText,
                                               List<PoulpeUser> listUsers, Pagination paginate); @Override void save(User user);  }### Answer:
@Test public void testFindUsersNotInGroups_withoutFilterUsername() { Group firstGroup = TestFixtures.groupWithUsers(); Group secondGroup = TestFixtures.groupWithUsers(); saveAndEvict(firstGroup); saveAndEvict(secondGroup); List<PoulpeUser> usersNotInFirstGroup = dao.findUsersNotInGroups(NO_FILTER, Arrays.asList(firstGroup), Pages.paginate(0, 1000)); assertTrue(secondGroup.getUsers().containsAll(usersNotInFirstGroup)); }
@Test public void testFindUsersNotInGroups_withFilterUsername() { Group firstGroup = TestFixtures.groupWithUsers(); Group secondGroup = TestFixtures.groupWithUsers(); saveAndEvict(firstGroup); saveAndEvict(secondGroup); String filter = secondGroup.getUsers().get(0).getUsername(); List<PoulpeUser> usersNotInFirstGroup = dao.findUsersNotInGroups(filter, Arrays.asList(firstGroup), Pages.paginate(0, 1000)); for (PoulpeUser poulpeUser : usersNotInFirstGroup) { assertTrue(poulpeUser.getUsername().contains(filter)); } assertTrue(secondGroup.getUsers().containsAll(usersNotInFirstGroup)); }
@Test public void testFindUsersNotInGroups_withLimit() { Group firstGroup = TestFixtures.groupWithUsers(); Group secondGroup = TestFixtures.groupWithUsers(); saveAndEvict(firstGroup); saveAndEvict(secondGroup); int limit = 2; List<PoulpeUser> actual = dao.findUsersNotInGroups(NO_FILTER, Arrays.asList(firstGroup), Pages.paginate(0, limit)); assertEquals(actual.size(), limit); }