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 21c100d98c
commit c811f7fb73
2 changed files with 11 additions and 1 deletions

View File

@@ -41,7 +41,7 @@ public class PageImpl<T> extends Chunk<T> implements Page<T> {
super(content, 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

@@ -160,4 +160,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));
}
}