CoerceExpression extends EvaluationExpression { @Override public IJsonNode evaluate(final IJsonNode node, final IJsonNode target, final EvaluationContext context) { return TypeCoercer.INSTANCE.coerce(this.valueExpression.evaluate(node, context), target, this.targetType); } @SuppressWarnings("unchecked")  CoerceExpression(final Class<? extends IJsonNode> targetType, final EvaluationExpression value);  CoerceExpression(final Class<? extends IJsonNode> targetType); EvaluationExpression getValueExpression(); void setValueExpression(final EvaluationExpression valueExpression); @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 shouldChangeTypeOfIntToText() { final IJsonNode result = new CoerceExpression(TextNode.class).evaluate(IntNode.valueOf(42), null, this.context); Assert.assertEquals(TextNode.valueOf("42"), result); }
@Test public void shouldChangeTypeOfTextInterpretedNumberToInt() { final IJsonNode result = new CoerceExpression(IntNode.class).evaluate(TextNode.valueOf("42"), null, this.context); Assert.assertEquals(IntNode.valueOf(42), result); }
@Test public void shouldOnlyChangeOuterType() { final IJsonNode result = new CoerceExpression(ArrayNode.class).evaluate( createArrayNode(IntNode.valueOf(42), BooleanNode.TRUE), null, this.context); Assert.assertEquals(createArrayNode(IntNode.valueOf(42), BooleanNode.TRUE), result); }
@Test(expected = CoercionException.class) public void shouldThrowExceptionWhenChangeingTextToInt() { new CoerceExpression(IntNode.class).evaluate(TextNode.valueOf("testname"), null, this.context); }