ExpressionLanguageBasedConditionEvaluator implements ConditionEvaluator { @Override public boolean evaluate(Request request, ExecutionContext executionContext) { if (expression != null) { StandardEvaluationContext context = new StandardEvaluationContext(); context.setVariable("request", new EvaluableRequest(request)); context.setVariable("context", new EvaluableExecutionContext(executionContext)); return this.expression.getValue(context, Boolean.class); } return true; } ExpressionLanguageBasedConditionEvaluator(final String condition); @Override boolean evaluate(Request request, ExecutionContext executionContext);  }
@Test public void shouldEvalTrueWithEmpty() { ExpressionLanguageBasedConditionEvaluator evaluator = new ExpressionLanguageBasedConditionEvaluator(null); Request request = mock(Request.class); ExecutionContext executionContext = mock(ExecutionContext.class); boolean evaluate = evaluator.evaluate(request, executionContext); assertTrue(evaluate); }
@Test public void shouldEvalTrueWithTrue() { ExpressionLanguageBasedConditionEvaluator evaluator = new ExpressionLanguageBasedConditionEvaluator("true"); Request request = mock(Request.class); ExecutionContext executionContext = mock(ExecutionContext.class); boolean evaluate = evaluator.evaluate(request, executionContext); assertTrue(evaluate); }
@Test public void shouldEvalFalseWithFalse() { ExpressionLanguageBasedConditionEvaluator evaluator = new ExpressionLanguageBasedConditionEvaluator("false"); Request request = mock(Request.class); ExecutionContext executionContext = mock(ExecutionContext.class); boolean evaluate = evaluator.evaluate(request, executionContext); assertFalse(evaluate); }
@Test public void shouldEvalFalseWithParseException() { ExpressionLanguageBasedConditionEvaluator evaluator = new ExpressionLanguageBasedConditionEvaluator("foo bar"); Request request = mock(Request.class); ExecutionContext executionContext = mock(ExecutionContext.class); boolean evaluate = evaluator.evaluate(request, executionContext); assertFalse(evaluate); }