Skip to content

Commit

Permalink
Correctly apply Sorting of unpaged Pageable.
Browse files Browse the repository at this point in the history
Closes #1939
  • Loading branch information
mp911de committed Nov 14, 2024
1 parent a164871 commit a4c462e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ public Query limit(int limit) {
*/
public Query with(Pageable pageable) {

assertNoCaseSort(pageable.getSort());

if (pageable.isUnpaged()) {
return this;
return new Query(this.criteria, this.columns, this.sort.and(pageable.getSort()), this.limit, this.offset);
}

assertNoCaseSort(pageable.getSort());

return new Query(this.criteria, this.columns, this.sort.and(pageable.getSort()), pageable.getPageSize(),
pageable.getOffset());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@

import org.junit.jupiter.api.Test;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

/**
* Tests the {@link Query} class.
*
* @author Jens Schauder
* @author Mark Paluch
*/
public class QueryUnitTests {

@Test // DATAJDBC614
@Test // DATAJDBC-614
public void withCombinesSortAndPaging() {

Query query = Query.empty() //
Expand All @@ -40,7 +42,7 @@ public void withCombinesSortAndPaging() {
.containsExactly("alpha", "beta");
}

@Test // DATAJDBC614
@Test // DATAJDBC-614
public void withCombinesEmptySortAndPaging() {

Query query = Query.empty() //
Expand All @@ -51,7 +53,7 @@ public void withCombinesEmptySortAndPaging() {
.containsExactly("beta");
}

@Test // DATAJDBC614
@Test // DATAJDBC-614
public void withCombinesSortAndUnsortedPaging() {

Query query = Query.empty() //
Expand All @@ -62,4 +64,17 @@ public void withCombinesSortAndUnsortedPaging() {
.extracting(Sort.Order::getProperty) //
.containsExactly("alpha");
}

@Test // GH-1939
public void withCombinesUnpagedWithSort() {

Query query = Query.empty() //
.with(Pageable.unpaged(Sort.by("beta")));

assertThat(query.getSort().get()) //
.extracting(Sort.Order::getProperty) //
.containsExactly("beta");
assertThat(query.getLimit()).isEqualTo(-1);
assertThat(query.getOffset()).isEqualTo(-1);
}
}

0 comments on commit a4c462e

Please sign in to comment.