|
|
|
@ -51,6 +51,7 @@ import org.springframework.expression.spel.standard.SpelExpression; |
|
|
|
import org.springframework.expression.spel.standard.SpelExpressionParser; |
|
|
|
import org.springframework.expression.spel.standard.SpelExpressionParser; |
|
|
|
import org.springframework.expression.spel.support.StandardEvaluationContext; |
|
|
|
import org.springframework.expression.spel.support.StandardEvaluationContext; |
|
|
|
import org.springframework.expression.spel.testdata.PersonInOtherPackage; |
|
|
|
import org.springframework.expression.spel.testdata.PersonInOtherPackage; |
|
|
|
|
|
|
|
import org.springframework.expression.spel.testresources.Person; |
|
|
|
|
|
|
|
|
|
|
|
import static java.util.stream.Collectors.joining; |
|
|
|
import static java.util.stream.Collectors.joining; |
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
@ -909,7 +910,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class) |
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class) |
|
|
|
.isThrownBy(expression::getValue) |
|
|
|
.isThrownBy(expression::getValue) |
|
|
|
.withMessageEndingWith("Type cannot be found 'Missing'"); |
|
|
|
.withMessageEndingWith("Type cannot be found 'Missing'"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@ -994,7 +995,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
ctx.setVariable("foo", String.class); |
|
|
|
ctx.setVariable("foo", String.class); |
|
|
|
expression = parse("3 instanceof #foo"); |
|
|
|
expression = parse("3 instanceof #foo"); |
|
|
|
assertThat(expression.getValue(ctx)).isEqualTo(false); |
|
|
|
assertThat(expression.getValue(ctx)).isEqualTo(false); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
|
|
|
|
|
|
|
|
// use of primitive as type for instanceof check - compilable
|
|
|
|
// use of primitive as type for instanceof check - compilable
|
|
|
|
// but always false
|
|
|
|
// but always false
|
|
|
|
@ -1279,13 +1280,13 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
// Can't compile this as we aren't going down the getfalse() branch in our evaluation
|
|
|
|
// Can't compile this as we aren't going down the getfalse() branch in our evaluation
|
|
|
|
expression = parser.parseExpression("gettrue() or getfalse()"); |
|
|
|
expression = parser.parseExpression("gettrue() or getfalse()"); |
|
|
|
resultI = expression.getValue(tc, boolean.class); |
|
|
|
resultI = expression.getValue(tc, boolean.class); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
|
|
|
|
|
|
|
|
expression = parser.parseExpression("getA() or getB()"); |
|
|
|
expression = parser.parseExpression("getA() or getB()"); |
|
|
|
tc.a = true; |
|
|
|
tc.a = true; |
|
|
|
tc.b = true; |
|
|
|
tc.b = true; |
|
|
|
resultI = expression.getValue(tc, boolean.class); |
|
|
|
resultI = expression.getValue(tc, boolean.class); |
|
|
|
assertCantCompile(expression); // Haven't yet been into second branch
|
|
|
|
assertCannotCompile(expression); // Haven't yet been into second branch
|
|
|
|
tc.a = false; |
|
|
|
tc.a = false; |
|
|
|
tc.b = true; |
|
|
|
tc.b = true; |
|
|
|
resultI = expression.getValue(tc, boolean.class); |
|
|
|
resultI = expression.getValue(tc, boolean.class); |
|
|
|
@ -1335,13 +1336,13 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
// Can't compile this as we aren't going down the gettrue() branch in our evaluation
|
|
|
|
// Can't compile this as we aren't going down the gettrue() branch in our evaluation
|
|
|
|
expression = parser.parseExpression("getfalse() and gettrue()"); |
|
|
|
expression = parser.parseExpression("getfalse() and gettrue()"); |
|
|
|
resultI = expression.getValue(tc, boolean.class); |
|
|
|
resultI = expression.getValue(tc, boolean.class); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
|
|
|
|
|
|
|
|
expression = parser.parseExpression("getA() and getB()"); |
|
|
|
expression = parser.parseExpression("getA() and getB()"); |
|
|
|
tc.a = false; |
|
|
|
tc.a = false; |
|
|
|
tc.b = false; |
|
|
|
tc.b = false; |
|
|
|
resultI = expression.getValue(tc, boolean.class); |
|
|
|
resultI = expression.getValue(tc, boolean.class); |
|
|
|
assertCantCompile(expression); // Haven't yet been into second branch
|
|
|
|
assertCannotCompile(expression); // Haven't yet been into second branch
|
|
|
|
tc.a = true; |
|
|
|
tc.a = true; |
|
|
|
tc.b = false; |
|
|
|
tc.b = false; |
|
|
|
resultI = expression.getValue(tc, boolean.class); |
|
|
|
resultI = expression.getValue(tc, boolean.class); |
|
|
|
@ -1409,7 +1410,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
boolean root = true; |
|
|
|
boolean root = true; |
|
|
|
expression = parser.parseExpression("(#root and true)?T(Integer).valueOf(1):T(Long).valueOf(3L)"); |
|
|
|
expression = parser.parseExpression("(#root and true)?T(Integer).valueOf(1):T(Long).valueOf(3L)"); |
|
|
|
assertThat(expression.getValue(root)).isEqualTo(1); |
|
|
|
assertThat(expression.getValue(root)).isEqualTo(1); |
|
|
|
assertCantCompile(expression); // Have not gone down false branch
|
|
|
|
assertCannotCompile(expression); // Have not gone down false branch
|
|
|
|
root = false; |
|
|
|
root = false; |
|
|
|
assertThat(expression.getValue(root)).isEqualTo(3L); |
|
|
|
assertThat(expression.getValue(root)).isEqualTo(3L); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -1636,7 +1637,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
String s = "abc"; |
|
|
|
String s = "abc"; |
|
|
|
expression = parser.parseExpression("#root?:'b'"); |
|
|
|
expression = parser.parseExpression("#root?:'b'"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
resultI = expression.getValue(s, String.class); |
|
|
|
resultI = expression.getValue(s, String.class); |
|
|
|
assertThat(resultI).isEqualTo("abc"); |
|
|
|
assertThat(resultI).isEqualTo("abc"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -1792,7 +1793,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
// type nor method are public
|
|
|
|
// type nor method are public
|
|
|
|
expression = parser.parseExpression("#doCompare([0],#arg)"); |
|
|
|
expression = parser.parseExpression("#doCompare([0],#arg)"); |
|
|
|
assertThat(expression.getValue(context, Integer.class).toString()).isEqualTo("-1"); |
|
|
|
assertThat(expression.getValue(context, Integer.class).toString()).isEqualTo("-1"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
|
|
|
|
|
|
|
|
// type not public but method is
|
|
|
|
// type not public but method is
|
|
|
|
context = new StandardEvaluationContext(new Object[] {"1"}); |
|
|
|
context = new StandardEvaluationContext(new Object[] {"1"}); |
|
|
|
@ -1801,7 +1802,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
context.setVariable("arg", "2"); |
|
|
|
context.setVariable("arg", "2"); |
|
|
|
expression = parser.parseExpression("#doCompare([0],#arg)"); |
|
|
|
expression = parser.parseExpression("#doCompare([0],#arg)"); |
|
|
|
assertThat(expression.getValue(context, Integer.class).toString()).isEqualTo("-1"); |
|
|
|
assertThat(expression.getValue(context, Integer.class).toString()).isEqualTo("-1"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -2059,7 +2060,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// Differing types of number, not yet supported
|
|
|
|
// Differing types of number, not yet supported
|
|
|
|
expression = parse("1 < 3.0d"); |
|
|
|
expression = parse("1 < 3.0d"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
|
|
|
|
|
|
|
|
expression = parse("T(Integer).valueOf(3) < 4"); |
|
|
|
expression = parse("T(Integer).valueOf(3) < 4"); |
|
|
|
assertThat((Boolean) expression.getValue()).isTrue(); |
|
|
|
assertThat((Boolean) expression.getValue()).isTrue(); |
|
|
|
@ -2118,7 +2119,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// Differing types of number, not yet supported
|
|
|
|
// Differing types of number, not yet supported
|
|
|
|
expression = parse("1 <= 3.0d"); |
|
|
|
expression = parse("1 <= 3.0d"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
|
|
|
|
|
|
|
|
expression = parse("T(Integer).valueOf(3) <= 4"); |
|
|
|
expression = parse("T(Integer).valueOf(3) <= 4"); |
|
|
|
assertThat((Boolean) expression.getValue()).isTrue(); |
|
|
|
assertThat((Boolean) expression.getValue()).isTrue(); |
|
|
|
@ -2168,7 +2169,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// Differing types of number, not yet supported
|
|
|
|
// Differing types of number, not yet supported
|
|
|
|
expression = parse("1 > 3.0d"); |
|
|
|
expression = parse("1 > 3.0d"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
|
|
|
|
|
|
|
|
expression = parse("T(Integer).valueOf(3) > 4"); |
|
|
|
expression = parse("T(Integer).valueOf(3) > 4"); |
|
|
|
assertThat((Boolean) expression.getValue()).isFalse(); |
|
|
|
assertThat((Boolean) expression.getValue()).isFalse(); |
|
|
|
@ -2230,7 +2231,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// Differing types of number, not yet supported
|
|
|
|
// Differing types of number, not yet supported
|
|
|
|
expression = parse("1 >= 3.0d"); |
|
|
|
expression = parse("1 >= 3.0d"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
|
|
|
|
|
|
|
|
expression = parse("T(Integer).valueOf(3) >= 4"); |
|
|
|
expression = parse("T(Integer).valueOf(3) >= 4"); |
|
|
|
assertThat((Boolean) expression.getValue()).isFalse(); |
|
|
|
assertThat((Boolean) expression.getValue()).isFalse(); |
|
|
|
@ -2310,7 +2311,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// number types are not the same
|
|
|
|
// number types are not the same
|
|
|
|
expression = parse("1 == 3.0d"); |
|
|
|
expression = parse("1 == 3.0d"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
|
|
|
|
|
|
|
|
Double d = 3.0d; |
|
|
|
Double d = 3.0d; |
|
|
|
expression = parse("#root==3.0d"); |
|
|
|
expression = parse("#root==3.0d"); |
|
|
|
@ -2455,7 +2456,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// not compatible number types
|
|
|
|
// not compatible number types
|
|
|
|
expression = parse("1 != 3.0d"); |
|
|
|
expression = parse("1 != 3.0d"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
|
|
|
|
|
|
|
|
expression = parse("T(Integer).valueOf(3) != 4"); |
|
|
|
expression = parse("T(Integer).valueOf(3) != 4"); |
|
|
|
assertThat((Boolean) expression.getValue()).isTrue(); |
|
|
|
assertThat((Boolean) expression.getValue()).isTrue(); |
|
|
|
@ -3127,7 +3128,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
// Three strings, optimal bytecode would only use one StringBuilder
|
|
|
|
// Three strings, optimal bytecode would only use one StringBuilder
|
|
|
|
expression = parse("'hello' + 3 + ' spring'"); |
|
|
|
expression = parse("'hello' + 3 + ' spring'"); |
|
|
|
assertThat(expression.getValue(new Greeter())).isEqualTo("hello3 spring"); |
|
|
|
assertThat(expression.getValue(new Greeter())).isEqualTo("hello3 spring"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
|
|
|
|
|
|
|
|
expression = parse("object + 'a'"); |
|
|
|
expression = parse("object + 'a'"); |
|
|
|
assertThat(expression.getValue(new Greeter())).isEqualTo("objecta"); |
|
|
|
assertThat(expression.getValue(new Greeter())).isEqualTo("objecta"); |
|
|
|
@ -4262,7 +4263,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
String testclass9 = "org.springframework.expression.spel.SpelCompilationCoverageTests$TestClass9"; |
|
|
|
String testclass9 = "org.springframework.expression.spel.SpelCompilationCoverageTests$TestClass9"; |
|
|
|
expression = parser.parseExpression("new " + testclass9 + "(42)"); |
|
|
|
expression = parser.parseExpression("new " + testclass9 + "(42)"); |
|
|
|
assertThat(expression.getValue().getClass().getName()).isEqualTo(testclass9); |
|
|
|
assertThat(expression.getValue().getClass().getName()).isEqualTo(testclass9); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -4272,7 +4273,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
// Should call the non varargs version of concat
|
|
|
|
// Should call the non varargs version of concat
|
|
|
|
// (which causes the '::' prefix in test output)
|
|
|
|
// (which causes the '::' prefix in test output)
|
|
|
|
expression = parser.parseExpression("concat('test')"); |
|
|
|
expression = parser.parseExpression("concat('test')"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("::test"); |
|
|
|
assertThat(tc.s).isEqualTo("::test"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4283,7 +4284,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// This will call the varargs concat with an empty array
|
|
|
|
// This will call the varargs concat with an empty array
|
|
|
|
expression = parser.parseExpression("concat()"); |
|
|
|
expression = parser.parseExpression("concat()"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEmpty(); |
|
|
|
assertThat(tc.s).isEmpty(); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4295,7 +4296,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
// Should call the non varargs version of concat
|
|
|
|
// Should call the non varargs version of concat
|
|
|
|
// (which causes the '::' prefix in test output)
|
|
|
|
// (which causes the '::' prefix in test output)
|
|
|
|
expression = parser.parseExpression("concat2('test')"); |
|
|
|
expression = parser.parseExpression("concat2('test')"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("::test"); |
|
|
|
assertThat(tc.s).isEqualTo("::test"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4306,7 +4307,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// This will call the varargs concat with an empty array
|
|
|
|
// This will call the varargs concat with an empty array
|
|
|
|
expression = parser.parseExpression("concat2()"); |
|
|
|
expression = parser.parseExpression("concat2()"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEmpty(); |
|
|
|
assertThat(tc.s).isEmpty(); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4322,7 +4323,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// varargs string
|
|
|
|
// varargs string
|
|
|
|
expression = parser.parseExpression("eleven()"); |
|
|
|
expression = parser.parseExpression("eleven()"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEmpty(); |
|
|
|
assertThat(tc.s).isEmpty(); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4333,7 +4334,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// varargs string
|
|
|
|
// varargs string
|
|
|
|
expression = parser.parseExpression("eleven('aaa')"); |
|
|
|
expression = parser.parseExpression("eleven('aaa')"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("aaa"); |
|
|
|
assertThat(tc.s).isEqualTo("aaa"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4344,7 +4345,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// varargs string
|
|
|
|
// varargs string
|
|
|
|
expression = parser.parseExpression("eleven(stringArray)"); |
|
|
|
expression = parser.parseExpression("eleven(stringArray)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("aaabbbccc"); |
|
|
|
assertThat(tc.s).isEqualTo("aaabbbccc"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4355,7 +4356,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// varargs string
|
|
|
|
// varargs string
|
|
|
|
expression = parser.parseExpression("eleven('aaa','bbb','ccc')"); |
|
|
|
expression = parser.parseExpression("eleven('aaa','bbb','ccc')"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("aaabbbccc"); |
|
|
|
assertThat(tc.s).isEqualTo("aaabbbccc"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4365,7 +4366,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
tc.reset(); |
|
|
|
tc.reset(); |
|
|
|
|
|
|
|
|
|
|
|
expression = parser.parseExpression("sixteen('aaa','bbb','ccc')"); |
|
|
|
expression = parser.parseExpression("sixteen('aaa','bbb','ccc')"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("aaabbbccc"); |
|
|
|
assertThat(tc.s).isEqualTo("aaabbbccc"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4387,7 +4388,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// varargs int
|
|
|
|
// varargs int
|
|
|
|
expression = parser.parseExpression("twelve(1,2,3)"); |
|
|
|
expression = parser.parseExpression("twelve(1,2,3)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.i).isEqualTo(6); |
|
|
|
assertThat(tc.i).isEqualTo(6); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4397,7 +4398,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
tc.reset(); |
|
|
|
tc.reset(); |
|
|
|
|
|
|
|
|
|
|
|
expression = parser.parseExpression("twelve(1)"); |
|
|
|
expression = parser.parseExpression("twelve(1)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.i).isEqualTo(1); |
|
|
|
assertThat(tc.i).isEqualTo(1); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4408,7 +4409,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// one string then varargs string
|
|
|
|
// one string then varargs string
|
|
|
|
expression = parser.parseExpression("thirteen('aaa','bbb','ccc')"); |
|
|
|
expression = parser.parseExpression("thirteen('aaa','bbb','ccc')"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("aaa::bbbccc"); |
|
|
|
assertThat(tc.s).isEqualTo("aaa::bbbccc"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4419,7 +4420,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// nothing passed to varargs parameter
|
|
|
|
// nothing passed to varargs parameter
|
|
|
|
expression = parser.parseExpression("thirteen('aaa')"); |
|
|
|
expression = parser.parseExpression("thirteen('aaa')"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("aaa::"); |
|
|
|
assertThat(tc.s).isEqualTo("aaa::"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4430,7 +4431,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// nested arrays
|
|
|
|
// nested arrays
|
|
|
|
expression = parser.parseExpression("fourteen('aaa',stringArray,stringArray)"); |
|
|
|
expression = parser.parseExpression("fourteen('aaa',stringArray,stringArray)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("aaa::{aaabbbccc}{aaabbbccc}"); |
|
|
|
assertThat(tc.s).isEqualTo("aaa::{aaabbbccc}{aaabbbccc}"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4441,7 +4442,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// nested primitive array
|
|
|
|
// nested primitive array
|
|
|
|
expression = parser.parseExpression("fifteen('aaa',intArray,intArray)"); |
|
|
|
expression = parser.parseExpression("fifteen('aaa',intArray,intArray)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("aaa::{112233}{112233}"); |
|
|
|
assertThat(tc.s).isEqualTo("aaa::{112233}{112233}"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4452,7 +4453,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// varargs boolean
|
|
|
|
// varargs boolean
|
|
|
|
expression = parser.parseExpression("arrayz(true,true,false)"); |
|
|
|
expression = parser.parseExpression("arrayz(true,true,false)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("truetruefalse"); |
|
|
|
assertThat(tc.s).isEqualTo("truetruefalse"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4462,7 +4463,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
tc.reset(); |
|
|
|
tc.reset(); |
|
|
|
|
|
|
|
|
|
|
|
expression = parser.parseExpression("arrayz(true)"); |
|
|
|
expression = parser.parseExpression("arrayz(true)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("true"); |
|
|
|
assertThat(tc.s).isEqualTo("true"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4473,7 +4474,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// varargs short
|
|
|
|
// varargs short
|
|
|
|
expression = parser.parseExpression("arrays(s1,s2,s3)"); |
|
|
|
expression = parser.parseExpression("arrays(s1,s2,s3)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("123"); |
|
|
|
assertThat(tc.s).isEqualTo("123"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4483,7 +4484,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
tc.reset(); |
|
|
|
tc.reset(); |
|
|
|
|
|
|
|
|
|
|
|
expression = parser.parseExpression("arrays(s1)"); |
|
|
|
expression = parser.parseExpression("arrays(s1)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("1"); |
|
|
|
assertThat(tc.s).isEqualTo("1"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4494,7 +4495,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// varargs double
|
|
|
|
// varargs double
|
|
|
|
expression = parser.parseExpression("arrayd(1.0d,2.0d,3.0d)"); |
|
|
|
expression = parser.parseExpression("arrayd(1.0d,2.0d,3.0d)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("1.02.03.0"); |
|
|
|
assertThat(tc.s).isEqualTo("1.02.03.0"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4504,7 +4505,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
tc.reset(); |
|
|
|
tc.reset(); |
|
|
|
|
|
|
|
|
|
|
|
expression = parser.parseExpression("arrayd(1.0d)"); |
|
|
|
expression = parser.parseExpression("arrayd(1.0d)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("1.0"); |
|
|
|
assertThat(tc.s).isEqualTo("1.0"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4515,7 +4516,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// varargs long
|
|
|
|
// varargs long
|
|
|
|
expression = parser.parseExpression("arrayj(l1,l2,l3)"); |
|
|
|
expression = parser.parseExpression("arrayj(l1,l2,l3)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("123"); |
|
|
|
assertThat(tc.s).isEqualTo("123"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4525,7 +4526,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
tc.reset(); |
|
|
|
tc.reset(); |
|
|
|
|
|
|
|
|
|
|
|
expression = parser.parseExpression("arrayj(l1)"); |
|
|
|
expression = parser.parseExpression("arrayj(l1)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("1"); |
|
|
|
assertThat(tc.s).isEqualTo("1"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4536,7 +4537,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// varargs char
|
|
|
|
// varargs char
|
|
|
|
expression = parser.parseExpression("arrayc(c1,c2,c3)"); |
|
|
|
expression = parser.parseExpression("arrayc(c1,c2,c3)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("abc"); |
|
|
|
assertThat(tc.s).isEqualTo("abc"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4546,7 +4547,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
tc.reset(); |
|
|
|
tc.reset(); |
|
|
|
|
|
|
|
|
|
|
|
expression = parser.parseExpression("arrayc(c1)"); |
|
|
|
expression = parser.parseExpression("arrayc(c1)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("a"); |
|
|
|
assertThat(tc.s).isEqualTo("a"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4557,7 +4558,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// varargs byte
|
|
|
|
// varargs byte
|
|
|
|
expression = parser.parseExpression("arrayb(b1,b2,b3)"); |
|
|
|
expression = parser.parseExpression("arrayb(b1,b2,b3)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("656667"); |
|
|
|
assertThat(tc.s).isEqualTo("656667"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4567,7 +4568,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
tc.reset(); |
|
|
|
tc.reset(); |
|
|
|
|
|
|
|
|
|
|
|
expression = parser.parseExpression("arrayb(b1)"); |
|
|
|
expression = parser.parseExpression("arrayb(b1)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("65"); |
|
|
|
assertThat(tc.s).isEqualTo("65"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4578,7 +4579,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// varargs float
|
|
|
|
// varargs float
|
|
|
|
expression = parser.parseExpression("arrayf(f1,f2,f3)"); |
|
|
|
expression = parser.parseExpression("arrayf(f1,f2,f3)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("1.02.03.0"); |
|
|
|
assertThat(tc.s).isEqualTo("1.02.03.0"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4588,7 +4589,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
tc.reset(); |
|
|
|
tc.reset(); |
|
|
|
|
|
|
|
|
|
|
|
expression = parser.parseExpression("arrayf(f1)"); |
|
|
|
expression = parser.parseExpression("arrayf(f1)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("1.0"); |
|
|
|
assertThat(tc.s).isEqualTo("1.0"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4603,7 +4604,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
// non-static method, no args, void return
|
|
|
|
// non-static method, no args, void return
|
|
|
|
expression = parser.parseExpression("new %s()?.one()".formatted(TestClass5.class.getName())); |
|
|
|
expression = parser.parseExpression("new %s()?.one()".formatted(TestClass5.class.getName())); |
|
|
|
|
|
|
|
|
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
|
|
|
|
|
|
|
|
TestClass5._i = 0; |
|
|
|
TestClass5._i = 0; |
|
|
|
assertThat(expression.getValue()).isNull(); |
|
|
|
assertThat(expression.getValue()).isNull(); |
|
|
|
@ -4620,7 +4621,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
// static method, no args, void return
|
|
|
|
// static method, no args, void return
|
|
|
|
expression = parser.parseExpression("T(%s)?.two()".formatted(TestClass5.class.getName())); |
|
|
|
expression = parser.parseExpression("T(%s)?.two()".formatted(TestClass5.class.getName())); |
|
|
|
|
|
|
|
|
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
|
|
|
|
|
|
|
|
TestClass5._i = 0; |
|
|
|
TestClass5._i = 0; |
|
|
|
assertThat(expression.getValue()).isNull(); |
|
|
|
assertThat(expression.getValue()).isNull(); |
|
|
|
@ -4637,7 +4638,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
// non-static method, no args, Void return
|
|
|
|
// non-static method, no args, Void return
|
|
|
|
expression = parser.parseExpression("new %s()?.oneVoidWrapper()".formatted(TestClass5.class.getName())); |
|
|
|
expression = parser.parseExpression("new %s()?.oneVoidWrapper()".formatted(TestClass5.class.getName())); |
|
|
|
|
|
|
|
|
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
|
|
|
|
|
|
|
|
TestClass5._i = 0; |
|
|
|
TestClass5._i = 0; |
|
|
|
assertThat(expression.getValue()).isNull(); |
|
|
|
assertThat(expression.getValue()).isNull(); |
|
|
|
@ -4654,7 +4655,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
// static method, no args, Void return
|
|
|
|
// static method, no args, Void return
|
|
|
|
expression = parser.parseExpression("T(%s)?.twoVoidWrapper()".formatted(TestClass5.class.getName())); |
|
|
|
expression = parser.parseExpression("T(%s)?.twoVoidWrapper()".formatted(TestClass5.class.getName())); |
|
|
|
|
|
|
|
|
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
|
|
|
|
|
|
|
|
TestClass5._i = 0; |
|
|
|
TestClass5._i = 0; |
|
|
|
assertThat(expression.getValue()).isNull(); |
|
|
|
assertThat(expression.getValue()).isNull(); |
|
|
|
@ -4672,7 +4673,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// non-static method, no args, void return
|
|
|
|
// non-static method, no args, void return
|
|
|
|
expression = parser.parseExpression("one()"); |
|
|
|
expression = parser.parseExpression("one()"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
tc.reset(); |
|
|
|
tc.reset(); |
|
|
|
@ -4682,7 +4683,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// static method, no args, void return
|
|
|
|
// static method, no args, void return
|
|
|
|
expression = parser.parseExpression("two()"); |
|
|
|
expression = parser.parseExpression("two()"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
tc.reset(); |
|
|
|
tc.reset(); |
|
|
|
@ -4692,7 +4693,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// non-static method, reference type return
|
|
|
|
// non-static method, reference type return
|
|
|
|
expression = parser.parseExpression("three()"); |
|
|
|
expression = parser.parseExpression("three()"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
tc.reset(); |
|
|
|
tc.reset(); |
|
|
|
@ -4701,7 +4702,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// non-static method, primitive type return
|
|
|
|
// non-static method, primitive type return
|
|
|
|
expression = parser.parseExpression("four()"); |
|
|
|
expression = parser.parseExpression("four()"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
tc.reset(); |
|
|
|
tc.reset(); |
|
|
|
@ -4710,7 +4711,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// static method, reference type return
|
|
|
|
// static method, reference type return
|
|
|
|
expression = parser.parseExpression("five()"); |
|
|
|
expression = parser.parseExpression("five()"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
tc.reset(); |
|
|
|
tc.reset(); |
|
|
|
@ -4719,7 +4720,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// static method, primitive type return
|
|
|
|
// static method, primitive type return
|
|
|
|
expression = parser.parseExpression("six()"); |
|
|
|
expression = parser.parseExpression("six()"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
tc.reset(); |
|
|
|
tc.reset(); |
|
|
|
@ -4728,7 +4729,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// non-static method, one parameter of reference type
|
|
|
|
// non-static method, one parameter of reference type
|
|
|
|
expression = parser.parseExpression("seven(\"foo\")"); |
|
|
|
expression = parser.parseExpression("seven(\"foo\")"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
tc.reset(); |
|
|
|
tc.reset(); |
|
|
|
@ -4738,7 +4739,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// static method, one parameter of reference type
|
|
|
|
// static method, one parameter of reference type
|
|
|
|
expression = parser.parseExpression("eight(\"bar\")"); |
|
|
|
expression = parser.parseExpression("eight(\"bar\")"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
tc.reset(); |
|
|
|
tc.reset(); |
|
|
|
@ -4748,7 +4749,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// non-static method, one parameter of primitive type
|
|
|
|
// non-static method, one parameter of primitive type
|
|
|
|
expression = parser.parseExpression("nine(231)"); |
|
|
|
expression = parser.parseExpression("nine(231)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
tc.reset(); |
|
|
|
tc.reset(); |
|
|
|
@ -4758,7 +4759,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// static method, one parameter of primitive type
|
|
|
|
// static method, one parameter of primitive type
|
|
|
|
expression = parser.parseExpression("ten(111)"); |
|
|
|
expression = parser.parseExpression("ten(111)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
tc.reset(); |
|
|
|
tc.reset(); |
|
|
|
@ -4770,10 +4771,10 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// Converting from an int to a string
|
|
|
|
// Converting from an int to a string
|
|
|
|
expression = parser.parseExpression("seven(123)"); |
|
|
|
expression = parser.parseExpression("seven(123)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("123"); |
|
|
|
assertThat(tc.s).isEqualTo("123"); |
|
|
|
assertCantCompile(expression); // Uncompilable as argument conversion is occurring
|
|
|
|
assertCannotCompile(expression); // Uncompilable as argument conversion is occurring
|
|
|
|
|
|
|
|
|
|
|
|
Expression expression = parser.parseExpression("'abcd'.substring(index1,index2)"); |
|
|
|
Expression expression = parser.parseExpression("'abcd'.substring(index1,index2)"); |
|
|
|
String resultI = expression.getValue(new TestClass1(), String.class); |
|
|
|
String resultI = expression.getValue(new TestClass1(), String.class); |
|
|
|
@ -4784,7 +4785,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// Converting from an int to a Number
|
|
|
|
// Converting from an int to a Number
|
|
|
|
expression = parser.parseExpression("takeNumber(123)"); |
|
|
|
expression = parser.parseExpression("takeNumber(123)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("123"); |
|
|
|
assertThat(tc.s).isEqualTo("123"); |
|
|
|
tc.reset(); |
|
|
|
tc.reset(); |
|
|
|
@ -4794,7 +4795,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// Passing a subtype
|
|
|
|
// Passing a subtype
|
|
|
|
expression = parser.parseExpression("takeNumber(T(Integer).valueOf(42))"); |
|
|
|
expression = parser.parseExpression("takeNumber(T(Integer).valueOf(42))"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("42"); |
|
|
|
assertThat(tc.s).isEqualTo("42"); |
|
|
|
tc.reset(); |
|
|
|
tc.reset(); |
|
|
|
@ -4804,11 +4805,11 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// Passing a subtype
|
|
|
|
// Passing a subtype
|
|
|
|
expression = parser.parseExpression("takeString(T(Integer).valueOf(42))"); |
|
|
|
expression = parser.parseExpression("takeString(T(Integer).valueOf(42))"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("42"); |
|
|
|
assertThat(tc.s).isEqualTo("42"); |
|
|
|
tc.reset(); |
|
|
|
tc.reset(); |
|
|
|
assertCantCompile(expression); // method takes a string and we are passing an Integer
|
|
|
|
assertCannotCompile(expression); // method takes a string and we are passing an Integer
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -4835,7 +4836,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
tc.field = "foo"; |
|
|
|
tc.field = "foo"; |
|
|
|
expression = parser.parseExpression("seven(field)"); |
|
|
|
expression = parser.parseExpression("seven(field)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("foo"); |
|
|
|
assertThat(tc.s).isEqualTo("foo"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4846,7 +4847,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
// method with changing parameter types (change reference type)
|
|
|
|
// method with changing parameter types (change reference type)
|
|
|
|
tc.obj = "foo"; |
|
|
|
tc.obj = "foo"; |
|
|
|
expression = parser.parseExpression("seven(obj)"); |
|
|
|
expression = parser.parseExpression("seven(obj)"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
expression.getValue(tc); |
|
|
|
expression.getValue(tc); |
|
|
|
assertThat(tc.s).isEqualTo("foo"); |
|
|
|
assertThat(tc.s).isEqualTo("foo"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
@ -4982,35 +4983,35 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
|
|
|
|
|
|
|
|
// non-static field
|
|
|
|
// non-static field
|
|
|
|
expression = parser.parseExpression("orange"); |
|
|
|
expression = parser.parseExpression("orange"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
assertThat(expression.getValue(tc)).isEqualTo("value1"); |
|
|
|
assertThat(expression.getValue(tc)).isEqualTo("value1"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertThat(expression.getValue(tc)).isEqualTo("value1"); |
|
|
|
assertThat(expression.getValue(tc)).isEqualTo("value1"); |
|
|
|
|
|
|
|
|
|
|
|
// static field
|
|
|
|
// static field
|
|
|
|
expression = parser.parseExpression("apple"); |
|
|
|
expression = parser.parseExpression("apple"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
assertThat(expression.getValue(tc)).isEqualTo("value2"); |
|
|
|
assertThat(expression.getValue(tc)).isEqualTo("value2"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertThat(expression.getValue(tc)).isEqualTo("value2"); |
|
|
|
assertThat(expression.getValue(tc)).isEqualTo("value2"); |
|
|
|
|
|
|
|
|
|
|
|
// non static getter
|
|
|
|
// non static getter
|
|
|
|
expression = parser.parseExpression("banana"); |
|
|
|
expression = parser.parseExpression("banana"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
assertThat(expression.getValue(tc)).isEqualTo("value3"); |
|
|
|
assertThat(expression.getValue(tc)).isEqualTo("value3"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertThat(expression.getValue(tc)).isEqualTo("value3"); |
|
|
|
assertThat(expression.getValue(tc)).isEqualTo("value3"); |
|
|
|
|
|
|
|
|
|
|
|
// static getter
|
|
|
|
// static getter
|
|
|
|
expression = parser.parseExpression("plum"); |
|
|
|
expression = parser.parseExpression("plum"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
assertThat(expression.getValue(tc)).isEqualTo("value4"); |
|
|
|
assertThat(expression.getValue(tc)).isEqualTo("value4"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertThat(expression.getValue(tc)).isEqualTo("value4"); |
|
|
|
assertThat(expression.getValue(tc)).isEqualTo("value4"); |
|
|
|
|
|
|
|
|
|
|
|
// record-style accessor
|
|
|
|
// record-style accessor
|
|
|
|
expression = parser.parseExpression("strawberry"); |
|
|
|
expression = parser.parseExpression("strawberry"); |
|
|
|
assertCantCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
assertThat(expression.getValue(tc)).isEqualTo("value5"); |
|
|
|
assertThat(expression.getValue(tc)).isEqualTo("value5"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertThat(expression.getValue(tc)).isEqualTo("value5"); |
|
|
|
assertThat(expression.getValue(tc)).isEqualTo("value5"); |
|
|
|
@ -5631,7 +5632,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
.isTrue(); |
|
|
|
.isTrue(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void assertCantCompile(Expression expression) { |
|
|
|
private void assertCannotCompile(Expression expression) { |
|
|
|
assertThat(SpelCompiler.compile(expression)) |
|
|
|
assertThat(SpelCompiler.compile(expression)) |
|
|
|
.as(() -> "Expression <%s> should not be compilable" |
|
|
|
.as(() -> "Expression <%s> should not be compilable" |
|
|
|
.formatted(((SpelExpression) expression).toStringAST())) |
|
|
|
.formatted(((SpelExpression) expression).toStringAST())) |
|
|
|
@ -5860,25 +5861,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class Person { |
|
|
|
public static class Person3 { |
|
|
|
|
|
|
|
|
|
|
|
private int age; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Person(int age) { |
|
|
|
|
|
|
|
this.age = age; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int getAge() { |
|
|
|
|
|
|
|
return age; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setAge(int age) { |
|
|
|
|
|
|
|
this.age = age; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class Person3 { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int age; |
|
|
|
private int age; |
|
|
|
|
|
|
|
|
|
|
|
|