Consistent target method resolution for event and caching expressions

Issue: SPR-16779
This commit is contained in:
Juergen Hoeller
2018-04-27 18:23:42 +02:00
parent aa11721ff0
commit eaff2c28a7
6 changed files with 72 additions and 119 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@@ -59,7 +59,7 @@ public class ExpressionEvaluatorTests {
@Test
public void testMultipleCachingSource() throws Exception {
public void testMultipleCachingSource() {
Collection<CacheOperation> ops = getOps("multipleCaching");
assertEquals(2, ops.size());
Iterator<CacheOperation> it = ops.iterator();
@@ -74,19 +74,18 @@ public class ExpressionEvaluatorTests {
}
@Test
public void testMultipleCachingEval() throws Exception {
public void testMultipleCachingEval() {
AnnotatedClass target = new AnnotatedClass();
Method method = ReflectionUtils.findMethod(AnnotatedClass.class, "multipleCaching", Object.class,
Object.class);
Object[] args = new Object[] { new Object(), new Object() };
Method method = ReflectionUtils.findMethod(
AnnotatedClass.class, "multipleCaching", Object.class, Object.class);
Object[] args = new Object[] {new Object(), new Object()};
Collection<ConcurrentMapCache> caches = Collections.singleton(new ConcurrentMapCache("test"));
EvaluationContext evalCtx = this.eval.createEvaluationContext(caches, method, args,
target, target.getClass(), null);
target, target.getClass(), method, CacheOperationExpressionEvaluator.NO_RESULT, null);
Collection<CacheOperation> ops = getOps("multipleCaching");
Iterator<CacheOperation> it = ops.iterator();
AnnotatedElementKey key = new AnnotatedElementKey(method, AnnotatedClass.class);
Object keyA = this.eval.key(it.next().getKey(), key, evalCtx);
@@ -97,28 +96,28 @@ public class ExpressionEvaluatorTests {
}
@Test
public void withReturnValue() throws Exception {
public void withReturnValue() {
EvaluationContext context = createEvaluationContext("theResult");
Object value = new SpelExpressionParser().parseExpression("#result").getValue(context);
assertThat(value, equalTo("theResult"));
}
@Test
public void withNullReturn() throws Exception {
public void withNullReturn() {
EvaluationContext context = createEvaluationContext(null);
Object value = new SpelExpressionParser().parseExpression("#result").getValue(context);
assertThat(value, nullValue());
}
@Test
public void withoutReturnValue() throws Exception {
public void withoutReturnValue() {
EvaluationContext context = createEvaluationContext(CacheOperationExpressionEvaluator.NO_RESULT);
Object value = new SpelExpressionParser().parseExpression("#result").getValue(context);
assertThat(value, nullValue());
}
@Test
public void unavailableReturnValue() throws Exception {
public void unavailableReturnValue() {
EvaluationContext context = createEvaluationContext(CacheOperationExpressionEvaluator.RESULT_UNAVAILABLE);
try {
new SpelExpressionParser().parseExpression("#result").getValue(context);
@@ -130,7 +129,7 @@ public class ExpressionEvaluatorTests {
}
@Test
public void resolveBeanReference() throws Exception {
public void resolveBeanReference() {
StaticApplicationContext applicationContext = new StaticApplicationContext();
BeanDefinition beanDefinition = new RootBeanDefinition(String.class);
applicationContext.registerBeanDefinition("myBean", beanDefinition);
@@ -147,11 +146,12 @@ public class ExpressionEvaluatorTests {
private EvaluationContext createEvaluationContext(Object result, BeanFactory beanFactory) {
AnnotatedClass target = new AnnotatedClass();
Method method = ReflectionUtils.findMethod(AnnotatedClass.class, "multipleCaching", Object.class,
Object.class);
Object[] args = new Object[] { new Object(), new Object() };
Method method = ReflectionUtils.findMethod(
AnnotatedClass.class, "multipleCaching", Object.class, Object.class);
Object[] args = new Object[] {new Object(), new Object()};
Collection<ConcurrentMapCache> caches = Collections.singleton(new ConcurrentMapCache("test"));
return this.eval.createEvaluationContext(caches, method, args, target, target.getClass(), result, beanFactory);
return this.eval.createEvaluationContext(
caches, method, args, target, target.getClass(), method, result, beanFactory);
}