From a09b573f6e074e97d104039f758a3952350ab758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Manteaux?= Date: Thu, 19 Sep 2024 11:34:52 +0200 Subject: [PATCH 1/2] Fix sonar issues --- .../coreoz/plume/db/querydsl/pagination/SqlPaginatedQuery.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plume-db-querydsl/src/main/java/com/coreoz/plume/db/querydsl/pagination/SqlPaginatedQuery.java b/plume-db-querydsl/src/main/java/com/coreoz/plume/db/querydsl/pagination/SqlPaginatedQuery.java index 60013ae..c5ec754 100644 --- a/plume-db-querydsl/src/main/java/com/coreoz/plume/db/querydsl/pagination/SqlPaginatedQuery.java +++ b/plume-db-querydsl/src/main/java/com/coreoz/plume/db/querydsl/pagination/SqlPaginatedQuery.java @@ -97,7 +97,7 @@ public Slice fetchSlice( ) { List slicedQueryResults = this.sqlQuery .offset(Pages.offset(pageNumber, pageSize)) - .limit(pageSize + 1) + .limit(pageSize + 1L) .fetch(); boolean hasMore = slicedQueryResults.size() > pageSize; From 2c2a7c62b88d6a63605f86e9ec738f53e1502433 Mon Sep 17 00:00:00 2001 From: Lucas Amiaud Date: Thu, 19 Sep 2024 11:46:37 +0200 Subject: [PATCH 2/2] add slice test + fix doc --- plume-db-querydsl/README.md | 3 ++- .../coreoz/plume/db/pagination/SliceTest.java | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 plume-db/src/test/java/com/coreoz/plume/db/pagination/SliceTest.java diff --git a/plume-db-querydsl/README.md b/plume-db-querydsl/README.md index 32e648a..ef9e388 100644 --- a/plume-db-querydsl/README.md +++ b/plume-db-querydsl/README.md @@ -110,10 +110,11 @@ public enum SortPath { private final Expression path; @Nullable - public static SortPath fromSortKey(String sortKey) { + public static Expression fromSortKey(String sortKey) { return Arrays.stream(SortPath.values()) .filter(entry -> entry.sortKey.equals(sortKey)) .findFirst() + .map(sortPath -> sortPath.path) .orElse(null); } } diff --git a/plume-db/src/test/java/com/coreoz/plume/db/pagination/SliceTest.java b/plume-db/src/test/java/com/coreoz/plume/db/pagination/SliceTest.java new file mode 100644 index 0000000..681eb14 --- /dev/null +++ b/plume-db/src/test/java/com/coreoz/plume/db/pagination/SliceTest.java @@ -0,0 +1,26 @@ +package com.coreoz.plume.db.pagination; + +import org.assertj.core.api.Assertions; +import org.junit.Test; + +import java.util.List; + +public class SliceTest { + + @Test + public void should_map_users() { + User user = new User(1L, "To fetch"); + Slice page = new Slice<>( + List.of(user), + true + ); + + Slice userNames = page.map(User::name); + + Assertions.assertThat(userNames.items().stream().findFirst()).isNotEmpty(); + Assertions.assertThat(userNames.items().stream().findFirst().get()).contains("To fetch"); + } + + private record User(long id, String name) { + } +}