Skip to content

Commit 017900f

Browse files
committed
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
1 parent a6bd18c commit 017900f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Diff for: src/main/java/org/springframework/data/domain/Sort.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public String toString() {
277277
*/
278278
private Sort withDirection(Direction direction) {
279279

280-
return Sort.by(stream().map(it -> new Order(direction, it.getProperty())).collect(Collectors.toList()));
280+
return Sort.by(stream().map(it -> it.with(direction)).collect(Collectors.toList()));
281281
}
282282

283283
/**

Diff for: src/test/java/org/springframework/data/domain/SortUnitTests.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,12 @@ void handlesAdditionalNullSort() {
104104
assertThat(sort).containsExactly(Order.by("foo"));
105105
}
106106

107-
@Test // DATACMNS-281, DATACMNS-1021
107+
@Test // DATACMNS-281, DATACMNS-1021, GH-2585
108108
void configuresIgnoreCaseForOrder() {
109+
109110
assertThat(Order.asc("foo").ignoreCase().isIgnoreCase()).isTrue();
111+
assertThat(Sort.by(Order.by("foo").ignoreCase()).descending().iterator().next().isIgnoreCase()).isTrue();
112+
assertThat(Sort.by(Order.by("foo").ignoreCase()).ascending().iterator().next().isIgnoreCase()).isTrue();
110113
}
111114

112115
@Test // DATACMNS-281, DATACMNS-1021
@@ -154,6 +157,15 @@ void orderWithDefaultNullHandlingHint() {
154157
assertThat(Order.by("foo").getNullHandling()).isEqualTo(NATIVE);
155158
}
156159

160+
@Test // GH-2585
161+
void retainsNullHandlingAfterChangingDirection() {
162+
163+
assertThat(Sort.by(Order.by("foo").with(NULLS_FIRST)).ascending().iterator().next().getNullHandling())
164+
.isEqualTo(NULLS_FIRST);
165+
assertThat(Sort.by(Order.by("foo").with(NULLS_FIRST)).descending().iterator().next().getNullHandling())
166+
.isEqualTo(NULLS_FIRST);
167+
}
168+
157169
@Test // DATACMNS-908
158170
void createsNewOrderForDifferentProperty() {
159171

0 commit comments

Comments
 (0)