Allow reversing Sort.

We now allow reversing the sort order of Sort instances to flip ASC and DESC sort orders.

Closes #2805
This commit is contained in:
Mark Paluch
2023-05-11 15:59:42 +02:00
parent 1ba2932275
commit 46ff9d25a6
2 changed files with 59 additions and 3 deletions

View File

@@ -201,6 +201,21 @@ class SortUnitTests {
.containsExactly(Order.by("center"), Order.by("radius"));
}
@Test // GH-2805
void reversesSortCorrectly() {
assertThat(Sort.by(Order.asc("center"), Order.desc("radius")).reverse()) //
.containsExactly(Order.desc("center"), Order.asc("radius"));
}
@Test // GH-2805
void reversesTypedSortCorrectly() {
Sort reverse = Sort.sort(Circle.class).by(Circle::getCenter).reverse();
assertThat(reverse) //
.containsExactly(Order.desc("center"));
}
@Getter
static class Sample {
Nested nested;