KickJava   Java API By Example, From Geeks To Geeks.

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


1 package ch.ethz.prose.crosscut;
2
3 import junit.framework.TestCase;
4 import ch.ethz.prose.*;
5 import ch.ethz.prose.filter.Fields;
6 import ch.ethz.prose.filter.PointCutter;
7
8 public class ConstructorFieldTest extends TestCase {
9
10       protected static boolean crosscutted;
11
12       public ConstructorFieldTest(String JavaDoc name) {
13         super(name);
14       }
15
16       protected void setUp() throws SystemStartupException {
17         ProseSystem.startup();
18         crosscutted = false;
19       }
20
21       protected void tearDown() throws SystemTeardownException {
22         ProseSystem.teardown();
23       }
24
25       public void test_010_empty_constructor() {
26         ProseSystem.getAspectManager().insert(new TestAspect());
27         TestClass tc = new TestClass();
28         assertTrue("Field `value' is crosscutted by a GetCut", crosscutted);
29       }
30
31       public void test_020_second_constructor() {
32         ProseSystem.getAspectManager().insert(new TestAspect());
33         TestClass tc = new TestClass(42);
34         assertTrue("Field `value' is crosscutted by a GetCut", crosscutted);
35       }
36
37       public static class TestClass {
38         int value = 10;
39         public TestClass() {};
40         public TestClass(int v) {
41           value = v;
42         }
43       }
44
45       public static class TestAspect extends DefaultAspect {
46         public Crosscut c = new SetCut() {
47           public void SET_ARGS(TestClass c, int v) {
48             crosscutted = true;
49           }
50           protected PointCutter pointCutter() {
51             return Fields.named("value");
52           }
53           protected Class JavaDoc[] potentialCrosscutClasses() {
54             return new Class JavaDoc[] { TestClass.class };
55           }
56         };
57       }
58
59 }
60
Popular Tags