GenericBinaryTreeUsage { public String max(BinaryTree<String> tree) { return tree.match(new BinaryTree.MatchBlock<String, String>() { @Override public String _case(Node<String> x) { final String maxLeft = max(x.left); final String maxRight = max(x.right); return maxString(maxString(maxLeft, maxRight), x.value); } @Override public String _case(EmptyTree<String> x) { return null; } }); }  BinaryTree<String> createExample(); String max(BinaryTree<String> tree);  }
@Test public void testMax() { GenericBinaryTreeUsage usage = new GenericBinaryTreeUsage(); BinaryTree<String> empty = _EmptyTree(); assertEquals(null, usage.max(empty)); assertEquals("whatever", usage.max(_Node("hello", _Node("goodbye", empty, empty), _Node("whatever", empty, _Node("foo", empty, empty))))); }