KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > polymorphic > PolymorphicTest


1 package test.polymorphic;
2
3 import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
4 import org.codehaus.aspectwerkz.joinpoint.MethodRtti;
5 import org.codehaus.aspectwerkz.joinpoint.ConstructorRtti;
6 import org.codehaus.aspectwerkz.joinpoint.Rtti;
7 import junit.framework.TestCase;
8
9 public class PolymorphicTest extends TestCase {
10
11     public static StringBuffer JavaDoc LOG = new StringBuffer JavaDoc("");
12
13     public void testPolymorphicCallJoinPoint() {
14         // see AW-228
15
LOG = new StringBuffer JavaDoc("");
16         SubClass child = new SubClass();
17         child.methodTest();
18         assertEquals("call child parent parent 1 ", LOG.toString());
19
20         LOG = new StringBuffer JavaDoc("");
21         SuperClass parent = new SuperClass();
22         parent.methodTest();
23         assertEquals("call parent ", LOG.toString());
24     }
25
26     public void testCtorCall() {
27         LOG = new StringBuffer JavaDoc("");
28         SubClass child = new SubClass("s");
29         assertEquals("callctor parent s child s ", LOG.toString());
30
31         LOG = new StringBuffer JavaDoc("");
32         SuperClass parent = new SuperClass("ss");
33         assertEquals("callctor parent ss ", LOG.toString());
34     }
35
36     public void testCtorExecution() {
37         LOG = new StringBuffer JavaDoc("");
38         SubClass child = new SubClass(0);
39         assertEquals("exector parent 0 exector child 0 ", LOG.toString());
40
41         LOG = new StringBuffer JavaDoc("");
42         SuperClass parent = new SuperClass(1);
43         assertEquals("exector parent 1 ", LOG.toString());
44     }
45
46     public static void main(String JavaDoc[] args) {
47         junit.textui.TestRunner.run(suite());
48     }
49
50     public static junit.framework.Test suite() {
51         return new junit.framework.TestSuite(PolymorphicTest.class);
52     }
53
54
55     //---- Aspect
56

57     public static class TestAspect {
58
59         public void method1Advise(JoinPoint joinPoint) {
60             MethodRtti mrtti = (MethodRtti) joinPoint.getRtti();
61             LOG.append("call ");
62         }
63
64         public void ctor1Advise(JoinPoint joinPoint) {
65             ConstructorRtti crtti = (ConstructorRtti) joinPoint.getRtti();
66             LOG.append("exector ");
67         }
68
69         public void ctor2Advise(JoinPoint joinPoint) {
70             ConstructorRtti crtti = (ConstructorRtti) joinPoint.getRtti();
71             LOG.append("callctor ");
72         }
73     }
74 }
Popular Tags