01: /**************************************************************************************
02: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
03: * http://aspectwerkz.codehaus.org *
04: * ---------------------------------------------------------------------------------- *
05: * The software in this package is published under the terms of the LGPL license *
06: * a copy of which has been included with this distribution in the license.txt file. *
07: **************************************************************************************/package test.reflection;
08:
09: import junit.framework.TestCase;
10:
11: /**
12: * The advice used here reverse the sign of the integer returned by the incr(..) methods. Each
13: * incr(..) method return the argument incremented of 1 (or -1 if arg is negative). Child is
14: * overriding a method defined in Super but still does call it. Child is used with a dual pointcut,
15: * defined both in super method and overrided method. Child2 is used in the case of a single
16: * pointcut defined in super method. <p/>For AW-90 same tests are done for static methods
17: */
18: public class ReflectionTest extends TestCase {
19: public void testSinglePointcutOnSuperClassWithOverridedMethodNonDelegating() {
20: OtherChild2 c = new OtherChild2();
21: assertEquals(2, c.incr(1));
22:
23: // advice non applied since method is overrided and poincut is NOT hierarchical
24: Super2 s = new Super2();
25: assertEquals(-2, s.incr(1));
26:
27: // advice bounded
28: }
29:
30: public void testStaticSinglePointcutOnSuperClassWithOverridedMethodNonDelegating() {
31: assertEquals(2, OtherChild2.incrStatic(1));
32:
33: // advice non applied since method is overrided and poincut is NOT hierarchical
34: assertEquals(-2, Super2.incrStatic(1));
35:
36: // advice bounded
37: }
38:
39: public void testSinglePointcutOnSuperClassWithOverridedMethodDelegating() {
40: Child2 c = new Child2();
41: assertEquals(-3, c.incr(1));
42: }
43:
44: public void testStaticSinglePointcutOnSuperClassWithOverridedMethodDelegating() {
45: assertEquals(-3, Child2.incrStatic(1));
46: }
47:
48: public void testDualPointcutWithOverridedMethodNonDelegating() {
49: OtherChild c = new OtherChild();
50: assertEquals(-2, c.incr(1));
51: }
52:
53: public void testStaticDualPointcutWithOverridedMethodNonDelegating() {
54: assertEquals(-2, OtherChild.incrStatic(1));
55: }
56:
57: public void testDualPointcutWithOverridedMethodDelegating() {
58: Child c = new Child();
59: assertEquals(+3, c.incr(1));
60: }
61:
62: public void testStaticDualPointcutWithOverridedMethodDelegating() {
63: assertEquals(+3, Child.incrStatic(1));
64: }
65:
66: public void testDollar() {
67: Child c = new Child();
68: assertEquals(-1, c.do$2(1));
69: }
70:
71: public void testReflectionCall() {
72: Child c = new Child();
73: assertEquals(+3, c.reflectionCallIncr(1));
74: }
75:
76: // -- JUnit
77: public static void main(String[] args) {
78: junit.textui.TestRunner.run(suite());
79: }
80:
81: public static junit.framework.Test suite() {
82: return new junit.framework.TestSuite(ReflectionTest.class);
83: }
84: }
|