KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > FieldGetOutOfWeaver


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;
9
10 import junit.framework.TestCase;
11
12 import java.io.PrintStream JavaDoc;
13
14 import org.codehaus.aspectwerkz.annotation.Before;
15 import org.codehaus.aspectwerkz.joinpoint.StaticJoinPoint;
16
17 /**
18  * @author <a HREF="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
19  */

20 public class FieldGetOutOfWeaver extends TestCase {
21
22     static String JavaDoc s_log = "";
23
24     public void testSystemGet() {
25         s_log = "";
26         PrintStream JavaDoc out = System.out;
27         out = Foo.out;// match as well
28
assertEquals("advice advice ", s_log);
29     }
30
31     public void testSystemGetOutsideCode() {
32         s_log = "";
33         PrintStream JavaDoc out = System.out;
34         out = Foo.out;
35         assertEquals("", s_log);
36     }
37
38     public void testSystemGetTyped() {
39         s_log = "";
40         PrintStream JavaDoc out = System.out;
41         out = Foo.out;
42         assertEquals("adviceTyped ", s_log);
43     }
44
45     public void testSystemGetPatternedTyped() {
46         s_log = "";
47         PrintStream JavaDoc out = System.out;
48         out = Foo.out;
49         assertEquals("advicePatternedTyped ", s_log);
50     }
51
52     public static void main(String JavaDoc[] args) {
53         junit.textui.TestRunner.run(suite());
54     }
55
56     public static junit.framework.Test suite() {
57         return new junit.framework.TestSuite(FieldGetOutOfWeaver.class);
58     }
59
60     public static class Foo {
61         public static PrintStream JavaDoc out;
62     }
63
64     public static class Aspect {
65
66         @Before("get(* out) && withincode(* test.FieldGetOutOfWeaver.testSystemGet(..))")
67         void before(StaticJoinPoint sjp) {
68             FieldGetOutOfWeaver.s_log += "advice ";
69         }
70
71         @Before("get(* java.lang.System.out) && withincode(* test.FieldGetOutOfWeaver.testSystemGetTyped(..))")
72         void beforeTyped() {
73             FieldGetOutOfWeaver.s_log += "adviceTyped ";
74         }
75
76         @Before("get(* java.lang.*.out) && withincode(* test.FieldGetOutOfWeaver.testSystemGetPatternedTyped(..))")
77         void beforePatternedTyped() {
78             FieldGetOutOfWeaver.s_log += "advicePatternedTyped ";
79         }
80     }
81 }
82
Popular Tags