### Question:
JexlExpressionEvaluator implements ExpressionEvaluator { @Override public Object evaluate(String expression, Map<String, Object> context) { JexlContext jexlContext = new MapContext(context); try { Map<String, JexlExpression> expressionMap = expressionMapThreadLocal.get(); JexlExpression jexlExpression = expressionMap.get(expression); if (jexlExpression == null) { jexlExpression = getJexlEngine().createExpression(expression); expressionMap.put(expression, jexlExpression); } return jexlExpression.evaluate(jexlContext); } catch (Exception e) { throw new EvaluationException("An error occurred when evaluating expression " + expression, e); } } JexlExpressionEvaluator();  JexlExpressionEvaluator(final boolean silent, final boolean strict);  JexlExpressionEvaluator(String expression);  JexlExpressionEvaluator(Map<String, Object> context);  JexlExpressionEvaluator(JexlContext jexlContext); @Override Object evaluate(String expression, Map<String, Object> context); @Override Object evaluate(Map<String, Object> context); JexlExpression getJexlExpression(); void setJexlEngine(JexlEngine jexlEngine); JexlEngine getJexlEngine(); @Override String getExpression();  }### Answer:
@Test public void simple2VarExpression() { String expression = "2 * x + y"; Map<String, Object> vars = new HashMap<>(); vars.put("x", 2); vars.put("y", 3); ExpressionEvaluator expressionEvaluator = new JexlExpressionEvaluator(); Object result = expressionEvaluator.evaluate(expression, vars); assertNotNull(result); assertEquals("Simple 2-var expression evaluation result is wrong", "7", result.toString()); }
@Test public void shouldThrowEvaluationExceptionWhenError() { String expression = "2 * x + y )"; Map<String, Object> vars = new HashMap<>(); vars.put("x", 2); vars.put("y", 3); ExpressionEvaluator expressionEvaluator = new JexlExpressionEvaluator(); thrown.expect(EvaluationException.class); thrown.expectMessage(CoreMatchers.both(CoreMatchers.containsString("error")).and(CoreMatchers.containsString(expression))); Object result = expressionEvaluator.evaluate( expression, vars ); assertNotNull( result ); }
@Test public void evaluateWhenVarIsNull() { String expression = "2*x + dummy.intValue"; Map<String, Object> vars = new HashMap<>(); vars.put("x", 2); vars.put("dummy", null); ExpressionEvaluator expressionEvaluator = new JexlExpressionEvaluator(); Object result = expressionEvaluator.evaluate( expression , vars); assertEquals("Incorrect evaluation when a var is null", "4", result.toString()); }
@Test public void evaluateWhenExpressionVarIsUndefined() { String expression = "dummy.intValue"; Map<String, Object> vars = new HashMap<>(); ExpressionEvaluator expressionEvaluator = new JexlExpressionEvaluator(); Object result = expressionEvaluator.evaluate( expression, vars ); assertNull(result); }