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;
08:
09: import junit.framework.TestCase;
10:
11: import java.io.PrintStream;
12:
13: import org.codehaus.aspectwerkz.annotation.Before;
14: import org.codehaus.aspectwerkz.joinpoint.StaticJoinPoint;
15:
16: /**
17: * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
18: */
19: public class FieldGetOutOfWeaver extends TestCase {
20:
21: static String s_log = "";
22:
23: public void testSystemGet() {
24: s_log = "";
25: PrintStream out = System.out;
26: out = Foo.out;// match as well
27: assertEquals("advice advice ", s_log);
28: }
29:
30: public void testSystemGetOutsideCode() {
31: s_log = "";
32: PrintStream out = System.out;
33: out = Foo.out;
34: assertEquals("", s_log);
35: }
36:
37: public void testSystemGetTyped() {
38: s_log = "";
39: PrintStream out = System.out;
40: out = Foo.out;
41: assertEquals("adviceTyped ", s_log);
42: }
43:
44: public void testSystemGetPatternedTyped() {
45: s_log = "";
46: PrintStream out = System.out;
47: out = Foo.out;
48: assertEquals("advicePatternedTyped ", s_log);
49: }
50:
51: public static void main(String[] args) {
52: junit.textui.TestRunner.run(suite());
53: }
54:
55: public static junit.framework.Test suite() {
56: return new junit.framework.TestSuite(FieldGetOutOfWeaver.class);
57: }
58:
59: public static class Foo {
60: public static PrintStream out;
61: }
62:
63: public static class Aspect {
64:
65: @Before("get(* out) && withincode(* test.FieldGetOutOfWeaver.testSystemGet(..))")
66: void before(StaticJoinPoint sjp) {
67: FieldGetOutOfWeaver.s_log += "advice ";
68: }
69:
70: @Before("get(* java.lang.System.out) && withincode(* test.FieldGetOutOfWeaver.testSystemGetTyped(..))")
71: void beforeTyped() {
72: FieldGetOutOfWeaver.s_log += "adviceTyped ";
73: }
74:
75: @Before("get(* java.lang.*.out) && withincode(* test.FieldGetOutOfWeaver.testSystemGetPatternedTyped(..))")
76: void beforePatternedTyped() {
77: FieldGetOutOfWeaver.s_log += "advicePatternedTyped ";
78: }
79: }
80: }
|