KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > tree > NodeCountTestBase


1 package com.tonbeller.wcf.tree;
2
3 import junit.framework.TestCase;
4
5
6 /**
7  * @author av
8  */

9 public class NodeCountTestBase extends TestCase {
10   protected void assertChildCount(TreeModel tm, int level, int count) {
11     Object JavaDoc[] o = getChildren(tm, level);
12     assertEquals("child count ", count, o.length);
13   }
14
15   protected Object JavaDoc [] getChildren(TreeModel tm, int level) {
16     Object JavaDoc[] o = tm.getRoots();
17     for (int i = 0; i < level; i++) {
18       Object JavaDoc 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 JavaDoc[] o = getChildren(tm, path);
27     assertEquals("child count ", count, o.length);
28   }
29
30   protected Object JavaDoc [] getChildren(TreeModel tm, int[] path) {
31     Object JavaDoc[] o = tm.getRoots();
32     for (int i = 0; i < path.length; i++) {
33       Object JavaDoc 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 JavaDoc[] o = getChildren(tm, level-1);
42     assertFalse("leaf expected ", tm.hasChildren(o[0]));
43   }
44
45   protected void testParentChildConsistence(TreeModel ttm) {
46     Object JavaDoc[] roots = ttm.getRoots();
47     testParentChildConsistence(ttm, null, roots);
48   }
49   
50   protected void testParentChildConsistence(TreeModel ttm, Object JavaDoc parent, Object JavaDoc[] children) {
51     for (int i = 0; i < children.length; i++) {
52       Object JavaDoc 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