DATACMNS-1613 - Fixed Chunk.getSize() for usage with an unpaged Pageable.
We now return the content length as size of a Chunk if no Pageable has been used to create a Chunk. This makes the usage of a Chunk without an explicit Pageable work just like it was requested with the size of the given content.
This commit is contained in:
@@ -70,7 +70,7 @@ abstract class Chunk<T> implements Slice<T>, Serializable {
|
||||
* @see org.springframework.data.domain.Slice#getSize()
|
||||
*/
|
||||
public int getSize() {
|
||||
return pageable.isPaged() ? pageable.getPageSize() : 0;
|
||||
return pageable.isPaged() ? pageable.getPageSize() : content.size();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -174,4 +174,15 @@ public class PageImplUnitTests {
|
||||
assertThat(page.nextPageable()).isEqualTo(Pageable.unpaged());
|
||||
assertThat(page.nextOrLastPageable()).isEqualTo(pageable);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1613
|
||||
public void usesContentLengthForSizeIfNoPageableGiven() {
|
||||
|
||||
Page<Integer> page = new PageImpl<>(Arrays.asList(1, 2));
|
||||
|
||||
assertThat(page.getSize()).isEqualTo(2);
|
||||
assertThat(page.getTotalPages()).isEqualTo(1);
|
||||
assertThat(page.hasPrevious()).isFalse();
|
||||
assertThat(page.hasNext()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user