@ -25,6 +25,7 @@ import jakarta.validation.constraints.NotEmpty;
@@ -25,6 +25,7 @@ import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size ;
import org.junit.jupiter.api.Test ;
import org.springframework.context.support.StaticApplicationContext ;
import org.springframework.util.ClassUtils ;
import org.springframework.validation.annotation.Validated ;
@ -79,6 +80,23 @@ class HandlerMethodTests {
@@ -79,6 +80,23 @@ class HandlerMethodTests {
assertThat ( handlerMethod . createWithResolvedBean ( ) ) . isSameAs ( handlerMethod ) ;
}
@Test
void resolvedFromHandlerMethod ( ) {
StaticApplicationContext context = new StaticApplicationContext ( ) ;
context . registerSingleton ( "myClass" , MyClass . class ) ;
MyClass target = new MyClass ( ) ;
Method method = ClassUtils . getMethod ( target . getClass ( ) , "addPerson" , ( Class < ? > [ ] ) null ) ;
HandlerMethod hm1 = new HandlerMethod ( "myClass" , context . getBeanFactory ( ) , method ) ;
HandlerMethod hm2 = hm1 . createWithValidateFlags ( ) ;
HandlerMethod hm3 = hm2 . createWithResolvedBean ( ) ;
assertThat ( hm1 . getResolvedFromHandlerMethod ( ) ) . isNull ( ) ;
assertThat ( hm2 . getResolvedFromHandlerMethod ( ) ) . isSameAs ( hm1 ) ;
assertThat ( hm3 . getResolvedFromHandlerMethod ( ) ) . isSameAs ( hm1 ) ;
}
private static void testValidateArgs ( Object target , List < String > methodNames , boolean expected ) {
for ( String methodName : methodNames ) {
assertThat ( getHandlerMethod ( target , methodName ) . shouldValidateArguments ( ) ) . isEqualTo ( expected ) ;