MVELExpressionEvaluator implements ExpressionEvaluator { @Override public boolean evaluateUnaryExpression(String rawExpression, Object resultValue, Class<?> resultClass) { Map<String, Object> params = new HashMap<>(); params.put(ACTUAL_VALUE_IDENTIFIER, resultValue); Object expressionResult = compileAndExecute(rawExpression, params); if (!(expressionResult instanceof Boolean)) { return compareValues(expressionResult, resultValue); } return (boolean) expressionResult; } MVELExpressionEvaluator(ClassLoader classLoader); @Override boolean evaluateUnaryExpression(String rawExpression, Object resultValue, Class<?> resultClass); @Override Object evaluateLiteralExpression(String rawExpression, String className, List<String> genericClasses); @Override String fromObjectToExpression(Object value);  }
@Test public void evaluateUnaryExpression() { assertTrue(evaluator.evaluateUnaryExpression(mvelExpression("java.util.Objects.equals(" + ACTUAL_VALUE_IDENTIFIER + ", \"Test\")"), "Test", String.class)); assertFalse(evaluator.evaluateUnaryExpression(mvelExpression("java.util.Objects.equals(" + ACTUAL_VALUE_IDENTIFIER + ", " + "\"Test\")"), "Test1", String.class)); assertTrue(evaluator.evaluateUnaryExpression(mvelExpression("1"), 1, Integer.class)); assertFalse(evaluator.evaluateUnaryExpression(mvelExpression("2"), 1, Integer.class)); assertTrue(evaluator.evaluateUnaryExpression(mvelExpression(""), null, String.class)); assertFalse(evaluator.evaluateUnaryExpression(mvelExpression(""), "", String.class)); assertTrue(evaluator.evaluateUnaryExpression(mvelExpression(null), null, String.class)); assertFalse(evaluator.evaluateUnaryExpression(mvelExpression(null), "null", String.class)); assertTrue(evaluator.evaluateUnaryExpression(mvelExpression("\"\""), "", String.class)); assertFalse(evaluator.evaluateUnaryExpression(mvelExpression(null), "", String.class)); assertTrue(evaluator.evaluateUnaryExpression(mvelExpression(ACTUAL_VALUE_IDENTIFIER + " == 123"), 123, Integer.class)); assertTrue(evaluator.evaluateUnaryExpression(mvelExpression(ACTUAL_VALUE_IDENTIFIER + " != 123"), 321, Integer.class)); assertFalse(evaluator.evaluateUnaryExpression(mvelExpression(ACTUAL_VALUE_IDENTIFIER + " == 123"), 321, Integer.class)); assertFalse(evaluator.evaluateUnaryExpression(mvelExpression(ACTUAL_VALUE_IDENTIFIER + " != 123"), 123, Integer.class)); assertThatThrownBy(() -> evaluator.evaluateUnaryExpression(null, "", String.class)) .isInstanceOf(IllegalArgumentException.class) .hasMessageStartingWith("Malformed MVEL expression"); }