|
|
|
@ -2642,14 +2642,12 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertThat(expression.getValue(context)).isEqualTo(20); |
|
|
|
assertThat(expression.getValue(context)).isEqualTo(20); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expression = parser.parseExpression("#appendChar('abc'.charAt(0),'abc'.charAt(1))"); |
|
|
|
expression = parser.parseExpression("#appendChar('abc'.charAt(0),'abc'.charAt(1))"); |
|
|
|
assertThat(expression.getValue(context)).isEqualTo("ab"); |
|
|
|
assertThat(expression.getValue(context)).isEqualTo("ab"); |
|
|
|
assertThat(((SpelExpression) expression).getAST().isCompilable()).isTrue(); |
|
|
|
assertThat(((SpelExpression) expression).getAST().isCompilable()).isTrue(); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertThat(expression.getValue(context)).isEqualTo("ab"); |
|
|
|
assertThat(expression.getValue(context)).isEqualTo("ab"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expression = parser.parseExpression("#append4('a','b','c')"); |
|
|
|
expression = parser.parseExpression("#append4('a','b','c')"); |
|
|
|
assertThat(expression.getValue(context).toString()).isEqualTo("a::bc"); |
|
|
|
assertThat(expression.getValue(context).toString()).isEqualTo("a::bc"); |
|
|
|
assertThat(((SpelExpression) expression).getAST().isCompilable()).isTrue(); |
|
|
|
assertThat(((SpelExpression) expression).getAST().isCompilable()).isTrue(); |
|
|
|
@ -3259,7 +3257,6 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
assertThat(b).isTrue(); |
|
|
|
assertThat(b).isTrue(); |
|
|
|
assertThat(aa.gotComparedTo).isEqualTo(bb); |
|
|
|
assertThat(aa.gotComparedTo).isEqualTo(bb); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> ls = new ArrayList<>(); |
|
|
|
List<String> ls = new ArrayList<>(); |
|
|
|
ls.add("foo"); |
|
|
|
ls.add("foo"); |
|
|
|
StandardEvaluationContext context = new StandardEvaluationContext(ls); |
|
|
|
StandardEvaluationContext context = new StandardEvaluationContext(ls); |
|
|
|
@ -4682,7 +4679,6 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
assertThat(expression.getValue(Boolean.class)).isNull(); |
|
|
|
assertThat(expression.getValue(Boolean.class)).isNull(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Test variants of using T(...) and static/non-static method/property/field references. |
|
|
|
* Test variants of using T(...) and static/non-static method/property/field references. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -4775,7 +4771,6 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
assertThat(expression.getValue(StaticsHelper.sh)).isEqualTo("mb"); |
|
|
|
assertThat(expression.getValue(StaticsHelper.sh)).isEqualTo("mb"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertThat(expression.getValue(StaticsHelper.sh)).isEqualTo("mb"); |
|
|
|
assertThat(expression.getValue(StaticsHelper.sh)).isEqualTo("mb"); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -4863,86 +4858,89 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { |
|
|
|
context = new StandardEvaluationContext(new Object[] {person.getAge()}); |
|
|
|
context = new StandardEvaluationContext(new Object[] {person.getAge()}); |
|
|
|
context.setVariable("it", person); |
|
|
|
context.setVariable("it", person); |
|
|
|
assertThat(ex.getValue(context, Boolean.class)).isTrue(); |
|
|
|
assertThat(ex.getValue(context, Boolean.class)).isTrue(); |
|
|
|
assertThat(ex.getValue(context, Boolean.class)).isTrue(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PersonInOtherPackage person2 = new PersonInOtherPackage(1); |
|
|
|
PersonInOtherPackage person2 = new PersonInOtherPackage(1); |
|
|
|
ex = parser.parseRaw("#it?.age.equals([0])"); |
|
|
|
ex = parser.parseRaw("#it?.age.equals([0])"); |
|
|
|
context = new StandardEvaluationContext(new Object[] {person2.getAge()}); |
|
|
|
context = new StandardEvaluationContext(new Object[] {person2.getAge()}); |
|
|
|
context.setVariable("it", person2); |
|
|
|
context.setVariable("it", person2); |
|
|
|
assertThat(ex.getValue(context, Boolean.class)).isTrue(); |
|
|
|
assertThat(ex.getValue(context, Boolean.class)).isTrue(); |
|
|
|
assertThat(ex.getValue(context, Boolean.class)).isTrue(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ex = parser.parseRaw("#it?.age.equals([0])"); |
|
|
|
ex = parser.parseRaw("#it?.age.equals([0])"); |
|
|
|
context = new StandardEvaluationContext(new Object[] {person2.getAge()}); |
|
|
|
context = new StandardEvaluationContext(new Object[] {person2.getAge()}); |
|
|
|
context.setVariable("it", person2); |
|
|
|
context.setVariable("it", person2); |
|
|
|
assertThat((Boolean) ex.getValue(context)).isTrue(); |
|
|
|
assertThat((Boolean) ex.getValue(context)).isTrue(); |
|
|
|
assertThat((Boolean) ex.getValue(context)).isTrue(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void constructorReference() { |
|
|
|
void constructorReference() { |
|
|
|
// simple ctor
|
|
|
|
// simple constructor
|
|
|
|
expression = parser.parseExpression("new String('123')"); |
|
|
|
expression = parser.parseExpression("new String('123')"); |
|
|
|
assertThat(expression.getValue()).isEqualTo("123"); |
|
|
|
assertThat(expression.getValue()).isEqualTo("123"); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertThat(expression.getValue()).isEqualTo("123"); |
|
|
|
assertThat(expression.getValue()).isEqualTo("123"); |
|
|
|
|
|
|
|
|
|
|
|
String testclass8 = "org.springframework.expression.spel.SpelCompilationCoverageTests$TestClass8"; |
|
|
|
String testclass8 = TestClass8.class.getName(); |
|
|
|
// multi arg ctor that includes primitives
|
|
|
|
Object result; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// multi arg constructor that includes primitives
|
|
|
|
expression = parser.parseExpression("new " + testclass8 + "(42,'123',4.0d,true)"); |
|
|
|
expression = parser.parseExpression("new " + testclass8 + "(42,'123',4.0d,true)"); |
|
|
|
assertThat(expression.getValue().getClass().getName()).isEqualTo(testclass8); |
|
|
|
result = expression.getValue(); |
|
|
|
|
|
|
|
assertThat(result).isExactlyInstanceOf(TestClass8.class); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
Object o = expression.getValue(); |
|
|
|
result = expression.getValue(); |
|
|
|
assertThat(o.getClass().getName()).isEqualTo(testclass8); |
|
|
|
assertThat(result).isExactlyInstanceOf(TestClass8.class); |
|
|
|
TestClass8 tc8 = (TestClass8) o; |
|
|
|
TestClass8 tc8 = (TestClass8) result; |
|
|
|
assertThat(tc8.i).isEqualTo(42); |
|
|
|
assertThat(tc8.i).isEqualTo(42); |
|
|
|
assertThat(tc8.s).isEqualTo("123"); |
|
|
|
assertThat(tc8.s).isEqualTo("123"); |
|
|
|
assertThat(tc8.d).isCloseTo(4.0d, within(0.5d)); |
|
|
|
assertThat(tc8.d).isCloseTo(4.0d, within(0.5d)); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(tc8.z).isTrue(); |
|
|
|
assertThat(tc8.z).isTrue(); |
|
|
|
|
|
|
|
|
|
|
|
// no-arg ctor
|
|
|
|
// no-arg constructor
|
|
|
|
expression = parser.parseExpression("new " + testclass8 + "()"); |
|
|
|
expression = parser.parseExpression("new " + testclass8 + "()"); |
|
|
|
assertThat(expression.getValue().getClass().getName()).isEqualTo(testclass8); |
|
|
|
result = expression.getValue(); |
|
|
|
|
|
|
|
assertThat(result).isExactlyInstanceOf(TestClass8.class); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
o = expression.getValue(); |
|
|
|
result = expression.getValue(); |
|
|
|
assertThat(o.getClass().getName()).isEqualTo(testclass8); |
|
|
|
assertThat(result).isExactlyInstanceOf(TestClass8.class); |
|
|
|
|
|
|
|
|
|
|
|
// pass primitive to reference type ctor
|
|
|
|
// pass primitive to reference type constructor
|
|
|
|
expression = parser.parseExpression("new " + testclass8 + "(42)"); |
|
|
|
expression = parser.parseExpression("new " + testclass8 + "(42)"); |
|
|
|
assertThat(expression.getValue().getClass().getName()).isEqualTo(testclass8); |
|
|
|
result = expression.getValue(); |
|
|
|
|
|
|
|
assertThat(result).isExactlyInstanceOf(TestClass8.class); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
o = expression.getValue(); |
|
|
|
result = expression.getValue(); |
|
|
|
assertThat(o.getClass().getName()).isEqualTo(testclass8); |
|
|
|
assertThat(result).isExactlyInstanceOf(TestClass8.class); |
|
|
|
tc8 = (TestClass8) o; |
|
|
|
tc8 = (TestClass8) result; |
|
|
|
assertThat(tc8.i).isEqualTo(42); |
|
|
|
assertThat(tc8.i).isEqualTo(42); |
|
|
|
|
|
|
|
|
|
|
|
// varargs
|
|
|
|
// varargs
|
|
|
|
expression = parser.parseExpression("new " + testclass8 + "(#root)"); |
|
|
|
expression = parser.parseExpression("new " + testclass8 + "(#root)"); |
|
|
|
Object[] objectArray = { "a", "b", "c" }; |
|
|
|
Object[] objectArray = { "a", "b", "c" }; |
|
|
|
o = expression.getValue(objectArray); |
|
|
|
result = expression.getValue(objectArray); |
|
|
|
assertThat(o).isExactlyInstanceOf(TestClass8.class); |
|
|
|
assertThat(result).isExactlyInstanceOf(TestClass8.class); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
o = expression.getValue(objectArray); |
|
|
|
result = expression.getValue(objectArray); |
|
|
|
assertThat(o).isExactlyInstanceOf(TestClass8.class); |
|
|
|
assertThat(result).isExactlyInstanceOf(TestClass8.class); |
|
|
|
tc8 = (TestClass8) o; |
|
|
|
tc8 = (TestClass8) result; |
|
|
|
assertThat(tc8.args).containsExactly("a", "b", "c"); |
|
|
|
assertThat(tc8.args).containsExactly("a", "b", "c"); |
|
|
|
|
|
|
|
|
|
|
|
// varargs with argument component type that is a subtype of the varargs component type.
|
|
|
|
// varargs with argument component type that is a subtype of the varargs component type.
|
|
|
|
expression = parser.parseExpression("new " + testclass8 + "(#root)"); |
|
|
|
expression = parser.parseExpression("new " + testclass8 + "(#root)"); |
|
|
|
String[] stringArray = { "a", "b", "c" }; |
|
|
|
String[] stringArray = { "a", "b", "c" }; |
|
|
|
o = expression.getValue(stringArray); |
|
|
|
result = expression.getValue(stringArray); |
|
|
|
assertThat(o).isExactlyInstanceOf(TestClass8.class); |
|
|
|
assertThat(result).isExactlyInstanceOf(TestClass8.class); |
|
|
|
assertCanCompile(expression); |
|
|
|
assertCanCompile(expression); |
|
|
|
o = expression.getValue(stringArray); |
|
|
|
result = expression.getValue(stringArray); |
|
|
|
assertThat(o).isExactlyInstanceOf(TestClass8.class); |
|
|
|
assertThat(result).isExactlyInstanceOf(TestClass8.class); |
|
|
|
tc8 = (TestClass8) o; |
|
|
|
tc8 = (TestClass8) result; |
|
|
|
assertThat(tc8.args).containsExactly("a", "b", "c"); |
|
|
|
assertThat(tc8.args).containsExactly("a", "b", "c"); |
|
|
|
|
|
|
|
|
|
|
|
// private class, can't compile it
|
|
|
|
// private class, can't compile it
|
|
|
|
String testclass9 = "org.springframework.expression.spel.SpelCompilationCoverageTests$TestClass9"; |
|
|
|
String testclass9 = TestClass9.class.getName(); |
|
|
|
expression = parser.parseExpression("new " + testclass9 + "(42)"); |
|
|
|
expression = parser.parseExpression("new " + testclass9 + "(42)"); |
|
|
|
assertThat(expression.getValue().getClass().getName()).isEqualTo(testclass9); |
|
|
|
result = expression.getValue(); |
|
|
|
|
|
|
|
assertThat(result).isExactlyInstanceOf(TestClass9.class); |
|
|
|
assertCannotCompile(expression); |
|
|
|
assertCannotCompile(expression); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|