|
25 | 25 | import jakarta.validation.constraints.Size;
|
26 | 26 | import org.junit.jupiter.api.Test;
|
27 | 27 |
|
| 28 | +import org.springframework.context.support.StaticApplicationContext; |
28 | 29 | import org.springframework.util.ClassUtils;
|
29 | 30 | import org.springframework.validation.annotation.Validated;
|
30 | 31 |
|
@@ -79,6 +80,23 @@ void createWithResolvedBeanSameInstance() {
|
79 | 80 | assertThat(handlerMethod.createWithResolvedBean()).isSameAs(handlerMethod);
|
80 | 81 | }
|
81 | 82 |
|
| 83 | + @Test |
| 84 | + void resolvedFromHandlerMethod() { |
| 85 | + StaticApplicationContext context = new StaticApplicationContext(); |
| 86 | + context.registerSingleton("myClass", MyClass.class); |
| 87 | + |
| 88 | + MyClass target = new MyClass(); |
| 89 | + Method method = ClassUtils.getMethod(target.getClass(), "addPerson", (Class<?>[]) null); |
| 90 | + |
| 91 | + HandlerMethod hm1 = new HandlerMethod("myClass", context.getBeanFactory(), method); |
| 92 | + HandlerMethod hm2 = hm1.createWithValidateFlags(); |
| 93 | + HandlerMethod hm3 = hm2.createWithResolvedBean(); |
| 94 | + |
| 95 | + assertThat(hm1.getResolvedFromHandlerMethod()).isNull(); |
| 96 | + assertThat(hm2.getResolvedFromHandlerMethod()).isSameAs(hm1); |
| 97 | + assertThat(hm3.getResolvedFromHandlerMethod()).isSameAs(hm1); |
| 98 | + } |
| 99 | + |
82 | 100 | private static void testValidateArgs(Object target, List<String> methodNames, boolean expected) {
|
83 | 101 | for (String methodName : methodNames) {
|
84 | 102 | assertThat(getHandlerMethod(target, methodName).shouldValidateArguments()).isEqualTo(expected);
|
|
0 commit comments