ArrayCreation extends ContainerExpression { @Override public IJsonNode evaluate(final IJsonNode node, final IJsonNode target, final EvaluationContext context) { final IArrayNode targetArray = SopremoUtil.reinitializeTarget(target, ArrayNode.class); for (int index = 0; index < this.elements.size(); index++) targetArray.add(this.elements.get(index).evaluate(node, targetArray.get(index), context)); return targetArray; } ArrayCreation(final EvaluationExpression... elements);  ArrayCreation(final List<EvaluationExpression> elements); int size(); @Override boolean equals(final Object obj); @Override IJsonNode evaluate(final IJsonNode node, final IJsonNode target, final EvaluationContext context); @Override int hashCode(); @Override List<? extends EvaluationExpression> getChildren(); @Override void setChildren(final List<? extends EvaluationExpression> children); @Override void toString(final StringBuilder builder);  }
@Test public void shouldCreateArrayWithListAsParam() { final List<EvaluationExpression> list = new ArrayList<EvaluationExpression>(); list.add(new ConstantExpression(IntNode.valueOf(0))); list.add(EvaluationExpression.VALUE); final IJsonNode result = new ArrayCreation(list).evaluate(IntNode.valueOf(42), null, this.context); Assert.assertEquals(createArrayNode(IntNode.valueOf(0), IntNode.valueOf(42)), result); }
@Test public void shouldReuseTarget() { final IJsonNode target = new ArrayNode(); final IJsonNode result = new ArrayCreation(new ConstantExpression(IntNode.valueOf(42))).evaluate( IntNode.valueOf(42), target, this.context); Assert.assertEquals(new ArrayNode(IntNode.valueOf(42)), result); Assert.assertSame(target, result); }
@Test public void shouldNotReuseTargetIfWrongType() { final IJsonNode target = new ObjectNode(); final IJsonNode result = new ArrayCreation(new ConstantExpression(IntNode.valueOf(42))).evaluate( IntNode.valueOf(42), target, this.context); Assert.assertEquals(new ArrayNode(IntNode.valueOf(42)), result); Assert.assertNotSame(target, result); }