Skip to content

Commit

Permalink
add slice test + fix doc
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-amiaud committed Sep 19, 2024
1 parent a31da44 commit 2c2a7c6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion plume-db-querydsl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<User> page = new Slice<>(
List.of(user),
true
);

Slice<String> 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) {
}
}

0 comments on commit 2c2a7c6

Please sign in to comment.