@@ -70,7 +70,7 @@ void supports() {
70
70
}
71
71
72
72
@ Test
73
- void resolve () {
73
+ void resolveWithInferredModelAttributeName () {
74
74
BindingResult bindingResult = createBindingResult (new Foo (), "foo" );
75
75
this .bindingContext .getModel ().asMap ().put (BindingResult .MODEL_KEY_PREFIX + "foo" , bindingResult );
76
76
@@ -82,11 +82,11 @@ void resolve() {
82
82
}
83
83
84
84
@ Test
85
- void resolveOnBindingResultAndModelAttributeWithCustomName () {
85
+ void resolveWithCustomModelAttributeNameConfiguredViaValueAttribute () {
86
86
BindingResult bindingResult = createBindingResult (new Foo (), "custom" );
87
87
this .bindingContext .getModel ().asMap ().put (BindingResult .MODEL_KEY_PREFIX + "custom" , bindingResult );
88
88
89
- ResolvableMethod testMethod = ResolvableMethod .on (getClass ()).named ("handleWithCustomModelAttributeName " ).build ();
89
+ ResolvableMethod testMethod = ResolvableMethod .on (getClass ()).named ("handleWithCustomModelAttributeNameViaValueAttribute " ).build ();
90
90
91
91
MethodParameter parameter = testMethod .arg (Errors .class );
92
92
Object actual = this .resolver .resolveArgument (parameter , this .bindingContext , this .exchange )
@@ -95,9 +95,18 @@ void resolveOnBindingResultAndModelAttributeWithCustomName() {
95
95
assertThat (actual ).isSameAs (bindingResult );
96
96
}
97
97
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 );
101
110
}
102
111
103
112
@ Test
@@ -113,11 +122,11 @@ void resolveWithMono() {
113
122
}
114
123
115
124
@ Test
116
- void resolveWithMonoOnBindingResultAndModelAttributeWithCustomName () {
125
+ void resolveWithMonoAndCustomModelAttributeNameConfiguredViaValueAttribute () {
117
126
BindingResult bindingResult = createBindingResult (new Foo (), "custom" );
118
127
this .bindingContext .getModel ().asMap ().put (BindingResult .MODEL_KEY_PREFIX + "custom" , Mono .just (bindingResult ));
119
128
120
- ResolvableMethod testMethod = ResolvableMethod .on (getClass ()).named ("handleWithCustomModelAttributeName " ).build ();
129
+ ResolvableMethod testMethod = ResolvableMethod .on (getClass ()).named ("handleWithCustomModelAttributeNameViaValueAttribute " ).build ();
121
130
122
131
MethodParameter parameter = testMethod .arg (Errors .class );
123
132
Object actual = this .resolver .resolveArgument (parameter , this .bindingContext , this .exchange )
@@ -146,6 +155,11 @@ void resolveWithBindingResultNotFound() {
146
155
"immediately after the @ModelAttribute argument" );
147
156
}
148
157
158
+ private BindingResult createBindingResult (Foo target , String name ) {
159
+ DataBinder binder = this .bindingContext .createDataBinder (this .exchange , target , name );
160
+ return binder .getBindingResult ();
161
+ }
162
+
149
163
150
164
@ SuppressWarnings ("unused" )
151
165
private static class Foo {
@@ -179,13 +193,15 @@ void handle(
179
193
}
180
194
181
195
@ SuppressWarnings ("unused" )
182
- void handleWithCustomModelAttributeName (
196
+ void handleWithCustomModelAttributeNameViaValueAttribute (
197
+ @ ModelAttribute ("custom" ) Foo foo ,
198
+ Errors errors ) {
199
+ }
200
+
201
+ @ SuppressWarnings ("unused" )
202
+ void handleWithCustomModelAttributeNameViaNameAttribute (
183
203
@ 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 ) {
189
205
}
190
206
191
207
}
0 commit comments