1 16 17 package org.apache.commons.jexl.junit; 18 19 import java.util.HashMap ; 20 import java.util.Map ; 21 22 import junit.framework.Assert; 23 24 import org.apache.commons.jexl.Expression; 25 import org.apache.commons.jexl.ExpressionFactory; 26 import org.apache.commons.jexl.JexlContext; 27 import org.apache.commons.jexl.JexlHelper; 28 29 38 public class Asserter extends Assert { 39 40 41 private final Map variables = new HashMap (); 42 43 private final JexlContext context = JexlHelper.createContext(); 44 45 49 public Asserter() { 50 51 } 52 53 59 public Asserter(Object variableValue) { 60 setVariable("this", variableValue); 61 } 62 63 72 public void assertExpression(String expression, Object expected) throws Exception { 73 Expression exp = ExpressionFactory.createExpression(expression); 74 75 context.setVars(variables); 76 Object value = exp.evaluate(context); 77 78 assertEquals("expression: " + expression, expected, value); 79 } 80 81 88 public void setVariable(String name, Object value) { 89 variables.put(name, value); 90 } 91 92 } 93 | Popular Tags |