BindingTuple implements Environment<Expression, ExprValue> { @Override public ExprValue resolve(Expression var) { if (var instanceof ReferenceExpression) { return resolve(((ReferenceExpression) var)); } else { throw new ExpressionEvaluationException(String.format("can resolve expression: %s", var)); } }  @Override ExprValue resolve(Expression var); abstract ExprValue resolve(ReferenceExpression ref); static BindingTuple EMPTY; }
@Test public void resolve_ref_expression() { BindingTuple bindingTuple = ExprValueUtils.tupleValue(ImmutableMap.of("ip", "209.160.24.63")).bindingTuples(); assertEquals(ExprValueUtils.stringValue("209.160.24.63"), bindingTuple.resolve(DSL.ref("ip", STRING))); }
@Test public void resolve_missing_expression() { BindingTuple bindingTuple = ExprValueUtils.tupleValue(ImmutableMap.of("ip", "209.160.24.63")).bindingTuples(); assertEquals(ExprValueUtils.LITERAL_MISSING, bindingTuple.resolve(DSL.ref("ip_missing", STRING))); }
@Test public void resolve_from_empty_tuple() { assertEquals(ExprValueUtils.LITERAL_MISSING, BindingTuple.EMPTY.resolve(DSL.ref("ip_missing", STRING))); }
@Test public void resolve_literal_expression_throw_exception() { BindingTuple bindingTuple = ExprValueUtils.tupleValue(ImmutableMap.of("ip", "209.160.24.63")).bindingTuples(); ExpressionEvaluationException exception = assertThrows(ExpressionEvaluationException.class, () -> bindingTuple.resolve(DSL.literal(1))); assertEquals("can resolve expression: 1", exception.getMessage()); }