@@ -193,9 +193,30 @@ void shouldAllowReverseSort() {
193
193
window = template .scroll (q .with (window .positionAt (0 )).limit (2 ), Person .class );
194
194
195
195
assertThat (window ).hasSize (2 );
196
- assertThat (window ).containsOnly (john20 , john40_1 );
197
- assertThat (window .hasNext ()).isTrue ();
198
- assertThat (window .isLast ()).isFalse ();
196
+ assertThat (window ).containsOnly (jane_20 , jane_40 );
197
+ assertThat (window .hasNext ()).isFalse ();
198
+ assertThat (window .isLast ()).isTrue ();
199
+ }
200
+
201
+ @ Test // GH-4413
202
+ void shouldAllowInitialBackwardSort () {
203
+
204
+ Person jane_20 = new Person ("Jane" , 20 );
205
+ Person jane_40 = new Person ("Jane" , 40 );
206
+ Person jane_42 = new Person ("Jane" , 42 );
207
+ Person john20 = new Person ("John" , 20 );
208
+ Person john40_1 = new Person ("John" , 40 );
209
+ Person john40_2 = new Person ("John" , 40 );
210
+
211
+ template .insertAll (Arrays .asList (john20 , john40_1 , john40_2 , jane_20 , jane_40 , jane_42 ));
212
+ Query q = new Query (where ("firstName" ).regex ("J.*" )).with (Sort .by ("firstName" , "age" ));
213
+ q .with (ScrollPosition .keyset ().backward ()).limit (3 );
214
+
215
+ Window <Person > window = template .scroll (q , Person .class );
216
+ assertThat (window ).containsExactly (john20 , john40_1 , john40_2 );
217
+
218
+ window = template .scroll (q .with (window .positionAt (0 )).limit (3 ), Person .class );
219
+ assertThat (window ).containsExactly (jane_20 , jane_40 , jane_42 );
199
220
}
200
221
201
222
@ ParameterizedTest // GH-4308
@@ -276,8 +297,7 @@ static Stream<Arguments> positions() {
276
297
return Stream .of (args (ScrollPosition .keyset (), Person .class , Function .identity ()), //
277
298
args (ScrollPosition .keyset (), Document .class , MongoTemplateScrollTests ::toDocument ), //
278
299
args (ScrollPosition .offset (), Person .class , Function .identity ()), //
279
- args (ScrollPosition .offset (), PersonDtoProjection .class ,
280
- MongoTemplateScrollTests ::toPersonDtoProjection ), //
300
+ args (ScrollPosition .offset (), PersonDtoProjection .class , MongoTemplateScrollTests ::toPersonDtoProjection ), //
281
301
args (ScrollPosition .offset (), PersonInterfaceProjection .class ,
282
302
MongoTemplateScrollTests ::toPersonInterfaceProjection , MongoTemplateScrollTests ::compareProxies ));
283
303
}
0 commit comments