1 package org.kuali.common.util.tree.test; 2 3 import org.junit.Assert; 4 import org.junit.Test; 5 import org.kuali.common.util.tree.MutableNode; 6 7 public class MutableNodeTest { 8 9 @Test 10 public void testMutableBasics() { 11 MutableNode<String> root = new MutableNode<String>("root"); 12 MutableNode<String> a = new MutableNode<String>("a"); 13 MutableNode<String> b = new MutableNode<String>("b"); 14 MutableNode<String> one = new MutableNode<String>("1"); 15 MutableNode<String> two = new MutableNode<String>("2"); 16 a.add(one, two); 17 root.add(a, b); 18 Assert.assertFalse(root.getParent().isPresent()); 19 Assert.assertTrue(a.getParent().isPresent()); 20 Assert.assertTrue(b.getParent().isPresent()); 21 Assert.assertTrue(one.getParent().isPresent()); 22 Assert.assertTrue(two.getParent().isPresent()); 23 Assert.assertEquals(a.getParent().get(), b.getParent().get()); 24 Assert.assertTrue(root.isRoot()); 25 Assert.assertFalse(root.isLeaf()); 26 Assert.assertFalse(a.isLeaf()); 27 Assert.assertFalse(a.isRoot()); 28 Assert.assertTrue(b.isLeaf()); 29 Assert.assertEquals(0, root.getLevel()); 30 Assert.assertEquals(1, root.getPath().size()); 31 Assert.assertEquals(3, two.getPath().size()); 32 Assert.assertEquals(two.getElement(), two.getElementPath().get(two.getPath().size() - 1)); 33 Assert.assertEquals(1, root.getElementPath().size()); 34 Assert.assertEquals(root.getElement(), root.getElementPath().get(0)); 35 Assert.assertTrue(two.isAncestor(a)); 36 Assert.assertTrue(one.isChild(a)); 37 } 38 39 @Test 40 public void testMutableIdentity() { 41 MutableNode<String> root = new MutableNode<String>("root"); 42 MutableNode<String> a = new MutableNode<String>("a"); 43 MutableNode<String> b = new MutableNode<String>("b"); 44 MutableNode<String> one = new MutableNode<String>("1"); 45 MutableNode<String> two = new MutableNode<String>("2"); 46 a.add(one, two); 47 root.add(a, b); 48 Assert.assertTrue(a.getParent().get() == root); 49 Assert.assertTrue(two.getParent().get() == a); 50 } 51 52 }