Revise contribution
See gh-25316
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,21 +18,25 @@ package org.springframework.expression.spel.support;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.expression.*;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.MethodExecutor;
|
||||
import org.springframework.expression.MethodResolver;
|
||||
import org.springframework.expression.ParseException;
|
||||
import org.springframework.expression.PropertyAccessor;
|
||||
import org.springframework.expression.TypedValue;
|
||||
import org.springframework.expression.spel.AbstractExpressionTests;
|
||||
import org.springframework.expression.spel.SpelUtilities;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
import org.springframework.expression.spel.support.ReflectionHelper.ArgumentsMatchKind;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
@@ -365,17 +369,18 @@ public class ReflectionHelperTests extends AbstractExpressionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testReflectiveMethodResolver() throws AccessException {
|
||||
MethodResolver resolver=new ReflectiveMethodResolver();
|
||||
void reflectiveMethodResolverForJdkProxies() throws Exception {
|
||||
Object proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[] { Runnable.class }, (p, m, args) -> null);
|
||||
|
||||
MethodResolver resolver = new ReflectiveMethodResolver();
|
||||
StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
|
||||
Object obj= Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[]{Runnable.class}, new InvocationHandler() {
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
MethodExecutor mexec=resolver.resolve(evaluationContext,obj,"toString",new ArrayList<>());
|
||||
Assert.notNull(mexec,"MethodExecutor should not be empty.");
|
||||
|
||||
MethodExecutor bogus = resolver.resolve(evaluationContext, proxy, "bogus", Collections.emptyList());
|
||||
assertThat(bogus).as("MethodExecutor for bogus()").isNull();
|
||||
MethodExecutor toString = resolver.resolve(evaluationContext, proxy, "toString", Collections.emptyList());
|
||||
assertThat(toString).as("MethodExecutor for toString()").isNotNull();
|
||||
MethodExecutor hashCode = resolver.resolve(evaluationContext, proxy, "hashCode", Collections.emptyList());
|
||||
assertThat(hashCode).as("MethodExecutor for hashCode()").isNotNull();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user