DATACMNS-731 - Parameter now exposes whether it's named explicitly.

Parameter now has a isExplicitlyNamed() to indicate whether the user explicitly assigned a name to it in contrast to an implicitly discovered parameter name.
This commit is contained in:
Oliver Gierke
2015-07-15 16:18:37 +02:00
parent cd6b2c09c6
commit 174e9a6e93
2 changed files with 40 additions and 2 deletions

View File

@@ -24,6 +24,7 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.test.util.ReflectionTestUtils;
/**
* Unit test for {@link Parameters}.
@@ -123,8 +124,35 @@ public class ParametersUnitTests {
getParametersFor("validWithPageableFirst", Pageable.class, String.class);
}
private Parameters<?, ?> getParametersFor(String methodName, Class<?>... parameterTypes) throws SecurityException,
NoSuchMethodException {
/**
* @see DATACMNS-731
*/
@Test
public void detectsExplicitlyNamedParameter() throws Exception {
Parameter parameter = getParametersFor("valid", String.class).getBindableParameter(0);
assertThat(parameter.getName(), is(notNullValue()));
assertThat(parameter.isExplicitlyNamed(), is(true));
}
/**
* @see DATACMNS-731
*/
@Test
public void doesNotConsiderParameterExplicitlyNamedEvenIfNamePresent() throws Exception {
Parameter parameter = getParametersFor("validWithSortFirst", Sort.class, String.class).getBindableParameter(0);
Object methodParameter = ReflectionTestUtils.getField(parameter, "parameter");
ReflectionTestUtils.setField(methodParameter, "parameterName", "name");
assertThat(parameter.getName(), is(notNullValue()));
assertThat(parameter.isExplicitlyNamed(), is(false));
}
private Parameters<?, ?> getParametersFor(String methodName, Class<?>... parameterTypes)
throws SecurityException, NoSuchMethodException {
Method method = SampleDao.class.getMethod(methodName, parameterTypes);