Allow combining Sort and TypedSort using Sort.and(…).

We now retain properly the collection of orders by using accessor methods instead of relying on using the orders field. TypedSort orders are not using the orders field, instead they iterate over recorded persistent property paths.

Closes #2103
Original pull request: #2377.
This commit is contained in:
Mark Paluch
2021-06-10 14:59:27 +02:00
parent f97b4b98ca
commit 9242b2c7b2
2 changed files with 18 additions and 5 deletions

View File

@@ -25,6 +25,7 @@ import java.util.Collection;
import org.junit.jupiter.api.Test;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;
import org.springframework.data.geo.Circle;
/**
* Unit test for {@link Sort}.
@@ -33,6 +34,7 @@ import org.springframework.data.domain.Sort.Order;
* @author Kevin Raymond
* @author Thomas Darimont
* @author Mark Paluch
* @author Hiufung Kwok
*/
class SortUnitTests {
@@ -186,6 +188,17 @@ class SortUnitTests {
.containsExactly(Order.by("nesteds.firstname"));
}
@Test // #2103
void allowsCombiningTypedSorts() {
assertThat(Sort.sort(Circle.class).by(Circle::getCenter) //
.and(Sort.sort(Circle.class).by(Circle::getRadius))) //
.containsExactly(Order.by("center"), Order.by("radius"));
assertThat(Sort.by("center").and(Sort.sort(Circle.class).by(Circle::getRadius))) //
.containsExactly(Order.by("center"), Order.by("radius"));
}
@Getter
static class Sample {
Nested nested;