assertEquals(er.getSize(), 3);
List<PetEntity> foundPets = er.getEntityList();
assertEquals(foundPets.get(0), pets[0]);
assertEquals(foundPets.get(1), pets[1]);
assertEquals(foundPets.get(2), pets[2]);
CouchPageNavigation pageNavigation = er.getCouchPageNavigation();
assertNotNull(pageNavigation);
assertFalse(pageNavigation.hasPreviousPage());
assertTrue(pageNavigation.hasNextPage());
assertTrue(pageNavigation.hasRequestedPage());
assertEquals(pageNavigation.getRequestedPage(), "_design/pet/_view/byCreatedAt?include_docs=true&limit=4");
String nextPage = String.format("_design/pet/_view/byCreatedAt?startkey=%%22%s%%22&startkey_docid=Pet:3&skip=1&descending=false", foundPets.get(2).getCreatedAt().toString());
assertEquals(pageNavigation.getNextPage(), nextPage);
// Second page
er = couchDatabase.get().entity(PetEntity.class, pageNavigation.queryNextPage()).execute();
assertEquals(er.getSize(), 3);
foundPets = er.getEntityList();
assertEquals(foundPets.get(0), pets[3]);
assertEquals(foundPets.get(1), pets[4]);
assertEquals(foundPets.get(2), pets[5]);
pageNavigation = er.getCouchPageNavigation();
assertNotNull(pageNavigation);
assertTrue(pageNavigation.hasPreviousPage());
assertTrue(pageNavigation.hasNextPage());
assertTrue(pageNavigation.hasRequestedPage());
assertEquals(pageNavigation.getRequestedPage(), nextPage);
String previousPage = String.format("_design/pet/_view/byCreatedAt?startkey=%%22%s%%22&startkey_docid=Pet:4&skip=1&descending=true", foundPets.get(0).getCreatedAt().toString());
assertEquals(pageNavigation.getPreviousPage(), previousPage);
nextPage = String.format("_design/pet/_view/byCreatedAt?startkey=%%22%s%%22&startkey_docid=Pet:6&skip=1&descending=false", foundPets.get(2).getCreatedAt().toString());
assertEquals(pageNavigation.getNextPage(), nextPage);
// Third page
er = couchDatabase.get().entity(PetEntity.class, pageNavigation.queryNextPage()).execute();
assertEquals(er.getSize(), 3);
foundPets = er.getEntityList();
assertEquals(foundPets.get(0), pets[6]);
assertEquals(foundPets.get(1), pets[7]);
assertEquals(foundPets.get(2), pets[8]);
pageNavigation = er.getCouchPageNavigation();
assertNotNull(pageNavigation);
assertTrue(pageNavigation.hasPreviousPage());
assertTrue(pageNavigation.hasNextPage());
assertTrue(pageNavigation.hasRequestedPage());
assertEquals(pageNavigation.getRequestedPage(), nextPage);
previousPage = String.format("_design/pet/_view/byCreatedAt?startkey=%%22%s%%22&startkey_docid=Pet:7&skip=1&descending=true", foundPets.get(0).getCreatedAt().toString());
assertEquals(pageNavigation.getPreviousPage(), previousPage);
nextPage = String.format("_design/pet/_view/byCreatedAt?startkey=%%22%s%%22&startkey_docid=Pet:9&skip=1&descending=false", foundPets.get(2).getCreatedAt().toString());
assertEquals(pageNavigation.getNextPage(), nextPage);
// Fourth page
er = couchDatabase.get().entity(PetEntity.class, pageNavigation.queryNextPage()).execute();
assertEquals(er.getSize(), 1);
foundPets = er.getEntityList();
assertEquals(foundPets.get(0), pets[9]);
pageNavigation = er.getCouchPageNavigation();
assertNotNull(pageNavigation);
assertTrue(pageNavigation.hasPreviousPage());
assertFalse(pageNavigation.hasNextPage());
assertTrue(pageNavigation.hasRequestedPage());
previousPage = String.format("_design/pet/_view/byCreatedAt?startkey=%%22%s%%22&startkey_docid=Pet:10&skip=1&descending=true", foundPets.get(0).getCreatedAt().toString());
assertEquals(pageNavigation.getPreviousPage(), previousPage);
}