@@ -70,7 +70,7 @@ void supports() {
7070 }
7171
7272 @ Test
73- void resolve () {
73+ void resolveWithInferredModelAttributeName () {
7474 BindingResult bindingResult = createBindingResult (new Foo (), "foo" );
7575 this .bindingContext .getModel ().asMap ().put (BindingResult .MODEL_KEY_PREFIX + "foo" , bindingResult );
7676
@@ -82,11 +82,11 @@ void resolve() {
8282 }
8383
8484 @ Test
85- void resolveOnBindingResultAndModelAttributeWithCustomName () {
85+ void resolveWithCustomModelAttributeNameConfiguredViaValueAttribute () {
8686 BindingResult bindingResult = createBindingResult (new Foo (), "custom" );
8787 this .bindingContext .getModel ().asMap ().put (BindingResult .MODEL_KEY_PREFIX + "custom" , bindingResult );
8888
89- ResolvableMethod testMethod = ResolvableMethod .on (getClass ()).named ("handleWithCustomModelAttributeName " ).build ();
89+ ResolvableMethod testMethod = ResolvableMethod .on (getClass ()).named ("handleWithCustomModelAttributeNameViaValueAttribute " ).build ();
9090
9191 MethodParameter parameter = testMethod .arg (Errors .class );
9292 Object actual = this .resolver .resolveArgument (parameter , this .bindingContext , this .exchange )
@@ -95,9 +95,18 @@ void resolveOnBindingResultAndModelAttributeWithCustomName() {
9595 assertThat (actual ).isSameAs (bindingResult );
9696 }
9797
98- private BindingResult createBindingResult (Foo target , String name ) {
99- DataBinder binder = this .bindingContext .createDataBinder (this .exchange , target , name );
100- return binder .getBindingResult ();
98+ @ Test
99+ void resolveWithCustomModelAttributeNameConfiguredViaNameAttribute () {
100+ BindingResult bindingResult = createBindingResult (new Foo (), "custom" );
101+ this .bindingContext .getModel ().asMap ().put (BindingResult .MODEL_KEY_PREFIX + "custom" , bindingResult );
102+
103+ ResolvableMethod testMethod = ResolvableMethod .on (getClass ()).named ("handleWithCustomModelAttributeNameViaNameAttribute" ).build ();
104+
105+ MethodParameter parameter = testMethod .arg (Errors .class );
106+ Object actual = this .resolver .resolveArgument (parameter , this .bindingContext , this .exchange )
107+ .block (Duration .ofMillis (5000 ));
108+
109+ assertThat (actual ).isSameAs (bindingResult );
101110 }
102111
103112 @ Test
@@ -113,11 +122,11 @@ void resolveWithMono() {
113122 }
114123
115124 @ Test
116- void resolveWithMonoOnBindingResultAndModelAttributeWithCustomName () {
125+ void resolveWithMonoAndCustomModelAttributeNameConfiguredViaValueAttribute () {
117126 BindingResult bindingResult = createBindingResult (new Foo (), "custom" );
118127 this .bindingContext .getModel ().asMap ().put (BindingResult .MODEL_KEY_PREFIX + "custom" , Mono .just (bindingResult ));
119128
120- ResolvableMethod testMethod = ResolvableMethod .on (getClass ()).named ("handleWithCustomModelAttributeName " ).build ();
129+ ResolvableMethod testMethod = ResolvableMethod .on (getClass ()).named ("handleWithCustomModelAttributeNameViaValueAttribute " ).build ();
121130
122131 MethodParameter parameter = testMethod .arg (Errors .class );
123132 Object actual = this .resolver .resolveArgument (parameter , this .bindingContext , this .exchange )
@@ -146,6 +155,11 @@ void resolveWithBindingResultNotFound() {
146155 "immediately after the @ModelAttribute argument" );
147156 }
148157
158+ private BindingResult createBindingResult (Foo target , String name ) {
159+ DataBinder binder = this .bindingContext .createDataBinder (this .exchange , target , name );
160+ return binder .getBindingResult ();
161+ }
162+
149163
150164 @ SuppressWarnings ("unused" )
151165 private static class Foo {
@@ -179,13 +193,15 @@ void handle(
179193 }
180194
181195 @ SuppressWarnings ("unused" )
182- void handleWithCustomModelAttributeName (
196+ void handleWithCustomModelAttributeNameViaValueAttribute (
197+ @ ModelAttribute ("custom" ) Foo foo ,
198+ Errors errors ) {
199+ }
200+
201+ @ SuppressWarnings ("unused" )
202+ void handleWithCustomModelAttributeNameViaNameAttribute (
183203 @ ModelAttribute (name = "custom" ) Foo foo ,
184- Errors errors ,
185- @ ModelAttribute Mono <Foo > fooMono ,
186- BindingResult bindingResult ,
187- Mono <Errors > errorsMono ,
188- String string ) {
204+ Errors errors ) {
189205 }
190206
191207}
0 commit comments