DATACMNS-753 - Fixed default handling of empty sort parameter.

We now correctly inspect the sort parameter values and also fall back to the default if a single, empty parameter value is given.

Related ticket: DATACMNS-408.
Related pull request: #138.
This commit is contained in:
Oliver Gierke
2015-09-09 17:56:27 +02:00
parent 9d9f230ed4
commit 01f2c30b1d
2 changed files with 27 additions and 23 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 the original author or authors.
* Copyright 2013-2015 the 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.
@@ -149,21 +149,6 @@ public class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitT
assertThat(resolveSort(request, PARAMETER), is(nullValue()));
}
/**
*
* @see DATACMNS-753
* see also DATACMNS-408
*/
@Test
public void doesNotReturnNullWhenAnnotatedWithSortDefault() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("sort", ""); //valid input
assertNotNull(resolveSort(request, getParameterOfMethod("simpleDefault")));
assertNotNull(resolveSort(request, getParameterOfMethod("containeredDefault")));
}
/**
* @see DATACMNS-408
*/
@@ -213,6 +198,19 @@ public class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitT
assertThat(resolveSort(request, PARAMETER), is(nullValue()));
}
/**
* @see DATACMNS-753, DATACMNS-408
*/
@Test
public void doesNotReturnNullWhenAnnotatedWithSortDefault() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("sort", "");
assertThat(resolveSort(request, getParameterOfMethod("simpleDefault")), is(new Sort("firstname", "lastname")));
assertThat(resolveSort(request, getParameterOfMethod("containeredDefault")), is(new Sort("foo", "bar")));
}
private static Sort resolveSort(HttpServletRequest request, MethodParameter parameter) throws Exception {
SortHandlerMethodArgumentResolver resolver = new SortHandlerMethodArgumentResolver();