### Question:
SpELAction implements Action { @Override public void execute(Facts facts) { try { StandardEvaluationContext context = new StandardEvaluationContext(); context.setRootObject(facts.asMap()); context.setVariables(facts.asMap()); if (beanResolver != null) { context.setBeanResolver(beanResolver); } compiledExpression.getValue(context); } catch (Exception e) { LOGGER.error("Unable to evaluate expression: '" + expression + "' on facts: " + facts, e); throw e; } } SpELAction(String expression);  SpELAction(String expression, BeanResolver beanResolver);  SpELAction(String expression, ParserContext parserContext);  SpELAction(String expression, ParserContext parserContext, BeanResolver beanResolver); @Override void execute(Facts facts);  }### Answer:
@Test public void testSpELActionExecution() throws Exception { Action markAsAdult = new SpELAction("#{ ['person'].setAdult(true) }"); Facts facts = new Facts(); Person foo = new Person("foo", 20); facts.put("person", foo); markAsAdult.execute(facts); assertThat(foo.isAdult()).isTrue(); }
@Test public void testSpELFunctionExecution() throws Exception { Action printAction = new SpELAction("#{ T(org.jeasy.rules.spel.Person).sayHello() }"); Facts facts = new Facts(); printAction.execute(facts); assertThat(systemOutRule.getLog()).contains("hello"); }
@Test public void testSpELActionExecutionWithFailure() { Action action = new SpELAction("#{ T(org.jeasy.rules.spel.Person).sayHi() }"); Facts facts = new Facts(); Person foo = new Person("foo", 20); facts.put("person", foo); assertThatThrownBy(() -> action.execute(facts)) .isInstanceOf(Exception.class) .hasMessage("EL1004E: Method call: Method sayHi() cannot be found on type org.jeasy.rules.spel.Person"); }
@Test public void testSpELActionWithExpressionAndParserContext() throws Exception { ParserContext context = new TemplateParserContext("%{", "}"); Action printAction = new SpELAction("%{ T(org.jeasy.rules.spel.Person).sayHello() }", context); Facts facts = new Facts(); printAction.execute(facts); assertThat(systemOutRule.getLog()).contains("hello"); }