|
|
|
@ -28,9 +28,9 @@ import org.springframework.beans.testfixture.beans.TestBean; |
|
|
|
import org.springframework.core.MethodParameter; |
|
|
|
import org.springframework.core.MethodParameter; |
|
|
|
import org.springframework.core.annotation.SynthesizingMethodParameter; |
|
|
|
import org.springframework.core.annotation.SynthesizingMethodParameter; |
|
|
|
import org.springframework.format.support.DefaultFormattingConversionService; |
|
|
|
import org.springframework.format.support.DefaultFormattingConversionService; |
|
|
|
import org.springframework.validation.BindException; |
|
|
|
|
|
|
|
import org.springframework.validation.BindingResult; |
|
|
|
import org.springframework.validation.BindingResult; |
|
|
|
import org.springframework.validation.Errors; |
|
|
|
import org.springframework.validation.Errors; |
|
|
|
|
|
|
|
import org.springframework.web.bind.MethodArgumentNotValidException; |
|
|
|
import org.springframework.web.bind.WebDataBinder; |
|
|
|
import org.springframework.web.bind.WebDataBinder; |
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute; |
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute; |
|
|
|
import org.springframework.web.bind.annotation.SessionAttributes; |
|
|
|
import org.springframework.web.bind.annotation.SessionAttributes; |
|
|
|
@ -109,7 +109,7 @@ public class ModelAttributeMethodProcessorTests { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void supportedParameters() throws Exception { |
|
|
|
public void supportedParameters() { |
|
|
|
assertThat(this.processor.supportsParameter(this.paramNamedValidModelAttr)).isTrue(); |
|
|
|
assertThat(this.processor.supportsParameter(this.paramNamedValidModelAttr)).isTrue(); |
|
|
|
assertThat(this.processor.supportsParameter(this.paramModelAttr)).isTrue(); |
|
|
|
assertThat(this.processor.supportsParameter(this.paramModelAttr)).isTrue(); |
|
|
|
|
|
|
|
|
|
|
|
@ -119,8 +119,8 @@ public class ModelAttributeMethodProcessorTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void supportedParametersInDefaultResolutionMode() throws Exception { |
|
|
|
public void supportedParametersInDefaultResolutionMode() { |
|
|
|
processor = new ModelAttributeMethodProcessor(true); |
|
|
|
this.processor = new ModelAttributeMethodProcessor(true); |
|
|
|
|
|
|
|
|
|
|
|
// Only non-simple types, even if not annotated
|
|
|
|
// Only non-simple types, even if not annotated
|
|
|
|
assertThat(this.processor.supportsParameter(this.paramNamedValidModelAttr)).isTrue(); |
|
|
|
assertThat(this.processor.supportsParameter(this.paramNamedValidModelAttr)).isTrue(); |
|
|
|
@ -132,21 +132,21 @@ public class ModelAttributeMethodProcessorTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void supportedReturnTypes() throws Exception { |
|
|
|
public void supportedReturnTypes() { |
|
|
|
processor = new ModelAttributeMethodProcessor(false); |
|
|
|
this.processor = new ModelAttributeMethodProcessor(false); |
|
|
|
assertThat(this.processor.supportsReturnType(returnParamNamedModelAttr)).isTrue(); |
|
|
|
assertThat(this.processor.supportsReturnType(returnParamNamedModelAttr)).isTrue(); |
|
|
|
assertThat(this.processor.supportsReturnType(returnParamNonSimpleType)).isFalse(); |
|
|
|
assertThat(this.processor.supportsReturnType(returnParamNonSimpleType)).isFalse(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void supportedReturnTypesInDefaultResolutionMode() throws Exception { |
|
|
|
public void supportedReturnTypesInDefaultResolutionMode() { |
|
|
|
processor = new ModelAttributeMethodProcessor(true); |
|
|
|
this.processor = new ModelAttributeMethodProcessor(true); |
|
|
|
assertThat(this.processor.supportsReturnType(returnParamNamedModelAttr)).isTrue(); |
|
|
|
assertThat(this.processor.supportsReturnType(returnParamNamedModelAttr)).isTrue(); |
|
|
|
assertThat(this.processor.supportsReturnType(returnParamNonSimpleType)).isTrue(); |
|
|
|
assertThat(this.processor.supportsReturnType(returnParamNonSimpleType)).isTrue(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void bindExceptionRequired() throws Exception { |
|
|
|
public void bindExceptionRequired() { |
|
|
|
assertThat(this.processor.isBindExceptionRequired(null, this.paramNonSimpleType)).isTrue(); |
|
|
|
assertThat(this.processor.isBindExceptionRequired(null, this.paramNonSimpleType)).isTrue(); |
|
|
|
assertThat(this.processor.isBindExceptionRequired(null, this.paramNamedValidModelAttr)).isFalse(); |
|
|
|
assertThat(this.processor.isBindExceptionRequired(null, this.paramNamedValidModelAttr)).isFalse(); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -227,11 +227,13 @@ public class ModelAttributeMethodProcessorTests { |
|
|
|
|
|
|
|
|
|
|
|
StubRequestDataBinder dataBinder = new StubRequestDataBinder(target, name); |
|
|
|
StubRequestDataBinder dataBinder = new StubRequestDataBinder(target, name); |
|
|
|
dataBinder.getBindingResult().reject("error"); |
|
|
|
dataBinder.getBindingResult().reject("error"); |
|
|
|
|
|
|
|
|
|
|
|
WebDataBinderFactory binderFactory = mock(); |
|
|
|
WebDataBinderFactory binderFactory = mock(); |
|
|
|
given(binderFactory.createBinder(this.request, target, name)).willReturn(dataBinder); |
|
|
|
given(binderFactory.createBinder(this.request, target, name)).willReturn(dataBinder); |
|
|
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(BindException.class).isThrownBy(() -> |
|
|
|
assertThatExceptionOfType(MethodArgumentNotValidException.class).isThrownBy(() -> |
|
|
|
this.processor.resolveArgument(this.paramNonSimpleType, this.container, this.request, binderFactory)); |
|
|
|
this.processor.resolveArgument(this.paramNonSimpleType, this.container, this.request, binderFactory)); |
|
|
|
|
|
|
|
|
|
|
|
verify(binderFactory).createBinder(this.request, target, name); |
|
|
|
verify(binderFactory).createBinder(this.request, target, name); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|