### Question:
UserHibernateDao extends GenericDao<PoulpeUser> implements UserDao { @Override public List<PoulpeUser> findPoulpeUsersPaginated(String searchString, Pagination paginate) { searchString = SqlLikeEscaper.escapeControlCharacters(searchString); Query query = session().getNamedQuery("findUsersByLikeUsername"); query.setString("username", MessageFormat.format(FORMAT, searchString)); 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 findPoulpeUsersPaginated_withPagination() { String startsWith = "SomeString"; givenMoreThanOnePage(startsWith); int limit = 10; List<PoulpeUser> users = dao.findPoulpeUsersPaginated(startsWith, Pages.paginate(1, limit)); assertEquals(users.size(), limit); }
@Test public void findPoulpeUsersPaginated_noFilterAndNoPagination() { List<PoulpeUser> users = TestFixtures.usersListOf(3); saveAndEvict(users); List<PoulpeUser> actual = dao.findPoulpeUsersPaginated(NO_FILTER, Pages.NONE); assertContainsSameElements(actual, users); }
@Test public void findPoulpeUsersPaginated_noFilterAndAllOnFirstPage() { List<PoulpeUser> users = TestFixtures.usersListOf(3); saveAndEvict(users); List<PoulpeUser> actual = dao.findPoulpeUsersPaginated(NO_FILTER, Pages.paginate(0, 10)); assertContainsSameElements(actual, users); }
@Test public void findPoulpeUsersPaginated_noFilterAndMoreThanOnePage() { List<PoulpeUser> users = TestFixtures.usersListOf(13); saveAndEvict(users); int limit = 10; List<PoulpeUser> actual = dao.findPoulpeUsersPaginated(NO_FILTER, Pages.paginate(0, limit)); assertEquals(actual.size(), limit); }