Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/main/java/org/springframework/data/domain/PageImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,24 @@ public PageImpl(List<T> content, Pageable pageable, long total) {
.orElse(total);
}

/**
* Creates a new {@link PageImpl} with the given content and pageable.
*
* @param content must not be {@literal null}.
* @param pageable the paging information, must not be {@literal null}.
*/
public PageImpl(List<T> content, Pageable pageable) {
this(content, pageable, CollectionUtils.isEmpty(content) ? 0 : content.size());
}

/**
* Creates a new {@link PageImpl} with the given content. This will result in the created {@link Page} being identical
* to the entire {@link List}.
*
* @param content must not be {@literal null}.
*/
public PageImpl(List<T> content) {
this(content, Pageable.unpaged(), CollectionUtils.isEmpty(content) ? 0 : content.size());
this(content, Pageable.unpaged());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@
*/
class PageImplUnitTests {

@Test
void createsPageWithContentAndPageable() {

List<String> content = Arrays.asList("foo", "bar", "baz");
PageRequest pageable = PageRequest.of(0, 10);

Page<String> page = new PageImpl<>(content, pageable);

assertThat(page.getContent()).isEqualTo(content);
assertThat(page.getPageable()).isEqualTo(pageable);
assertThat(page.getTotalElements()).isEqualTo(content.size());
assertThat(page.getTotalPages()).isEqualTo(1);
assertThat(page.getNumber()).isEqualTo(0);
assertThat(page.getSize()).isEqualTo(10);
}

@Test
void assertEqualsForSimpleSetup() {

Expand Down