KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > prose > crosscut > InterfaceMethodTest


1 package ch.ethz.prose.crosscut;
2
3 import junit.framework.TestCase;
4 import ch.ethz.prose.*;
5 import ch.ethz.prose.filter.*;
6
7 /**
8  * Cross-cut an invokeinterface method call.
9  *
10  * @author Johann Gyger
11  */

12 public class InterfaceMethodTest extends TestCase {
13
14   protected static boolean crosscutted;
15
16   public InterfaceMethodTest(String JavaDoc name) {
17     super(name);
18   }
19
20   protected void setUp() throws SystemStartupException {
21     ProseSystem.startup();
22   }
23
24   protected void tearDown() throws SystemTeardownException {
25     ProseSystem.teardown();
26   }
27
28   public void myMethod() {}
29
30   public void test_010_static_getcut() {
31     ProseSystem.getAspectManager().insert(new MethodAspect());
32     MyInterface mi = new MyClass();
33     mi.myMethod();
34     assertTrue("Interface invocation is cross-cutted", crosscutted);
35   }
36
37   public interface MyInterface {
38     public void myMethod();
39   }
40
41   public class MyClass implements MyInterface {
42     public void myMethod() {};
43   }
44
45   public class MethodAspect extends DefaultAspect {
46     public Crosscut c = new MethodCut() {
47       public void METHOD_ARGS(MyClass c) {
48         crosscutted = true;
49       }
50       protected PointCutter pointCutter() {
51         return Within.method("myMethod").AND(Executions.before());
52       }
53       protected Class JavaDoc[] potentialCrosscutClasses() {
54         return new Class JavaDoc[] { MyClass.class };
55       }
56     };
57   };
58
59 }
Popular Tags