|
29 | 29 | import java.util.StringTokenizer;
|
30 | 30 |
|
31 | 31 | import org.junit.jupiter.api.Test;
|
| 32 | +import org.junit.jupiter.params.ParameterizedTest; |
| 33 | +import org.junit.jupiter.params.provider.ValueSource; |
32 | 34 |
|
33 | 35 | import org.springframework.asm.MethodVisitor;
|
34 | 36 | import org.springframework.expression.AccessException;
|
|
55 | 57 | * Checks SpelCompiler behavior. This should cover compilation all compiled node types.
|
56 | 58 | *
|
57 | 59 | * @author Andy Clement
|
| 60 | + * @author Sam Brannen |
58 | 61 | * @since 4.1
|
59 | 62 | */
|
60 | 63 | public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
@@ -997,6 +1000,60 @@ public void functionReference() throws Exception {
|
997 | 1000 | assertThat(expression.getValue(ctx).toString()).isEqualTo("4.0");
|
998 | 1001 | }
|
999 | 1002 |
|
| 1003 | + @ParameterizedTest |
| 1004 | + @ValueSource(strings = {"voidMethod", "voidWrapperMethod"}) |
| 1005 | + public void voidFunctionReference(String method) throws Exception { |
| 1006 | + assertVoidFunctionReferenceBehavior(method); |
| 1007 | + } |
| 1008 | + |
| 1009 | + private void assertVoidFunctionReferenceBehavior(String methodName) throws Exception { |
| 1010 | + Method method = getClass().getDeclaredMethod(methodName, String.class); |
| 1011 | + |
| 1012 | + EvaluationContext ctx = new StandardEvaluationContext(); |
| 1013 | + ctx.setVariable("voidMethod", method); |
| 1014 | + |
| 1015 | + expression = parser.parseExpression("#voidMethod('a')"); |
| 1016 | + |
| 1017 | + voidMethodInvokedWith = null; |
| 1018 | + expression.getValue(ctx); |
| 1019 | + assertThat(voidMethodInvokedWith).isEqualTo("a"); |
| 1020 | + assertCanCompile(expression); |
| 1021 | + |
| 1022 | + voidMethodInvokedWith = null; |
| 1023 | + expression.getValue(ctx); |
| 1024 | + assertThat(voidMethodInvokedWith).isEqualTo("a"); |
| 1025 | + assertCanCompile(expression); |
| 1026 | + |
| 1027 | + voidMethodInvokedWith = null; |
| 1028 | + expression.getValue(ctx); |
| 1029 | + assertThat(voidMethodInvokedWith).isEqualTo("a"); |
| 1030 | + assertCanCompile(expression); |
| 1031 | + |
| 1032 | + expression = parser.parseExpression("#voidMethod(#a)"); |
| 1033 | + ctx.setVariable("a", "foo"); |
| 1034 | + |
| 1035 | + voidMethodInvokedWith = null; |
| 1036 | + expression.getValue(ctx); |
| 1037 | + assertThat(voidMethodInvokedWith).isEqualTo("foo"); |
| 1038 | + assertCanCompile(expression); |
| 1039 | + |
| 1040 | + voidMethodInvokedWith = null; |
| 1041 | + expression.getValue(ctx); |
| 1042 | + assertThat(voidMethodInvokedWith).isEqualTo("foo"); |
| 1043 | + assertCanCompile(expression); |
| 1044 | + } |
| 1045 | + |
| 1046 | + private static String voidMethodInvokedWith; |
| 1047 | + |
| 1048 | + public static Void voidWrapperMethod(String str) { |
| 1049 | + voidMethodInvokedWith = str; |
| 1050 | + return null; |
| 1051 | + } |
| 1052 | + |
| 1053 | + public static void voidMethod(String str) { |
| 1054 | + voidMethodInvokedWith = str; |
| 1055 | + } |
| 1056 | + |
1000 | 1057 | @Test
|
1001 | 1058 | public void functionReferenceVisibility_SPR12359() throws Exception {
|
1002 | 1059 | // Confirms visibility of what is being called.
|
|
0 commit comments