### Question:
RandomCutTree { static void replaceNode(Node oldNode, Node newNode) { Node parent = oldNode.getParent(); if (parent != null) { if (parent.getLeftChild() == oldNode) { parent.setLeftChild(newNode); } else { parent.setRightChild(newNode); } } newNode.setParent(parent); } protected  RandomCutTree(Builder<?> builder); static Builder builder(); static RandomCutTree defaultTree(long randomSeed); static RandomCutTree defaultTree(); boolean centerOfMassEnabled(); boolean storeSequenceIndexesEnabled(); void deletePoint(WeightedPoint weightedPoint); void addPoint(WeightedPoint weightedPoint); R traverseTree(double[] point, Visitor<R> visitor); R traverseTreeMulti(double[] point, MultiVisitor<R> visitor); Node getRoot(); static final boolean DEFAULT_STORE_SEQUENCE_INDEXES_ENABLED; static final boolean DEFAULT_CENTER_OF_MASS_ENABLED; }### Answer:
@Test public void testReplaceNode() { Node node1 = new Node(new double[] { 1.5, 2.7 }); Node node2 = new Node(new double[] { 3, 1.1 }); Node node3 = new Node(new double[] { 4, 1.1 }); BoundingBox parentBox = new BoundingBox(new double[] { 1.5, 2.7 }).getMergedBox(new double[] { 3, 1.1 }); Cut cut = new Cut(1, 2.0); Node parent = new Node(node1, node2, cut, parentBox); node1.setParent(parent); node2.setParent(parent); assertThat(node3.getParent(), is(nullValue())); RandomCutTree.replaceNode(node1, node3); assertThat(parent.getLeftChild(), sameInstance(node3)); assertThat(parent.getRightChild(), sameInstance(node2)); assertThat(node3.getParent(), sameInstance(parent)); assertThat(node2.getParent(), sameInstance(parent)); parent = new Node(node1, node2, cut, parentBox); node1.setParent(parent); node2.setParent(parent); node3.setParent(null); RandomCutTree.replaceNode(node2, node3); assertThat(parent.getLeftChild(), sameInstance(node1)); assertThat(parent.getRightChild(), sameInstance(node3)); assertThat(node1.getParent(), sameInstance(parent)); assertThat(node3.getParent(), sameInstance(parent)); }