Skip to content

Commit

Permalink
DATACMNS-1455 - HateoasPageableHandlerMethodArgumentResolver handles …
Browse files Browse the repository at this point in the history
…Pageable.unpaged() coprrectly.

Pageable.unpaged() is now effectively handled like a null value given in the 1.x branch.
  • Loading branch information
odrotbohm committed Dec 21, 2018
1 parent 96942e4 commit c209737
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -104,12 +105,18 @@ public TemplateVariables getPaginationTemplateVariables(MethodParameter paramete
@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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ public void enablingOneIndexedParameterReturnsOneForFirstPage() {
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() {

Expand Down

0 comments on commit c209737

Please sign in to comment.