Search in sources :

Example 6 with MethodExecutor

use of org.springframework.expression.MethodExecutor in project spring-framework by spring-projects.

the class SpelReproTests method wideningPrimitiveConversion_8224.

/**
	 * Test whether {@link ReflectiveMethodResolver} handles Widening Primitive Conversion. That's passing an 'int' to a
	 * method accepting 'long' is ok.
	 */
@Test
public void wideningPrimitiveConversion_8224() throws Exception {
    class WideningPrimitiveConversion {

        public int getX(long i) {
            return 10;
        }
    }
    final Integer INTEGER_VALUE = Integer.valueOf(7);
    WideningPrimitiveConversion target = new WideningPrimitiveConversion();
    EvaluationContext emptyEvalContext = new StandardEvaluationContext();
    List<TypeDescriptor> args = new ArrayList<>();
    args.add(TypeDescriptor.forObject(INTEGER_VALUE));
    MethodExecutor me = new ReflectiveMethodResolver(true).resolve(emptyEvalContext, target, "getX", args);
    final int actual = (Integer) me.execute(emptyEvalContext, target, INTEGER_VALUE).getValue();
    final int compiler = target.getX(INTEGER_VALUE);
    assertEquals(compiler, actual);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) TypeDescriptor(org.springframework.core.convert.TypeDescriptor) ReflectiveMethodResolver(org.springframework.expression.spel.support.ReflectiveMethodResolver) MethodExecutor(org.springframework.expression.MethodExecutor) ArrayList(java.util.ArrayList) EvaluationContext(org.springframework.expression.EvaluationContext) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Test(org.junit.Test)

Aggregations

TypeDescriptor (org.springframework.core.convert.TypeDescriptor)6 MethodExecutor (org.springframework.expression.MethodExecutor)6 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 EvaluationContext (org.springframework.expression.EvaluationContext)4 ReflectiveMethodResolver (org.springframework.expression.spel.support.ReflectiveMethodResolver)4 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Method (java.lang.reflect.Method)2 MethodParameter (org.springframework.core.MethodParameter)2 AccessException (org.springframework.expression.AccessException)2 Ignore (org.junit.Ignore)1 ExpectedException (org.junit.rules.ExpectedException)1 EvaluationException (org.springframework.expression.EvaluationException)1 Expression (org.springframework.expression.Expression)1 ExpressionException (org.springframework.expression.ExpressionException)1 ExpressionParser (org.springframework.expression.ExpressionParser)1 MethodResolver (org.springframework.expression.MethodResolver)1 TypedValue (org.springframework.expression.TypedValue)1 SpelEvaluationException (org.springframework.expression.spel.SpelEvaluationException)1