LowestCommonAncestor { public BinaryNode getRecursive(BinaryNode root, BinaryNode n1, BinaryNode n2) { validateInput(root, n1, n2); return getRecursiveInner(root, n1, n2); }  BinaryNode getRecursive(BinaryNode root, BinaryNode n1, BinaryNode n2); BinaryNode getIterative(BinaryNode root, BinaryNode n1, BinaryNode n2);  }
@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullElementsRecursive() { lca.getRecursive(null, null, null); }
@Test public void shouldFindLCAWhenIsAFatherOfBothNodesRecursive() { BinaryNode<Integer> root = new BinaryNode<Integer>(1); BinaryNode<Integer> n2 = new BinaryNode<Integer>(2); BinaryNode<Integer> n3 = new BinaryNode<Integer>(3); BinaryNode<Integer> n4 = new BinaryNode<Integer>(4); BinaryNode<Integer> n5 = new BinaryNode<Integer>(5); BinaryNode<Integer> n6 = new BinaryNode<Integer>(6); root.setLeft(n2); root.setRight(n3); n2.setLeft(n4); n2.setRight(n5); n4.setLeft(n6); BinaryNode result = lca.getRecursive(root, n5, n6); assertEquals(n2, result); }