How do I create a Pager object?

I'm trying to write a unit test using Mockito and Junit and creating mock objects, and the mock GroupManager has to return a list of users. It returns a Pager object, but Pager is an interface! I even tried to look at GroupManager souce code, but that is also an interface! How do I create a Pager object to return?

The JavaDocs doesn't even have the Pager class!

1 answer

1 accepted


you found the groupmanager interface. why didn't you continue to look for an implementation class? you can find them close to the interface definitions.

in the impl.* subpackage you will find e.g.the HibernateGroupManager which implements the GroupManager interface.

getGroups() is implemented this way:

public Pager<Group> getGroups() throws EntityException {

        List<Group> result;
        try {
            result = getGroupsFromHibernate();
        catch (DataAccessException e)  {
            throw new RepositoryException(e);

        if (result == null) {
            return DefaultPager.emptyPager();

        return new DefaultPager<Group>(result);

DefaultPager is in the sourcetree too:

public class DefaultPager<T> implements Pager<T> {

    private final List<T> page = new ArrayList<T>();
    private Iterator<T> iter;
    private int index; 

    public static <T> DefaultPager<T> emptyPager() {
        return new DefaultPager<T>(Collections.<T>emptyList());

    /** @deprecated since 2.0.3. Use the generic-friendly emptyPager() method */
    public DefaultPager(){

    public DefaultPager(Collection<T> col){
        if (col != null) {
        iter = page.iterator();

    public boolean isEmpty() {
        if (page == null) return true;
        return page.isEmpty();

    public Iterator<T> iterator() {
        return iter;

     * @return a single, preloaded page.
    public List<T> getCurrentPage() {
        return new ArrayList<T>(page);

    public void nextPage() {
        //do nothing, all contents are already within the currentPage

    public boolean onLastPage() {
        return true;

    public void skipTo(int index) throws PagerException  {
        if (index < 0)
            throw new PagerException("Cannot skipTo a negative amount [" + index + "]"); 

        int originalIndex = this.index;
        int distance;

        if (index > page.size()) {
            distance = page.size();
            this.index = page.size();
        else {
            distance = index - this.index;
            this.index = index;

        for (int i = originalIndex; i < distance; i++);


     * @return the current index position of the pager

    public int getIndex()  {
        return index;

     *  This pager always has all its items in a single page
     * @return zero, because this pager has all its items in a single page
    public int getIndexOfFirstItemInCurrentPage()  {
        return 0;

    public void remove()  {
        throw new UnsupportedOperationException("This iterator does not support removal");

    public boolean hasNext()   {
        return iter.hasNext();

    public T next()    {
        T o =;
        return o;

this should help (-:

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Tuesday in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

478 views 19 9
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you