DATAREST-1427 - Fixed handling of unpaged Pageable values.

This commit is contained in:
Oliver Drotbohm
2019-09-25 14:27:00 +02:00
parent 051479481b
commit 384e0ed0cd
2 changed files with 10 additions and 5 deletions

View File

@@ -65,11 +65,12 @@ public class MappingAwarePageableArgumentResolver implements HandlerMethodArgume
Pageable pageable = delegate.resolveArgument(methodParameter, mavContainer, webRequest, binderFactory);
if (pageable == null || pageable.getSort() == null) {
if (pageable.isUnpaged() || pageable.getSort().isUnsorted()) {
return pageable;
}
Sort translated = translator.translateSort(pageable.getSort(), methodParameter, webRequest);
return PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), translated);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 original author or authors.
* Copyright 2016-2019 original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@ import org.springframework.web.method.support.ModelAndViewContainer;
* Unit tests for {@link MappingAwarePageableArgumentResolver}.
*
* @author Mark Paluch
* @author Oliver Drotbohm
*/
@RunWith(MockitoJUnitRunner.class)
public class MappingAwarePageableArgumentResolverUnitTests {
@@ -82,14 +83,17 @@ public class MappingAwarePageableArgumentResolverUnitTests {
assertThat(result.getPageSize()).isEqualTo(1);
assertThat(result.getPageNumber()).isEqualTo(0);
assertThat(result.getSort()).isNull();
assertThat(result.getSort().isUnsorted()).isTrue();
}
@Test // DATAREST-906
public void resolveArgumentShouldReturnNoPageable() throws Exception {
public void resolveArgumentShouldReturnUnpagedPageable() throws Exception {
when(delegate.resolveArgument(parameter, modelAndViewContainer, webRequest, binderFactory))
.thenReturn(Pageable.unpaged());
Pageable result = resolver.resolveArgument(parameter, modelAndViewContainer, webRequest, binderFactory);
assertThat(result).isNull();
assertThat(result.isUnpaged()).isTrue();
}
}