Skip to content

Commit 138957b

Browse files
philwebbcbeams
authored andcommitted
Test SpEL unconditional argument conversion
Issue: SPR-9566
1 parent a27d1a2 commit 138957b

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

spring-expression/src/test/java/org/springframework/expression/spel/MethodInvocationTests.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
package org.springframework.expression.spel;
1818

19-
import static org.junit.Assert.*;
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertSame;
2021

2122
import java.lang.annotation.Annotation;
2223
import java.lang.annotation.Retention;
@@ -29,6 +30,7 @@
2930
import org.junit.Test;
3031
import org.springframework.core.convert.TypeDescriptor;
3132
import org.springframework.expression.AccessException;
33+
import org.springframework.expression.BeanResolver;
3234
import org.springframework.expression.EvaluationContext;
3335
import org.springframework.expression.Expression;
3436
import org.springframework.expression.ExpressionInvocationTargetException;
@@ -44,6 +46,7 @@
4446
* Tests invocation of methods.
4547
*
4648
* @author Andy Clement
49+
* @author Phillip Webb
4750
*/
4851
public class MethodInvocationTests extends ExpressionTestCase {
4952

@@ -369,4 +372,30 @@ public void testMethodOfClass() throws Exception {
369372
Object value = expression.getValue(new StandardEvaluationContext(String.class));
370373
assertEquals(value, "java.lang.String");
371374
}
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+
}
372401
}

0 commit comments

Comments
 (0)