TernaryExpression extends EvaluationExpression { @Override public IJsonNode evaluate(final IJsonNode node, final IJsonNode target, final EvaluationContext context) { if (TypeCoercer.INSTANCE.coerce(this.ifClause.evaluate(node, context), null, BooleanNode.class) == BooleanNode.TRUE) return this.ifExpression.evaluate(node, target, context); return this.thenExpression.evaluate(node, target, context); } TernaryExpression(final EvaluationExpression ifClause, final EvaluationExpression ifExpression,
			final EvaluationExpression thenExpression);  TernaryExpression(final EvaluationExpression ifClause, final EvaluationExpression ifExpression); EvaluationExpression getIfClause(); void setIfClause(final EvaluationExpression ifClause); EvaluationExpression getIfExpression(); void setIfExpression(final EvaluationExpression ifExpression); EvaluationExpression getThenExpression(); void setThenExpression(final EvaluationExpression thenExpression); @Override IJsonNode evaluate(final IJsonNode node, final IJsonNode target, final EvaluationContext context); @SuppressWarnings("unchecked") @Override EvaluationExpression transformRecursively(final TransformFunction function); @Override void toString(final StringBuilder builder); @Override int hashCode(); @Override boolean equals(final Object obj);  }
@Test public void shouldEvaluateIfExpIfClauseIsTrue() { final IJsonNode result = new TernaryExpression(new InputSelection(0), new ConstantExpression(IntNode.valueOf(0)), new ConstantExpression(IntNode.valueOf(1))).evaluate( createArrayNode(BooleanNode.TRUE, BooleanNode.FALSE), null, this.context); Assert.assertEquals(IntNode.valueOf(0), result); }
@Test public void shouldEvaluateThenExpIfClauseIsTrue() { final IJsonNode result = new TernaryExpression(new InputSelection(1), new ConstantExpression(IntNode.valueOf(0)), new ConstantExpression(IntNode.valueOf(1))).evaluate( createArrayNode(BooleanNode.TRUE, BooleanNode.FALSE), null, this.context); Assert.assertEquals(IntNode.valueOf(1), result); }
@Test public void shouldBeMissingIfThenExprIsEmpty() { final IJsonNode result = new TernaryExpression(new InputSelection(1), new ConstantExpression(IntNode.valueOf(0))).evaluate( createArrayNode(BooleanNode.TRUE, BooleanNode.FALSE), null, this.context); Assert.assertEquals(MissingNode.getInstance(), result); }
@Test public void shouldEvaluateIntNodes() { final TernaryExpression ternaryExpression = new TernaryExpression(new ConstantExpression(IntNode.valueOf(0)), new ConstantExpression(IntNode.valueOf(0))); final IJsonNode result = ternaryExpression.evaluate(IntNode.valueOf(42), null, this.context); Assert.assertEquals(MissingNode.getInstance(), result); }
@Test public void shouldEvaluateTextNodes() { final IJsonNode result = new TernaryExpression(new ConstantExpression(TextNode.valueOf("a")), new ConstantExpression(IntNode.valueOf(0))).evaluate(IntNode.valueOf(42), null, this.context); Assert.assertEquals(IntNode.valueOf(0), result); }