public void testIterPaginateStatefulPreviouPageSeveralTimes() {
Discovery[] discs = new Discovery[15];
for(int i=0; i<15; i++){
discs[i] = new Discovery("Disc_"+i, LongAutoID_CURIE);
}
pm.insert((Object[])discs);
Query<Discovery> query = pm.createQuery(Discovery.class).paginate(5).stateful().order("id");
Iterable<Discovery> iter = query.iter();
Iterator<Discovery> it = iter.iterator();
int i=0;
while(it.hasNext()){
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(5, i);
iter = query.nextPage().iter();
it = iter.iterator();
while(it.hasNext()){
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(10, i);
iter = query.nextPage().iter();
it = iter.iterator();
while(it.hasNext()){
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(15, i);
iter = query.previousPage().iter();
i=5;
it = iter.iterator();
while(it.hasNext()){
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(10, i);
iter = query.previousPage().iter();
i=0;
it = iter.iterator();
while(it.hasNext()){
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(5, i);
}