SortableProjectDataProvider provider = new SortableProjectDataProvider();
int pageSize = NUMBER_OF_TEST_PROJECTS - 1;
// test the default sort is by name
Iterator<IDoapResource> iterator = provider.iterator(0, pageSize);
IDoapResource project;
String prev = null;
String current;
int count = 0;
while (iterator.hasNext()) {
project = iterator.next();
current = (String) project.getName();
if (prev != null) {
assertTrue("Incorrect sort order: " + prev + " preceeds " + current,
current.compareTo(prev) >= 0);
}
prev = current;
count = count + 1;
}
assertEquals(
"not returning the right number of elements for the given start point and pageSize",
pageSize, count);
// test the sort is by shortDesc
provider.setSort(SortableProjectDataProvider.SORT_PROPERTY_SHORTDESC, true);
iterator = provider.iterator(0, 10);
prev = null;
count = 0;
logger.debug("Projects in the project data provider are:");
while (iterator.hasNext()) {
project = iterator.next();
current = project.getShortDesc();
logger.debug(current);
if (prev != null && current != null) {
assertTrue("Incorrect sort order: " + prev + " preceeds " + current,
current.compareTo(prev) >= 0);
}