Apply sort of unpaged Pageable to query.

Original pull request: #4773
Closes #4771
This commit is contained in:
Christoph Strobl
2024-08-29 13:02:22 +02:00
committed by Mark Paluch
parent 541c43b284
commit 4df06c7699
2 changed files with 13 additions and 0 deletions

View File

@@ -286,6 +286,9 @@ public class Query implements ReadConcernAware, ReadPreferenceAware {
public Query with(Pageable pageable) {
if (pageable.isUnpaged()) {
if(pageable.getSort().isSorted()) {
return with(pageable.getSort());
}
return this;
}

View File

@@ -23,6 +23,7 @@ import org.bson.Document;
import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.data.domain.Limit;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;
@@ -366,6 +367,15 @@ class QueryTests {
compareQueries(target, source);
}
@Test // GH-4771
void appliesSortOfUnpagedPageable() {
Query query = new Query();
query.with(Pageable.unpaged(Sort.by("sortMe")));
assertThat(query.isSorted()).isTrue();
}
private void compareQueries(Query actual, Query expected) {
assertThat(actual.getCollation()).isEqualTo(expected.getCollation());