KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.tonbeller.wcf.tree;
2
3 import junit.framework.TestCase;
4 public class NodeFilterTest extends TestCase {
5
6   public NodeFilterTest(String JavaDoc arg0) {
7     super(arg0);
8   }
9
10   class MyNodeFilter implements NodeFilter {
11     public boolean accept(Object JavaDoc node) {
12       return !node.toString().endsWith("[1]");
13     }
14   }
15   
16   class MyFalseFilter implements NodeFilter {
17     public boolean accept(Object JavaDoc node) {
18       return false;
19     }
20   }
21
22   public void testFilteringTreeModelDecorator() {
23     TreeModel tm = new TestTreeModel();
24     tm = new FilteringTreeModelDecorator(tm, new MyNodeFilter());
25     Object JavaDoc[] roots = tm.getRoots();
26     assertEquals(3, roots.length);
27     Object JavaDoc[] a1 = tm.getChildren(roots[0]);
28     assertEquals(3, a1.length);
29     assertEquals("A[0]", a1[0].toString());
30     assertEquals("A[2]", a1[1].toString());
31     assertEquals("A[3]", a1[2].toString());
32
33   }
34
35   public void testAndFilter() {
36     TreeModel tm = new TestTreeModel();
37     AndNodeFilter anf = new AndNodeFilter();
38     anf.add(new MyNodeFilter());
39     anf.add(new MyFalseFilter());
40     tm = new FilteringTreeModelDecorator(tm, anf);
41     Object JavaDoc[] roots = tm.getRoots();
42     assertEquals(0, roots.length);
43   }
44
45 }
46
Popular Tags