@Test
public void testFindDataObjectsWithCustomPaging() {

    List<DXRecord> records = Lists.newArrayList();
    Set<String> recordIds = Sets.newHashSet();
    for (int i = 0; i < 8; ++i) {
        DXRecord record =
                DXRecord.newRecord().setProject(testProject)
                        .setName("foo" + Integer.toString(i)).build();
        records.add(record);
        recordIds.add(record.getId());
    }
    List<DXRecord> outputRecords =
            DXSearch.findDataObjects().inProject(testProject).nameMatchesGlob("foo*")
                    .withClassRecord().execute().asList();
    Assert.assertEquals(8, outputRecords.size());
    List<DXRecord> outputRecordsWithPaging =
            DXSearch.findDataObjects().inProject(testProject).nameMatchesGlob("foo*")
                    .withClassRecord().execute(3).asList();
    Assert.assertEquals(outputRecords, outputRecordsWithPaging);
    Set<String> outputRecordIds = Sets.newHashSet();
    for (DXRecord record : outputRecordsWithPaging) {
        outputRecordIds.add(record.getId());
    }
    Assert.assertEquals(recordIds, outputRecordIds);
    List<DXRecord> outputRecordStreamWithPaging =
            ImmutableList.copyOf(DXSearch.findDataObjects().inProject(testProject)
                    .nameMatchesGlob("foo*").withClassRecord().execute(3));
    Assert.assertEquals(outputRecords, outputRecordStreamWithPaging);
    // Checking an amount of fetched pages
    DXSearch.FindDataObjectsResult<DXRecord> findResult =
            DXSearch.findDataObjects().inProject(testProject).nameMatchesGlob("foo*").withClassRecord().execute(3);
    Iterator<DXRecord> iter = findResult.iterator();
    List<DXRecord> iterativelyFetchedRecords = Lists.newArrayList(iter);
    Assert.assertEquals(outputRecords, iterativelyFetchedRecords);
    Assert.assertEquals(3, ((DXSearch.FindDataObjectsResult<DXRecord>.ResultIterator) iter).pageNo());
}