protected PaginatedList<DTO> findPaginatedWithQueryAndSort(Bson query, Bson sort, int page, int perPage) {
        try (final DBCursor<DTO> cursor = db.find(query)
                .sort(sort)
                .limit(perPage)
                .skip(perPage * Math.max(0, page - 1))) {
            final long grandTotal = db.count();
            return new PaginatedList<>(asImmutableList(cursor), cursor.count(), page, perPage, grandTotal);
        }
    }
@Test
    public void findPaginatedWithQueryAndSort() {
        dbService.save(newDto("hello1"));
        dbService.save(newDto("hello2"));
        dbService.save(newDto("hello3"));
        dbService.save(newDto("hello4"));
        dbService.save(newDto("hello5"));

        final PaginatedList<TestDTO> page1 = dbService.findPaginatedWithQueryAndSort(DBQuery.empty(), DBSort.asc("title"), 1, 2);

        assertThat(page1.pagination().count()).isEqualTo(2);
        assertThat(page1.pagination().total()).isEqualTo(5);
        assertThat(page1.delegate())
                .extracting("title")
                .containsExactly("hello1", "hello2");

        final PaginatedList<TestDTO> page2 = dbService.findPaginatedWithQueryAndSort(DBQuery.empty(), DBSort.asc("title"), 2, 2);

        assertThat(page2.pagination().count()).isEqualTo(2);
        assertThat(page2.pagination().total()).isEqualTo(5);
        assertThat(page2.delegate())
                .extracting("title")
                .containsExactly("hello3", "hello4");

        final PaginatedList<TestDTO> page3 = dbService.findPaginatedWithQueryAndSort(DBQuery.empty(), DBSort.asc("title"), 3, 2);

        assertThat(page3.pagination().count()).isEqualTo(1);
        assertThat(page3.pagination().total()).isEqualTo(5);
        assertThat(page3.delegate())
                .extracting("title")
                .containsExactly("hello5");

        final PaginatedList<TestDTO> page1reverse = dbService.findPaginatedWithQueryAndSort(DBQuery.empty(), DBSort.desc("title"), 1, 2);

        assertThat(page1reverse.pagination().count()).isEqualTo(2);
        assertThat(page1reverse.pagination().total()).isEqualTo(5);
        assertThat(page1reverse.delegate())
                .extracting("title")
                .containsExactly("hello5", "hello4");
    }