001: //$Id$
002: //=====================================================================
003: //
004: //(history at end)
005: //
006:
007: package ch.ethz.prose.crosscut;
008:
009: import junit.framework.TestCase;
010: import ch.ethz.prose.*;
011: import ch.ethz.prose.filter.*;
012:
013: /**
014: * Cross-cut static members.
015: *
016: * @version $Revision$
017: * @author Johann Gyger
018: */
019: public class StaticMembersTest extends TestCase {
020:
021: public static int value;
022:
023: protected static boolean crosscutted;
024:
025: public static int getValue() {
026: return value;
027: }
028:
029: public static void setValue(int newValue) {
030: value = newValue;
031: }
032:
033: public StaticMembersTest(String name) {
034: super (name);
035: }
036:
037: protected void setUp() throws SystemStartupException {
038: ProseSystem.startup();
039: crosscutted = false;
040: }
041:
042: protected void tearDown() throws SystemTeardownException {
043: ProseSystem.teardown();
044: }
045:
046: public void test_010_static_getcut() {
047: ProseSystem.getAspectManager().insert(new Get());
048: getValue();
049: assertTrue("Static field `value' is crosscutted by a GetCut",
050: crosscutted);
051: }
052:
053: public void test_020_static_setcut() {
054: ProseSystem.getAspectManager().insert(new Set());
055: setValue(42);
056: assertTrue("Static field `value' is crosscutted by a SetCut",
057: crosscutted);
058: }
059:
060: public void test_030_static_methodcut_entry() {
061: ProseSystem.getAspectManager().insert(new MethodBefore());
062: getValue();
063: assertTrue(
064: "Static method `getValue' is crosscutted by a MethodCut (before)",
065: crosscutted);
066: }
067:
068: public void test_040_static_methodcut_exit() {
069: ProseSystem.getAspectManager().insert(new MethodAfter());
070: getValue();
071: assertTrue(
072: "Static method `getValue' is crosscutted by a MethodCut (after)",
073: crosscutted);
074: }
075:
076: public static class Get extends DefaultAspect {
077: public Crosscut c = new GetCut() {
078: public void GET_ARGS(StaticMembersTest c, int v) {
079: crosscutted = true;
080: }
081:
082: protected PointCutter pointCutter() {
083: return Fields.named("value");
084: }
085:
086: protected Class[] potentialCrosscutClasses() {
087: return new Class[] { StaticMembersTest.class };
088: }
089: };
090: };
091:
092: public static class Set extends DefaultAspect {
093: public Crosscut c = new SetCut() {
094: public void SET_ARGS(StaticMembersTest c, int v) {
095: crosscutted = true;
096: }
097:
098: protected PointCutter pointCutter() {
099: return Fields.named("value");
100: }
101:
102: protected Class[] potentialCrosscutClasses() {
103: return new Class[] { StaticMembersTest.class };
104: }
105: };
106: };
107:
108: public static class MethodBefore extends DefaultAspect {
109: public Crosscut c = new MethodCut() {
110: public void METHOD_ARGS(StaticMembersTest c) {
111: crosscutted = true;
112: }
113:
114: protected PointCutter pointCutter() {
115: return Within.method("getValue").AND(
116: Executions.before());
117: }
118:
119: protected Class[] potentialCrosscutClasses() {
120: return new Class[] { StaticMembersTest.class };
121: }
122: };
123: };
124:
125: public static class MethodAfter extends DefaultAspect {
126: public Crosscut c = new MethodCut() {
127: public void METHOD_ARGS(StaticMembersTest c) {
128: crosscutted = true;
129: }
130:
131: protected PointCutter pointCutter() {
132: return Within.method("getValue")
133: .AND(Executions.after());
134: }
135:
136: protected Class[] potentialCrosscutClasses() {
137: return new Class[] { StaticMembersTest.class };
138: }
139: };
140: };
141: }
142:
143: //======================================================================
144: //
145: // $Log$
146: //
|