|                                                                                                              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
 12  public class StaticMembersTest extends TestCase {
 13
 14        public static int value;
 15
 16        protected static boolean crosscutted;
 17
 18        public static int getValue() {
 19          return value;
 20        }
 21
 22        public static void setValue(int newValue) {
 23          value = newValue;
 24        }
 25
 26        public StaticMembersTest(String
  name) { 27          super(name);
 28        }
 29
 30        protected void setUp() throws SystemStartupException {
 31          ProseSystem.startup();
 32          crosscutted = false;
 33        }
 34
 35        protected void tearDown() throws SystemTeardownException {
 36          ProseSystem.teardown();
 37        }
 38
 39        public void test_010_static_getcut() {
 40          ProseSystem.getAspectManager().insert(new Get());
 41          getValue();
 42          assertTrue("Static field `value' is crosscutted by a GetCut", crosscutted);
 43        }
 44
 45        public void test_020_static_setcut() {
 46          ProseSystem.getAspectManager().insert(new Set());
 47          setValue(42);
 48          assertTrue("Static field `value' is crosscutted by a SetCut", crosscutted);
 49        }
 50
 51        public void test_030_static_methodcut_entry() {
 52          ProseSystem.getAspectManager().insert(new MethodBefore());
 53          getValue();
 54          assertTrue("Static method `getValue' is crosscutted by a MethodCut (before)", crosscutted);
 55        }
 56
 57        public void test_040_static_methodcut_exit() {
 58          ProseSystem.getAspectManager().insert(new MethodAfter());
 59          getValue();
 60          assertTrue("Static method `getValue' is crosscutted by a MethodCut (after)", crosscutted);
 61        }
 62
 63        public static class Get extends DefaultAspect {
 64          public Crosscut c = new GetCut() {
 65            public void GET_ARGS(StaticMembersTest c, int v) {
 66              crosscutted = true;
 67            }
 68            protected PointCutter pointCutter() {
 69              return Fields.named("value");
 70            }
 71            protected Class
  [] potentialCrosscutClasses() { 72              return new Class
  [] { StaticMembersTest.class }; 73            }
 74          };
 75        };
 76
 77        public static class Set extends DefaultAspect {
 78          public Crosscut c = new SetCut() {
 79            public void SET_ARGS(StaticMembersTest c, int v) {
 80              crosscutted = true;
 81            }
 82            protected PointCutter pointCutter() {
 83              return Fields.named("value");
 84            }
 85            protected Class
  [] potentialCrosscutClasses() { 86              return new Class
  [] { StaticMembersTest.class }; 87            }
 88          };
 89        };
 90
 91        public static class MethodBefore extends DefaultAspect {
 92          public Crosscut c = new MethodCut() {
 93            public void METHOD_ARGS(StaticMembersTest c) {
 94              crosscutted = true;
 95            }
 96            protected PointCutter pointCutter() {
 97              return Within.method("getValue").AND(Executions.before());
 98            }
 99            protected Class
  [] potentialCrosscutClasses() { 100             return new Class
  [] { StaticMembersTest.class }; 101           }
 102         };
 103       };
 104
 105       public static class MethodAfter extends DefaultAspect {
 106         public Crosscut c = new MethodCut() {
 107           public void METHOD_ARGS(StaticMembersTest c) {
 108             crosscutted = true;
 109           }
 110           protected PointCutter pointCutter() {
 111             return Within.method("getValue").AND(Executions.after());
 112           }
 113           protected Class
  [] potentialCrosscutClasses() { 114             return new Class
  [] { StaticMembersTest.class }; 115           }
 116         };
 117       };
 118 }
                                                                                                                                                                                                             |                                                                       
 
 
 
 
 
                                                                                   Popular Tags                                                                                                                                                                                              |