KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > reflection > ReflectionTest


1 /**************************************************************************************
2  * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
3  * http://aspectwerkz.codehaus.org *
4  * ---------------------------------------------------------------------------------- *
5  * The software in this package is published under the terms of the LGPL license *
6  * a copy of which has been included with this distribution in the license.txt file. *
7  **************************************************************************************/

8 package test.reflection;
9
10 import junit.framework.TestCase;
11
12 /**
13  * The advice used here reverse the sign of the integer returned by the incr(..) methods. Each
14  * incr(..) method return the argument incremented of 1 (or -1 if arg is negative). Child is
15  * overriding a method defined in Super but still does call it. Child is used with a dual pointcut,
16  * defined both in super method and overrided method. Child2 is used in the case of a single
17  * pointcut defined in super method. <p/>For AW-90 same tests are done for static methods
18  */

19 public class ReflectionTest extends TestCase {
20     public void testSinglePointcutOnSuperClassWithOverridedMethodNonDelegating() {
21         OtherChild2 c = new OtherChild2();
22         assertEquals(2, c.incr(1));
23
24         // advice non applied since method is overrided and poincut is NOT hierarchical
25
Super2 s = new Super2();
26         assertEquals(-2, s.incr(1));
27
28         // advice bounded
29
}
30
31     public void testStaticSinglePointcutOnSuperClassWithOverridedMethodNonDelegating() {
32         assertEquals(2, OtherChild2.incrStatic(1));
33
34         // advice non applied since method is overrided and poincut is NOT hierarchical
35
assertEquals(-2, Super2.incrStatic(1));
36
37         // advice bounded
38
}
39
40     public void testSinglePointcutOnSuperClassWithOverridedMethodDelegating() {
41         Child2 c = new Child2();
42         assertEquals(-3, c.incr(1));
43     }
44
45     public void testStaticSinglePointcutOnSuperClassWithOverridedMethodDelegating() {
46         assertEquals(-3, Child2.incrStatic(1));
47     }
48
49     public void testDualPointcutWithOverridedMethodNonDelegating() {
50         OtherChild c = new OtherChild();
51         assertEquals(-2, c.incr(1));
52     }
53
54     public void testStaticDualPointcutWithOverridedMethodNonDelegating() {
55         assertEquals(-2, OtherChild.incrStatic(1));
56     }
57
58     public void testDualPointcutWithOverridedMethodDelegating() {
59         Child c = new Child();
60         assertEquals(+3, c.incr(1));
61     }
62
63     public void testStaticDualPointcutWithOverridedMethodDelegating() {
64         assertEquals(+3, Child.incrStatic(1));
65     }
66
67     public void testDollar() {
68         Child c = new Child();
69         assertEquals(-1, c.do$2(1));
70     }
71
72     public void testReflectionCall() {
73         Child c = new Child();
74         assertEquals(+3, c.reflectionCallIncr(1));
75     }
76
77
78     // -- JUnit
79
public static void main(String JavaDoc[] args) {
80         junit.textui.TestRunner.run(suite());
81     }
82
83     public static junit.framework.Test suite() {
84         return new junit.framework.TestSuite(ReflectionTest.class);
85     }
86 }
Popular Tags