AbstractRotatingBinarySearchTree extends BinarySearchTree<E, N> { protected void rotateRight(N target) { final N substitute = (N) target.getLeftChild(); if (substitute == null) { throw new IllegalStateException(); } initiateRotation(target, substitute); target.setLeftChild(substitute.getRightChild()); substitute.setParent(target.getParent()); substitute.setRightChild(target); target.setParent(substitute); } AbstractRotatingBinarySearchTree(Comparator<E> comparator, TreeNodeFactory<E, N> factory);   }
@Test public void testRotateRight() throws Exception { final AbstractRotatingBinarySearchTree<Integer, BinaryTreeNode<Integer>> tree = tree(); tree.insert(5, 3, 9, 1, 4, 7, 10, 6, 8); final BinaryTreeNode<Integer> node = tree.find(9); tree.rotateRight(node); assertThat(node.getParent(), is(notNullValue())); assertThat(node.getParent().getValue(), is(7)); assertThat(node.getLeftChild(), is(notNullValue())); assertThat(node.getLeftChild().getValue(), is(8)); assertThat(node.getRightChild(), is(notNullValue())); assertThat(node.getRightChild().getValue(), is(10)); }