1 package com.tonbeller.wcf.tree; 2 3 import junit.framework.TestCase; 4 5 8 public class TreeModelDecoratorTest extends TestCase { 9 10 public TreeModelDecoratorTest(String arg0) { 11 super(arg0); 12 } 13 14 N root; 15 TestModel tree; 16 17 NodeFilter filter = new NodeFilter() { 18 public boolean accept(Object node) { 19 return "*".equals(((N) node).getLabel()); 20 } 21 }; 22 23 34 35 protected void setUp() throws Exception { 36 root = 37 new N( 38 "a", 39 new N("b", new N("d", new N("h"), new N("*")), new N("e", new N("j"), new N("k"))), 40 new N("c", new N("f", new N("l"), new N("m")), new N("*", new N("n"), new N("o")))); 41 tree = new TestModel(root); 42 assertEquals("a[b[d[h,*],e[j,k]],c[f[l,m],*[n,o]]]", TestModel.print(tree)); 43 } 44 45 public void testOptimizer() { 46 47 OptimizingTreeModelDecorator opt = new OptimizingTreeModelDecorator(filter, tree); 48 assertEquals("b[d[h,*]],c[*[n,o]]", TestModel.print(opt)); 49 50 opt.setOptimizeRoot(false); 51 assertEquals("a[b[d[h,*]],c[*[n,o]]]", TestModel.print(opt)); 52 53 opt.setOptimizeLeafs(true); 54 assertEquals("a[b[d[*]],c[*]]", TestModel.print(opt)); 56 } 57 58 public void testCachingOptimizer() { 59 CachingTreeModelDecorator t1 = new CachingTreeModelDecorator(tree); 60 OptimizingTreeModelDecorator opt = new OptimizingTreeModelDecorator(filter, t1); 61 CachingTreeModelDecorator t2 = new CachingTreeModelDecorator(opt); 62 assertEquals("b[d[h,*]],c[*[n,o]]", TestModel.print(t2)); 63 64 opt.setOptimizeRoot(false); 65 assertEquals("a[b[d[h,*]],c[*[n,o]]]", TestModel.print(t2)); 66 67 opt.setOptimizeLeafs(true); 68 assertEquals("a[b[d[*]],c[*]]", TestModel.print(t2)); 70 } 71 72 public void testMutable() { 73 MutableTreeModelDecorator t0 = new MutableTreeModelDecorator(tree); 74 CachingTreeModelDecorator t1 = new CachingTreeModelDecorator(t0); 75 OptimizingTreeModelDecorator opt = new OptimizingTreeModelDecorator(filter, t1); 76 CachingTreeModelDecorator t2 = new CachingTreeModelDecorator(opt); 77 assertEquals("b[d[h,*]],c[*[n,o]]", TestModel.print(t2)); 78 79 opt.setOptimizeRoot(false); 80 assertEquals("a[b[d[h,*]],c[*[n,o]]]", TestModel.print(t2)); 81 82 opt.setOptimizeLeafs(true); 83 assertEquals("a[b[d[*]],c[*]]", TestModel.print(t2)); 85 86 t0.move(root, root.getChildren().get(0), 0, 1); 87 assertEquals("a[c[*],b[d[*]]]", TestModel.print(t2)); 88 } 89 90 91 92 } 93 | Popular Tags |