### Question:
JexlExpressionEvaluatorNoThreadLocal implements ExpressionEvaluator { @Override public Object evaluate(String expression, Map<String, Object> context) { JexlContext jexlContext = new MapContext(context); try { JexlExpression jexlExpression = expressionMap.get(expression); if (jexlExpression == null) { jexlExpression = jexl.createExpression(expression); expressionMap.put(expression, jexlExpression); } return jexlExpression.evaluate(jexlContext); } catch (Exception e) { throw new EvaluationException("An error occurred when evaluating expression " + expression, e); } } JexlExpressionEvaluatorNoThreadLocal();  JexlExpressionEvaluatorNoThreadLocal(boolean silent, boolean strict);  JexlExpressionEvaluatorNoThreadLocal(String expression);  JexlExpressionEvaluatorNoThreadLocal(Map<String, Object> context);  JexlExpressionEvaluatorNoThreadLocal(JexlContext jexlContext); @Override Object evaluate(String expression, Map<String, Object> context); @Override Object evaluate(Map<String, Object> context); JexlExpression getJexlExpression(); void setJexlEngine(final 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 JexlExpressionEvaluatorNoThreadLocal(); 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 JexlExpressionEvaluatorNoThreadLocal(); 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 JexlExpressionEvaluatorNoThreadLocal(); 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 JexlExpressionEvaluatorNoThreadLocal(); Object result = expressionEvaluator.evaluate( expression, vars ); assertNull(result); }