1 4 package org.oddjob.designer.factory; 5 6 import junit.framework.TestCase; 7 8 11 public class SimpleHierarchyTest extends TestCase { 12 13 SimpleHierarchy test; 14 15 protected void setUp() { 16 test = new SimpleHierarchy(String .class); 17 } 18 19 class Count implements HierarchyVisitor { 20 int leaves; 21 int nodes; 22 public void onHierarchy(SimpleHierarchy hierarchy) { 23 nodes++; 24 hierarchy.iterate(this); 25 } 26 public void onLeaf(Object leaf) { 27 System.out.println(leaf); 28 leaves++; 29 } 30 } 31 32 public void test1() { 33 Count c; 34 35 c = new Count(); 36 test.addLeaf("hello"); 37 test.addToHierarchy("big", "world"); 38 test.addToHierarchy("small", "you"); 39 40 test.iterate(c); 41 42 assertEquals("nodes", 2, c.nodes); 43 assertEquals("leaves", 3, c.leaves); 44 45 } 46 47 public void testConvert() { 48 test1(); 49 50 SimpleHierarchy converted = test.convert( 51 new HierarchyConversion() { 52 public Object convert(Object from) { 53 return ((String )from).toUpperCase(); 54 } 55 }, String .class); 56 57 Count c; 58 c = new Count(); 59 60 converted.iterate(c); 61 62 assertEquals("nodes", 2, c.nodes); 63 assertEquals("leaves", 3, c.leaves); 64 } 65 } 66 | Popular Tags |