### Question:
UserHibernateDao extends GenericDao<PoulpeUser> implements UserDao { @Override public List<PoulpeUser> findPoulpeUsersBySearchRequest(UserSearchRequest searchRequest) { String searchString = SqlLikeEscaper.escapeControlCharacters(searchRequest.getSearchString()); SimpleExpression expression = Restrictions.like("username", MessageFormat.format(FORMAT, searchString)).ignoreCase(); Criteria criteria = session().createCriteria(PoulpeUser.class) .add((searchRequest.isCaseSensitise()) ? expression : expression.ignoreCase()) .addOrder(getOrder(searchRequest)); searchRequest.getPagination().addPagination(criteria); return criteria.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 testFindPoulpeUsersBySearchRequestAsc(){ List<PoulpeUser> users = TestFixtures.usersListOf(23); saveAndEvict(users); int limit = 10; int page = 1; UserSearchRequest request = new UserSearchRequest(true,Pages.paginate(1, limit),BY_USERNAME,""); List<PoulpeUser> actual = dao.findPoulpeUsersBySearchRequest(request); assertEquals(actual.size(), limit); assertTrue(actual.get(0).getUsername().toLowerCase().charAt(0) <= actual.get(1).getUsername().toLowerCase().charAt(0)); }
@Test public void testFindPoulpeUsersBySearchRequestDesc(){ List<PoulpeUser> users = TestFixtures.usersListOf(23); saveAndEvict(users); int limit = 10; int page = 1; UserSearchRequest request = new UserSearchRequest(false,Pages.paginate(1, limit),BY_USERNAME,""); List<PoulpeUser> actual = dao.findPoulpeUsersBySearchRequest(request); assertEquals(actual.size(), limit); assertTrue(actual.get(0).getUsername().toLowerCase().charAt(0) >= actual.get(1).getUsername().toLowerCase().charAt(0)); }