|
22 | 22 | import java.util.ArrayList;
|
23 | 23 | import java.util.Collections;
|
24 | 24 | import java.util.List;
|
| 25 | +import java.util.Map; |
25 | 26 | import java.util.NoSuchElementException;
|
26 | 27 | import java.util.function.Function;
|
27 | 28 |
|
|
30 | 31 | import org.mockito.junit.jupiter.MockitoExtension;
|
31 | 32 | import org.mockito.junit.jupiter.MockitoSettings;
|
32 | 33 | import org.mockito.quality.Strictness;
|
| 34 | +import org.springframework.data.domain.ScrollPosition.Direction; |
33 | 35 | import org.springframework.data.support.WindowIterator;
|
| 36 | +import org.springframework.data.util.Streamable; |
34 | 37 |
|
35 | 38 | /**
|
36 | 39 | * Unit tests for {@link WindowIterator}.
|
@@ -127,4 +130,28 @@ void allowsToIterateAllWindows() {
|
127 | 130 |
|
128 | 131 | assertThat(capturedResult).containsExactly("a", "b", "c", "d");
|
129 | 132 | }
|
| 133 | + |
| 134 | + @Test // GH-2151 |
| 135 | + void considersBackwardKeysetScrolling() { |
| 136 | + |
| 137 | + Window<String> initial = Window.from(List.of("c", "d"), |
| 138 | + value -> KeysetScrollPosition.of(Map.of("k", 10 + value), Direction.BACKWARD), true); |
| 139 | + Window<String> terminal = Window.from(List.of("a", "b"), |
| 140 | + value -> KeysetScrollPosition.of(Map.of("k", value), Direction.BACKWARD)); |
| 141 | + |
| 142 | + WindowIterator<String> iterator = WindowIterator.of(it -> { |
| 143 | + |
| 144 | + if (it instanceof KeysetScrollPosition ksp) { |
| 145 | + if (Integer.valueOf(10).equals(ksp.getKeys().get("k"))) { |
| 146 | + return terminal; |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + return initial; |
| 151 | + |
| 152 | + }).startingAt(ScrollPosition.keyset().backward()); |
| 153 | + |
| 154 | + List<String> items = Streamable.of(() -> iterator).toList(); |
| 155 | + assertThat(items).containsExactly("c", "d", "a", "b"); |
| 156 | + } |
130 | 157 | }
|
0 commit comments