1 package com.tonbeller.wcf.tree; 2 3 import junit.framework.TestCase; 4 5 6 9 public class NodeCountTestBase extends TestCase { 10 protected void assertChildCount(TreeModel tm, int level, int count) { 11 Object [] o = getChildren(tm, level); 12 assertEquals("child count ", count, o.length); 13 } 14 15 protected Object [] getChildren(TreeModel tm, int level) { 16 Object [] o = tm.getRoots(); 17 for (int i = 0; i < level; i++) { 18 Object parent = o[0]; 19 assertTrue("has children ", tm.hasChildren(parent)); 20 o = tm.getChildren(parent); 21 } 22 return o; 23 } 24 25 protected void assertChildCount(TreeModel tm, int[] path, int count) { 26 Object [] o = getChildren(tm, path); 27 assertEquals("child count ", count, o.length); 28 } 29 30 protected Object [] getChildren(TreeModel tm, int[] path) { 31 Object [] o = tm.getRoots(); 32 for (int i = 0; i < path.length; i++) { 33 Object parent = o[path[i]]; 34 assertTrue("has children ", tm.hasChildren(parent)); 35 o = tm.getChildren(parent); 36 } 37 return o; 38 } 39 40 protected void assertLevelCount(TreeModel tm, int level) { 41 Object [] o = getChildren(tm, level-1); 42 assertFalse("leaf expected ", tm.hasChildren(o[0])); 43 } 44 45 protected void testParentChildConsistence(TreeModel ttm) { 46 Object [] roots = ttm.getRoots(); 47 testParentChildConsistence(ttm, null, roots); 48 } 49 50 protected void testParentChildConsistence(TreeModel ttm, Object parent, Object [] children) { 51 for (int i = 0; i < children.length; i++) { 52 Object child = children[i]; 53 assertEquals(parent, ttm.getParent(child)); 54 if (ttm.hasChildren(child)) 55 testParentChildConsistence(ttm, child, ttm.getChildren(child)); 56 } 57 } 58 } 59 | Popular Tags |