1   
2   package org.onemind.commons.java.pattern;
3   
4   import junit.framework.TestCase;
5   /***
6    * @author TiongHiang Lee (tlee@i2rd.com)
7    * @version $Id: DynamicVisitorTest.java,v 1.1 2004/10/31 16:03:44 thlee Exp $ $Name:  $
8    */
9   public class DynamicVisitorTest extends TestCase
10  {
11  
12      private class TestBaseClass
13      {
14      }
15  
16      public class TestClass extends TestBaseClass
17      {
18      }
19  
20      public class TestSubClass extends TestClass
21      {
22      }
23  
24      public class TestVisitor extends DynamicVisitor
25      {
26  
27          /*** 
28           * {@inheritDoc}
29           */
30          protected void initNodeHandlers()
31          {
32              addMethodNodeHandler(TestBaseClass.class, "visit");
33              addMethodNodeHandler(TestClass.class, "visit");
34              addMethodNodeHandler(TestSubClass.class, "visit");
35          }
36  
37          public Object visit(TestBaseClass obj, Object[] data)
38          {
39              assertTrue(obj.getClass()==TestBaseClass.class);
40              return null;
41          }
42  
43          public Object visit(TestClass obj, Object[] data)
44          {
45              assertTrue(obj.getClass()==TestClass.class);
46              return null;
47          }
48  
49          public Object visit(TestSubClass obj, Object[] data)
50          {
51              assertTrue(obj.getClass()==TestSubClass.class);
52              return null;
53          }
54      };
55  
56      public void testVisitor()
57      {
58          TestVisitor visitor = new TestVisitor();
59      }
60  }