Skip to content

Parameter direction should not be ignored if keys is empty #2841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*
* @author Mark Paluch
* @author Oliver Drotbohm
* @author Yanming Zhou
* @since 3.1
*/
public final class KeysetScrollPosition implements ScrollPosition {
Expand Down Expand Up @@ -70,7 +71,7 @@ static KeysetScrollPosition of(Map<String, ?> keys, Direction direction) {
Assert.notNull(keys, "Keys must not be null");
Assert.notNull(direction, "Direction must not be null");

return keys.isEmpty()
return keys.isEmpty() && direction == Direction.FORWARD
? initial()
: new KeysetScrollPosition(Collections.unmodifiableMap(new LinkedHashMap<>(keys)), direction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*
* @author Mark Paluch
* @author Oliver Drotbohm
* @author Yanming Zhou
*/
class ScrollPositionUnitTests {

Expand Down Expand Up @@ -137,4 +138,14 @@ void initialKeysetPosition() {
assertThat(keyset.isInitial()).isTrue();
assertThat(keyset.scrollsForward()).isTrue();
}

@Test // GH-2840
void keysetPositionWithEmptyKeys() {

KeysetScrollPosition forwardEmptyKeyset = ScrollPosition.of(Collections.emptyMap(), Direction.FORWARD);
KeysetScrollPosition backwordEmptyKeyset = ScrollPosition.of(Collections.emptyMap(), Direction.BACKWARD);

assertThat(forwardEmptyKeyset.isInitial()).isTrue();
assertThat(backwordEmptyKeyset.scrollsBackward()).isTrue();
}
}