DATACMNS-1455 - HateoasPageableHandlerMethodArgumentResolver handles Pageable.unpaged() coprrectly.

Pageable.unpaged() is now effectively handled like a null value given in the 1.x branch.
This commit is contained in:
Oliver Drotbohm
2018-12-21 09:55:11 +01:00
parent bb44322b3a
commit 566e6a3258
2 changed files with 17 additions and 0 deletions

View File

@@ -28,6 +28,7 @@ import org.springframework.hateoas.TemplateVariable.VariableType;
import org.springframework.hateoas.TemplateVariables;
import org.springframework.hateoas.mvc.UriComponentsContributor;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
@@ -104,12 +105,18 @@ public class HateoasPageableHandlerMethodArgumentResolver extends PageableHandle
@Override
public void enhance(UriComponentsBuilder builder, @Nullable MethodParameter parameter, Object value) {
Assert.notNull(builder, "UriComponentsBuilder must not be null!");
if (!(value instanceof Pageable)) {
return;
}
Pageable pageable = (Pageable) value;
if (pageable.isUnpaged()) {
return;
}
String pagePropertyName = getParameterNameToUse(getPageParameterName(), parameter);
String sizePropertyName = getParameterNameToUse(getSizeParameterName(), parameter);

View File

@@ -109,6 +109,16 @@ public class HateoasPageableHandlerMethodArgumentResolverUnitTests
assertThat(params.getFirst(resolver.getPageParameterName())).isEqualTo("1");
}
@Test // DATACMNS-1455
public void enhancesUnpaged() {
UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/");
getResolver().enhance(builder, null, Pageable.unpaged());
assertThat(builder).isEqualTo(builder);
}
@Override
protected HateoasPageableHandlerMethodArgumentResolver getResolver() {