SpelExpression extends AbstractExpression { @Override protected Object eval(Object context, Map<String, Object> vars) { return expr.eval(new DefaultElEvalContext(context, vars)); } SpelExpression(AstExpr expr); Object eval(ElEvalContext context); @Override String toString();  }
@Test public void testArrayItem() { int[] a = new int[]{1,2,3,4,5}; Map<String, Object> m = new HashMap<>(); m.put("a", a); m.put("s", "str"); Map<String, Object> vars = new HashMap<>(); vars.put("a", a); vars.put("m", m); vars.put("index", 0); vars.put("p", "s"); assertEquals(1, eval("a[0]",vars)); assertEquals(1, eval("a[index]",vars)); assertEquals(2, eval("a[index + 1]",vars)); assertEquals(1, eval("m['a'][0]",vars)); assertEquals("str", eval("m['s']",vars)); assertEquals("str", eval("m[p]",vars)); }
@Test public void testProperty() { Map<String,Object> m = New.hashMap("a","b"); assertEquals("b", eval("['a']", m)); Getter getter = new Getter() { @Override public Object get(String name) { return m.get(name); } }; Map<String, Object> vars = New.hashMap("o", getter); assertEquals("b", eval("o['a']", vars)); }
@Test public void testStaticField() { assertEquals(Boolean.TRUE,eval("T(java.lang.Boolean).TRUE")); assertEquals(Boolean.TRUE,eval("T(Boolean).TRUE")); assertEquals(Boolean.TRUE,eval("T(Strings).isEmpty('')")); }
@Test public void testVariableSpecialCharacters() { eval("$name"); eval("_name"); }