DATACMNS-713 - Disabled total adaption in PageImpl for empty pages.

The newly introduced adaption of the total in PageImpl must only be applied if the page accessed is not empty.
This commit is contained in:
Oliver Gierke
2015-06-19 15:26:40 +02:00
parent d641f978bf
commit fe3a682613
2 changed files with 11 additions and 1 deletions

View File

@@ -45,7 +45,7 @@ public class PageImpl<T> extends Chunk<T> implements Page<T> {
super(content, pageable);
this.pageable = pageable;
this.total = pageable != null && pageable.getOffset() + pageable.getPageSize() > total
this.total = !content.isEmpty() && pageable != null && pageable.getOffset() + pageable.getPageSize() > total
? pageable.getOffset() + content.size() : total;
}

View File

@@ -179,4 +179,14 @@ public class PageImplUnitTests {
assertThat(new PageImpl<String>(Arrays.asList("foo", "bar"), new PageRequest(1, 10), 11).getTotalElements(),
is(12L));
}
/**
* @see DATACMNS-713
*/
@Test
public void doesNotAdapttotalIfPageIsEmpty() {
assertThat(new PageImpl<String>(Collections.<String> emptyList(), new PageRequest(1, 10), 0).getTotalElements(),
is(0L));
}
}