Retain case-sensitivity and null-handling when changing Sort direction.
We now retain case-sensitivity and null-handling configuration when changing the entire Sort direction. Closes #2585
This commit is contained in:
@@ -277,7 +277,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
|
||||
*/
|
||||
private Sort withDirection(Direction direction) {
|
||||
|
||||
return Sort.by(stream().map(it -> new Order(direction, it.getProperty())).collect(Collectors.toList()));
|
||||
return Sort.by(stream().map(it -> it.with(direction)).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -104,9 +104,12 @@ class SortUnitTests {
|
||||
assertThat(sort).containsExactly(Order.by("foo"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-281, DATACMNS-1021
|
||||
@Test // DATACMNS-281, DATACMNS-1021, GH-2585
|
||||
void configuresIgnoreCaseForOrder() {
|
||||
|
||||
assertThat(Order.asc("foo").ignoreCase().isIgnoreCase()).isTrue();
|
||||
assertThat(Sort.by(Order.by("foo").ignoreCase()).descending().iterator().next().isIgnoreCase()).isTrue();
|
||||
assertThat(Sort.by(Order.by("foo").ignoreCase()).ascending().iterator().next().isIgnoreCase()).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-281, DATACMNS-1021
|
||||
@@ -154,6 +157,15 @@ class SortUnitTests {
|
||||
assertThat(Order.by("foo").getNullHandling()).isEqualTo(NATIVE);
|
||||
}
|
||||
|
||||
@Test // GH-2585
|
||||
void retainsNullHandlingAfterChangingDirection() {
|
||||
|
||||
assertThat(Sort.by(Order.by("foo").with(NULLS_FIRST)).ascending().iterator().next().getNullHandling())
|
||||
.isEqualTo(NULLS_FIRST);
|
||||
assertThat(Sort.by(Order.by("foo").with(NULLS_FIRST)).descending().iterator().next().getNullHandling())
|
||||
.isEqualTo(NULLS_FIRST);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-908
|
||||
void createsNewOrderForDifferentProperty() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user