1 8 package test; 9 10 import junit.framework.TestCase; 11 12 import java.io.PrintStream ; 13 14 import org.codehaus.aspectwerkz.annotation.Before; 15 import org.codehaus.aspectwerkz.joinpoint.StaticJoinPoint; 16 17 20 public class FieldGetOutOfWeaver extends TestCase { 21 22 static String s_log = ""; 23 24 public void testSystemGet() { 25 s_log = ""; 26 PrintStream out = System.out; 27 out = Foo.out; assertEquals("advice advice ", s_log); 29 } 30 31 public void testSystemGetOutsideCode() { 32 s_log = ""; 33 PrintStream out = System.out; 34 out = Foo.out; 35 assertEquals("", s_log); 36 } 37 38 public void testSystemGetTyped() { 39 s_log = ""; 40 PrintStream out = System.out; 41 out = Foo.out; 42 assertEquals("adviceTyped ", s_log); 43 } 44 45 public void testSystemGetPatternedTyped() { 46 s_log = ""; 47 PrintStream out = System.out; 48 out = Foo.out; 49 assertEquals("advicePatternedTyped ", s_log); 50 } 51 52 public static void main(String [] 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 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 |