### Question:
Node { public Node addChild(int index, Node node) { if(children.length <= childrenCount) { Node[] newChildren = new Node[children.length + 4]; System.arraycopy(children, 0, newChildren, 0, index); System.arraycopy(children, index, newChildren, index + 1, (childrenCount - index)); children = newChildren; } else { System.arraycopy(children, index, children, index + 1, (childrenCount - index)); } children[index] = node; childrenCount++; node.setParent(this); return this; } Node(NodeType type);  Node(); Node addChild(int index, Node node); Node addChild(Node node); Node getChild(int idx); int getChildrenCount(); void replaceChild(int idx, Node node); Node getParent(); void setParent(Node parent); void visit(NodeTreeVisitor visitor); @SuppressWarnings("unchecked") T deepCopy(); @Override String toString(); NodeType getType(); abstract Node copy(); abstract QuotingAppendable append(QuotingAppendable buffer); void appendChildrenSeparator(QuotingAppendable buffer, int childInd); void appendChildrenStart(QuotingAppendable buffer); void appendChildrenEnd(QuotingAppendable buffer);  }### Answer:
@Test public void testInsert() { assertEquals(0, node.childrenCount); assertNull(node.children); node.addChild(new TestNode()); assertEquals(1, node.childrenCount); assertNotNull(node.children); assertEquals(4, node.children.length); TestNode node1 = new TestNode(); this.node.addChild(0, node1); assertSame(node1, node.children[0]); assertEquals(2, this.node.childrenCount); assertEquals(4, this.node.children.length); TestNode node2 = new TestNode(); this.node.addChild(0, node2); assertSame(node2, node.children[0]); TestNode node3 = new TestNode(); this.node.addChild(0, node3); assertSame(node3, node.children[0]); TestNode node4 = new TestNode(); this.node.addChild(0, node4); assertSame(node4, node.children[0]); assertEquals(5, this.node.childrenCount); assertEquals(8, this.node.children.length); }
@Test public void testAdd() { assertEquals(0, node.childrenCount); assertNull(node.children); node.addChild(new TestNode()); assertEquals(1, node.childrenCount); assertNotNull(node.children); assertEquals(4, node.children.length); node.addChild(new TestNode()); node.addChild(new TestNode()); node.addChild(new TestNode()); assertEquals(4, node.childrenCount); assertEquals(4, node.children.length); node.addChild(new TestNode()); assertEquals(5, node.childrenCount); assertEquals(8, node.children.length); }