Skip to content

PageableExecutionUtils returns too many results for content #2492

@sniffertine

Description

@sniffertine

I have used PageableExecutionUtils for the first time today and think there might be a bug. The returned page seems to always contain the whole content, not a sublist of the given input as I would expect. Or is there a misunderstanding on my side that I am not seeing?

The following simple test illustrates the issue:

    @Test
    void testPageContent() {
        List<Integer> content = List.of(1, 2, 3, 4, 5, 6, 7, 8, 9);
        Page<Integer> page = PageableExecutionUtils.getPage(content, PageRequest.of(1, 4), content::size);

        assertThat(page.getTotalElements()).isEqualTo(9);
        assertThat(page.getTotalPages()).isEqualTo(3);
        assertThat(page.getNumber()).isEqualTo(1);
        assertThat(page.getSize()).isEqualTo(4);
        assertThat(page.getNumberOfElements()).isEqualTo(4); //fails
        assertThat(page.getContent().size()).isEqualTo(4); //fails
        assertThat(page).containsExactly(5, 6, 7, 8); //fails
    }

Cheers
Stefan

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions