|
18 | 18 |
|
19 | 19 | import java.io.ByteArrayOutputStream;
|
20 | 20 | import java.io.PrintStream;
|
21 |
| -import java.lang.reflect.InvocationHandler; |
22 | 21 | import java.lang.reflect.Method;
|
23 | 22 | import java.lang.reflect.Proxy;
|
24 | 23 | import java.util.ArrayList;
|
|
27 | 26 | import org.junit.jupiter.api.Test;
|
28 | 27 |
|
29 | 28 | import org.springframework.core.convert.TypeDescriptor;
|
30 |
| -import org.springframework.expression.*; |
| 29 | +import org.springframework.expression.EvaluationContext; |
| 30 | +import org.springframework.expression.MethodExecutor; |
| 31 | +import org.springframework.expression.MethodResolver; |
| 32 | +import org.springframework.expression.ParseException; |
| 33 | +import org.springframework.expression.PropertyAccessor; |
| 34 | +import org.springframework.expression.TypedValue; |
31 | 35 | import org.springframework.expression.spel.AbstractExpressionTests;
|
32 | 36 | import org.springframework.expression.spel.SpelUtilities;
|
33 | 37 | import org.springframework.expression.spel.standard.SpelExpression;
|
34 | 38 | import org.springframework.expression.spel.support.ReflectionHelper.ArgumentsMatchKind;
|
35 |
| -import org.springframework.util.Assert; |
36 | 39 |
|
37 | 40 | import static org.assertj.core.api.Assertions.assertThat;
|
38 | 41 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
@@ -365,17 +368,18 @@ public void testOptimalReflectivePropertyAccessor() throws Exception {
|
365 | 368 | }
|
366 | 369 |
|
367 | 370 | @Test
|
368 |
| - void testReflectiveMethodResolver() throws AccessException { |
369 |
| - MethodResolver resolver=new ReflectiveMethodResolver(); |
| 371 | + void reflectiveMethodResolverForJdkProxies() throws Exception { |
| 372 | + Object proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[] { Runnable.class }, (p, m, args) -> null); |
| 373 | + |
| 374 | + MethodResolver resolver = new ReflectiveMethodResolver(); |
370 | 375 | StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
|
371 |
| - Object obj= Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[]{Runnable.class}, new InvocationHandler() { |
372 |
| - @Override |
373 |
| - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { |
374 |
| - return null; |
375 |
| - } |
376 |
| - }); |
377 |
| - MethodExecutor mexec=resolver.resolve(evaluationContext,obj,"toString",new ArrayList<>()); |
378 |
| - Assert.notNull(mexec,"MethodExecutor should not be empty."); |
| 376 | + |
| 377 | + MethodExecutor bogus = resolver.resolve(evaluationContext, proxy, "bogus", List.of()); |
| 378 | + assertThat(bogus).as("MethodExecutor for bogus()").isNull(); |
| 379 | + MethodExecutor toString = resolver.resolve(evaluationContext, proxy, "toString", List.of()); |
| 380 | + assertThat(toString).as("MethodExecutor for toString()").isNotNull(); |
| 381 | + MethodExecutor hashCode = resolver.resolve(evaluationContext, proxy, "hashCode", List.of()); |
| 382 | + assertThat(hashCode).as("MethodExecutor for hashCode()").isNotNull(); |
379 | 383 | }
|
380 | 384 |
|
381 | 385 | /**
|
|
0 commit comments