Polishing
Issue: SPR-14863
This commit is contained in:
@@ -252,7 +252,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
assertEquals(false, expression.getValue());
|
||||
assertCanCompile(expression);
|
||||
assertEquals(false, expression.getValue());
|
||||
|
||||
|
||||
// double slot left operand - should get boxed, return false
|
||||
expression = parse("3.0d instanceof T(Integer)");
|
||||
assertEquals(false, expression.getValue());
|
||||
@@ -264,7 +264,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
assertEquals(true, expression.getValue());
|
||||
assertCanCompile(expression);
|
||||
assertEquals(true, expression.getValue());
|
||||
|
||||
|
||||
// Only when the right hand operand is a direct type reference
|
||||
// will it be compilable.
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext();
|
||||
@@ -279,7 +279,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
assertEquals(false, expression.getValue());
|
||||
assertCanCompile(expression);
|
||||
assertEquals(false, expression.getValue());
|
||||
|
||||
|
||||
expression = parse("3 instanceof T(long)");
|
||||
assertEquals(false, expression.getValue());
|
||||
assertCanCompile(expression);
|
||||
@@ -1624,120 +1624,78 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
|
||||
@Test
|
||||
public void opNe_SPR14863() throws Exception {
|
||||
// First part is from the test case specified in the bug report
|
||||
SpelParserConfiguration configuration =
|
||||
new SpelParserConfiguration(SpelCompilerMode.MIXED, ClassLoader.getSystemClassLoader());
|
||||
SpelExpressionParser parser = new SpelExpressionParser(configuration);
|
||||
Expression expression = parser.parseExpression("data['my-key'] != 'my-value'");
|
||||
|
||||
Map<String, String> data = new HashMap<>();
|
||||
data.put("my-key", new String("my-value"));
|
||||
StandardEvaluationContext context = new StandardEvaluationContext(new MyContext(data));
|
||||
SpelParserConfiguration configuration = new SpelParserConfiguration(SpelCompilerMode.MIXED,
|
||||
ClassLoader.getSystemClassLoader());
|
||||
SpelExpressionParser parser = new SpelExpressionParser(configuration);
|
||||
Expression expression = parser.parseExpression("data['my-key'] != 'my-value'");
|
||||
assertFalse(expression.getValue(context, Boolean.class));
|
||||
assertCanCompile(expression);
|
||||
((SpelExpression) expression).compileExpression();
|
||||
assertFalse(expression.getValue(context, Boolean.class));
|
||||
data.put("my-key", new String("my-value"));
|
||||
StandardEvaluationContext context = new StandardEvaluationContext(new MyContext(data));
|
||||
assertFalse(expression.getValue(context, Boolean.class));
|
||||
assertCanCompile(expression);
|
||||
((SpelExpression) expression).compileExpression();
|
||||
assertFalse(expression.getValue(context, Boolean.class));
|
||||
|
||||
List<String> ls = new ArrayList<String>();
|
||||
ls.add(new String("foo"));
|
||||
context = new StandardEvaluationContext(ls);
|
||||
expression = parse("get(0) != 'foo'");
|
||||
assertFalse(expression.getValue(context, Boolean.class));
|
||||
assertCanCompile(expression);
|
||||
assertFalse(expression.getValue(context, Boolean.class));
|
||||
|
||||
ls.remove(0);
|
||||
ls.add("goo");
|
||||
assertTrue(expression.getValue(context, Boolean.class));
|
||||
List<String> ls = new ArrayList<String>();
|
||||
ls.add(new String("foo"));
|
||||
context = new StandardEvaluationContext(ls);
|
||||
expression = parse("get(0) != 'foo'");
|
||||
assertFalse(expression.getValue(context, Boolean.class));
|
||||
assertCanCompile(expression);
|
||||
assertFalse(expression.getValue(context, Boolean.class));
|
||||
|
||||
ls.remove(0);
|
||||
ls.add("goo");
|
||||
assertTrue(expression.getValue(context, Boolean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void opEq_SPR14863() throws Exception {
|
||||
// Exercise the comparator invocation code that runs in
|
||||
// equalityCheck() (called from interpreted and compiled code)
|
||||
expression = parser.parseExpression("#aa==#bb");
|
||||
StandardEvaluationContext sec = new StandardEvaluationContext();
|
||||
Apple aa = new Apple(1);
|
||||
Apple bb = new Apple(2);
|
||||
sec.setVariable("aa",aa);
|
||||
sec.setVariable("bb",bb);
|
||||
boolean b = expression.getValue(sec, Boolean.class);
|
||||
// Verify what the expression caused aa to be compared to
|
||||
assertEquals(bb,aa.gotComparedTo);
|
||||
assertFalse(b);
|
||||
bb.setValue(1);
|
||||
b = expression.getValue(sec, Boolean.class);
|
||||
assertEquals(bb,aa.gotComparedTo);
|
||||
assertTrue(b);
|
||||
|
||||
assertCanCompile(expression);
|
||||
|
||||
// Similar test with compiled expression
|
||||
aa = new Apple(99);
|
||||
bb = new Apple(100);
|
||||
sec.setVariable("aa",aa);
|
||||
sec.setVariable("bb",bb);
|
||||
b = expression.getValue(sec, Boolean.class);
|
||||
assertFalse(b);
|
||||
assertEquals(bb,aa.gotComparedTo);
|
||||
bb.setValue(99);
|
||||
b = expression.getValue(sec, Boolean.class);
|
||||
assertTrue(b);
|
||||
assertEquals(bb,aa.gotComparedTo);
|
||||
|
||||
|
||||
List<String> ls = new ArrayList<String>();
|
||||
ls.add(new String("foo"));
|
||||
StandardEvaluationContext context = new StandardEvaluationContext(ls);
|
||||
expression = parse("get(0) == 'foo'");
|
||||
assertTrue(expression.getValue(context, Boolean.class));
|
||||
assertCanCompile(expression);
|
||||
assertTrue(expression.getValue(context, Boolean.class));
|
||||
|
||||
ls.remove(0);
|
||||
ls.add("goo");
|
||||
assertFalse(expression.getValue(context, Boolean.class));
|
||||
}
|
||||
|
||||
public static class Apple implements Comparable<Apple> {
|
||||
public Object gotComparedTo = null;
|
||||
public int i;
|
||||
@Test
|
||||
public void opEq_SPR14863() throws Exception {
|
||||
// Exercise the comparator invocation code that runs in
|
||||
// equalityCheck() (called from interpreted and compiled code)
|
||||
expression = parser.parseExpression("#aa==#bb");
|
||||
StandardEvaluationContext sec = new StandardEvaluationContext();
|
||||
Apple aa = new Apple(1);
|
||||
Apple bb = new Apple(2);
|
||||
sec.setVariable("aa",aa);
|
||||
sec.setVariable("bb",bb);
|
||||
boolean b = expression.getValue(sec, Boolean.class);
|
||||
// Verify what the expression caused aa to be compared to
|
||||
assertEquals(bb,aa.gotComparedTo);
|
||||
assertFalse(b);
|
||||
bb.setValue(1);
|
||||
b = expression.getValue(sec, Boolean.class);
|
||||
assertEquals(bb,aa.gotComparedTo);
|
||||
assertTrue(b);
|
||||
|
||||
public Apple(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public void setValue(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
assertCanCompile(expression);
|
||||
|
||||
@Override
|
||||
public int compareTo(Apple that) {
|
||||
this.gotComparedTo = that;
|
||||
if (this.i<that.i) {
|
||||
return -1;
|
||||
}
|
||||
else if (this.i>that.i) {
|
||||
return +1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// For opNe_SPR14863
|
||||
public static class MyContext {
|
||||
// Similar test with compiled expression
|
||||
aa = new Apple(99);
|
||||
bb = new Apple(100);
|
||||
sec.setVariable("aa",aa);
|
||||
sec.setVariable("bb",bb);
|
||||
b = expression.getValue(sec, Boolean.class);
|
||||
assertFalse(b);
|
||||
assertEquals(bb,aa.gotComparedTo);
|
||||
bb.setValue(99);
|
||||
b = expression.getValue(sec, Boolean.class);
|
||||
assertTrue(b);
|
||||
assertEquals(bb,aa.gotComparedTo);
|
||||
|
||||
private final Map<String, String> data;
|
||||
|
||||
public MyContext(Map<String, String> data) {
|
||||
this.data = data;
|
||||
}
|
||||
List<String> ls = new ArrayList<String>();
|
||||
ls.add(new String("foo"));
|
||||
StandardEvaluationContext context = new StandardEvaluationContext(ls);
|
||||
expression = parse("get(0) == 'foo'");
|
||||
assertTrue(expression.getValue(context, Boolean.class));
|
||||
assertCanCompile(expression);
|
||||
assertTrue(expression.getValue(context, Boolean.class));
|
||||
|
||||
public Map<String, String> getData() {
|
||||
return data;
|
||||
}
|
||||
ls.remove(0);
|
||||
ls.add("goo");
|
||||
assertFalse(expression.getValue(context, Boolean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -2733,7 +2691,6 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
checkCalc(p,"payload.valueI*payload.valueBB20",2400);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void opModulus_mixedNumberTypes() throws Exception {
|
||||
PayloadX p = new PayloadX();
|
||||
@@ -4430,10 +4387,10 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
|
||||
// // time it interpreted
|
||||
// long stime = System.currentTimeMillis();
|
||||
// for (int i = 0;i<100000;i++) {
|
||||
// for (int i = 0; i < 100000; i++) {
|
||||
// v = expression.getValue(ctx,holder);
|
||||
// }
|
||||
// System.out.println((System.currentTimeMillis()-stime));
|
||||
// System.out.println((System.currentTimeMillis() - stime));
|
||||
|
||||
assertCanCompile(expression);
|
||||
v = expression.getValue(ctx,holder);
|
||||
@@ -4441,10 +4398,10 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
|
||||
// // time it compiled
|
||||
// stime = System.currentTimeMillis();
|
||||
// for (int i = 0;i<100000;i++) {
|
||||
// for (int i = 0; i < 100000; i++) {
|
||||
// v = expression.getValue(ctx,holder);
|
||||
// }
|
||||
// System.out.println((System.currentTimeMillis()-stime));
|
||||
// System.out.println((System.currentTimeMillis() - stime));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -5660,4 +5617,48 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Apple implements Comparable<Apple> {
|
||||
|
||||
public Object gotComparedTo = null;
|
||||
public int i;
|
||||
|
||||
public Apple(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public void setValue(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Apple that) {
|
||||
this.gotComparedTo = that;
|
||||
if (this.i < that.i) {
|
||||
return -1;
|
||||
}
|
||||
else if (this.i > that.i) {
|
||||
return +1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// For opNe_SPR14863
|
||||
public static class MyContext {
|
||||
|
||||
private final Map<String, String> data;
|
||||
|
||||
public MyContext(Map<String, String> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public Map<String, String> getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user