Solution { public int maxDepth(TreeNode root) { if (root == null) { return 0; } else { int leftDepth = maxDepth(root.left); int rightDepth = maxDepth(root.right); return 1 + Integer.max(leftDepth, rightDepth); } }  int maxDepth(TreeNode root);  }
@Test public void noTreeNoDepth() throws Exception { Solution solution = new Solution(); int i = solution.maxDepth(null); assertThat(i, is(0)); }
@Test public void noChildrenOneDepth() throws Exception { Solution solution = new Solution(); int i = solution.maxDepth(new TreeNode(1)); assertThat(i, is(1)); }
@Test public void shouldFindOneChildLonger() throws Exception { TreeNode root = new TreeNode(1); root.left = new TreeNode(2); root.left.left = new TreeNode(3); root.right = new TreeNode(4); Solution solution = new Solution(); int i = solution.maxDepth(root); assertThat(i, is(3)); }