@ -29,6 +29,8 @@ import java.util.Set;
@@ -29,6 +29,8 @@ import java.util.Set;
import java.util.StringTokenizer ;
import org.junit.jupiter.api.Test ;
import org.junit.jupiter.params.ParameterizedTest ;
import org.junit.jupiter.params.provider.ValueSource ;
import org.springframework.asm.MethodVisitor ;
import org.springframework.expression.AccessException ;
@ -55,6 +57,7 @@ import static org.assertj.core.api.InstanceOfAssertFactories.BOOLEAN;
@@ -55,6 +57,7 @@ import static org.assertj.core.api.InstanceOfAssertFactories.BOOLEAN;
* Checks SpelCompiler behavior . This should cover compilation all compiled node types .
*
* @author Andy Clement
* @author Sam Brannen
* @since 4 . 1
* /
public class SpelCompilationCoverageTests extends AbstractExpressionTests {
@ -997,6 +1000,60 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
@@ -997,6 +1000,60 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
assertThat ( expression . getValue ( ctx ) . toString ( ) ) . isEqualTo ( "4.0" ) ;
}
@ParameterizedTest
@ValueSource ( strings = { "voidMethod" , "voidWrapperMethod" } )
public void voidFunctionReference ( String method ) throws Exception {
assertVoidFunctionReferenceBehavior ( method ) ;
}
private void assertVoidFunctionReferenceBehavior ( String methodName ) throws Exception {
Method method = getClass ( ) . getDeclaredMethod ( methodName , String . class ) ;
EvaluationContext ctx = new StandardEvaluationContext ( ) ;
ctx . setVariable ( "voidMethod" , method ) ;
expression = parser . parseExpression ( "#voidMethod('a')" ) ;
voidMethodInvokedWith = null ;
expression . getValue ( ctx ) ;
assertThat ( voidMethodInvokedWith ) . isEqualTo ( "a" ) ;
assertCanCompile ( expression ) ;
voidMethodInvokedWith = null ;
expression . getValue ( ctx ) ;
assertThat ( voidMethodInvokedWith ) . isEqualTo ( "a" ) ;
assertCanCompile ( expression ) ;
voidMethodInvokedWith = null ;
expression . getValue ( ctx ) ;
assertThat ( voidMethodInvokedWith ) . isEqualTo ( "a" ) ;
assertCanCompile ( expression ) ;
expression = parser . parseExpression ( "#voidMethod(#a)" ) ;
ctx . setVariable ( "a" , "foo" ) ;
voidMethodInvokedWith = null ;
expression . getValue ( ctx ) ;
assertThat ( voidMethodInvokedWith ) . isEqualTo ( "foo" ) ;
assertCanCompile ( expression ) ;
voidMethodInvokedWith = null ;
expression . getValue ( ctx ) ;
assertThat ( voidMethodInvokedWith ) . isEqualTo ( "foo" ) ;
assertCanCompile ( expression ) ;
}
private static String voidMethodInvokedWith ;
public static Void voidWrapperMethod ( String str ) {
voidMethodInvokedWith = str ;
return null ;
}
public static void voidMethod ( String str ) {
voidMethodInvokedWith = str ;
}
@Test
public void functionReferenceVisibility_SPR12359 ( ) throws Exception {
// Confirms visibility of what is being called.