|
16 | 16 |
|
17 | 17 | package org.springframework.expression.spel;
|
18 | 18 |
|
19 |
| -import static org.junit.Assert.*; |
| 19 | +import static org.junit.Assert.assertEquals; |
| 20 | +import static org.junit.Assert.assertSame; |
20 | 21 |
|
21 | 22 | import java.lang.annotation.Annotation;
|
22 | 23 | import java.lang.annotation.Retention;
|
|
29 | 30 | import org.junit.Test;
|
30 | 31 | import org.springframework.core.convert.TypeDescriptor;
|
31 | 32 | import org.springframework.expression.AccessException;
|
| 33 | +import org.springframework.expression.BeanResolver; |
32 | 34 | import org.springframework.expression.EvaluationContext;
|
33 | 35 | import org.springframework.expression.Expression;
|
34 | 36 | import org.springframework.expression.ExpressionInvocationTargetException;
|
|
44 | 46 | * Tests invocation of methods.
|
45 | 47 | *
|
46 | 48 | * @author Andy Clement
|
| 49 | + * @author Phillip Webb |
47 | 50 | */
|
48 | 51 | public class MethodInvocationTests extends ExpressionTestCase {
|
49 | 52 |
|
@@ -369,4 +372,30 @@ public void testMethodOfClass() throws Exception {
|
369 | 372 | Object value = expression.getValue(new StandardEvaluationContext(String.class));
|
370 | 373 | assertEquals(value, "java.lang.String");
|
371 | 374 | }
|
| 375 | + |
| 376 | + @Test |
| 377 | + public void invokeMethodWithoutConversion() throws Exception { |
| 378 | + final BytesService service = new BytesService(); |
| 379 | + byte[] bytes = new byte[100]; |
| 380 | + StandardEvaluationContext context = new StandardEvaluationContext(bytes); |
| 381 | + context.setBeanResolver(new BeanResolver() { |
| 382 | + public Object resolve(EvaluationContext context, String beanName) |
| 383 | + throws AccessException { |
| 384 | + if ("service".equals(beanName)) { |
| 385 | + return service; |
| 386 | + } |
| 387 | + return null; |
| 388 | + } |
| 389 | + }); |
| 390 | + Expression expression = parser.parseExpression("@service.handleBytes(#root)"); |
| 391 | + byte[] outBytes = expression.getValue(context, byte[].class); |
| 392 | + assertSame(bytes, outBytes); |
| 393 | + } |
| 394 | + |
| 395 | + public static class BytesService { |
| 396 | + |
| 397 | + public byte[] handleBytes(byte[] bytes) { |
| 398 | + return bytes; |
| 399 | + } |
| 400 | + } |
372 | 401 | }
|
0 commit comments