@Test
public void testFindNearestNode() {

    RBTree<Integer, String> tree = new RBTree<Integer, String>();
    tree.insert( 10, "" + 10 );
    tree.insert( 20, "" + 20 );
    tree.insert( 25, "" + 25 );
    tree.insert( 15, "" + 15 );
    tree.insert( 5, "" + 5 );
    assertEquals(5, (int)tree.findNearestNode(2, false, RBTree.Boundary.LOWER).key);
    assertEquals(null, tree.findNearestNode(2, false, RBTree.Boundary.UPPER));
    assertEquals(5, (int)tree.findNearestNode(2, true, RBTree.Boundary.LOWER).key);
    assertEquals(null, tree.findNearestNode(2, true, RBTree.Boundary.UPPER));
    assertEquals(10, (int)tree.findNearestNode(5, false, RBTree.Boundary.LOWER).key);
    assertEquals(null, tree.findNearestNode(5, false, RBTree.Boundary.UPPER));
    assertEquals(5, (int)tree.findNearestNode(5, true, RBTree.Boundary.LOWER).key);
    assertEquals(5, (int)tree.findNearestNode(5, true, RBTree.Boundary.UPPER).key);
    assertEquals(15, (int)tree.findNearestNode(12, false, RBTree.Boundary.LOWER).key);
    assertEquals(10, (int)tree.findNearestNode(12, false, RBTree.Boundary.UPPER).key);
    assertEquals(20, (int)tree.findNearestNode(15, false, RBTree.Boundary.LOWER).key);
    assertEquals(10, (int)tree.findNearestNode(15, false, RBTree.Boundary.UPPER).key);
    assertEquals(15, (int)tree.findNearestNode(15, true, RBTree.Boundary.UPPER).key);
    assertEquals(15, (int)tree.findNearestNode(15, true, RBTree.Boundary.LOWER).key);
    assertEquals(20, (int)tree.findNearestNode(25, false, RBTree.Boundary.UPPER).key);
    assertEquals(null, tree.findNearestNode(25, false, RBTree.Boundary.LOWER));
    assertEquals(25, (int)tree.findNearestNode(25, true, RBTree.Boundary.LOWER).key);
    assertEquals(25, (int)tree.findNearestNode(25, true, RBTree.Boundary.UPPER).key);
    assertEquals(25, (int)tree.findNearestNode(27, false, RBTree.Boundary.UPPER).key);
    assertEquals(null, tree.findNearestNode(27, false, RBTree.Boundary.LOWER));
    assertEquals(25, (int)tree.findNearestNode(27, true, RBTree.Boundary.UPPER).key);
    assertEquals(null, tree.findNearestNode(27, true, RBTree.Boundary.LOWER));
}