KickJava   Java API By Example, From Geeks To Geeks.

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


1 // $Id: ExceptionCutUserDefinedTest.java,v 1.3 2004/05/12 17:26:51 anicoara Exp $
2
// =====================================================================
3
//
4
// (history at end)
5
//
6

7 package ch.ethz.prose.crosscut;
8
9 //used packages
10
import java.io.IOException JavaDoc;
11
12 import junit.framework.*;
13 import ch.ethz.prose.DefaultAspect;
14 import ch.ethz.prose.ProseSystem;
15 import ch.ethz.prose.filter.PointCutter;
16
17 /**
18 * JUnit testcase for class XXX.
19 *
20 * @version $Revision: 1.3 $
21 * @author Andrei Popovici
22 */

23 public
24 class ExceptionCutUserDefinedTest extends TestCase {
25
26     // fixture
27
public static class MyRuntimeException extends RuntimeException JavaDoc {};
28     public static class MyException extends IOException JavaDoc {};
29     public static class MyError extends Error JavaDoc {};
30
31     // Jikes RVM doesn't allow to watch exceptions which are in the boot image.
32
// And the most common ones are...
33
public static class MySubRuntimeException extends MyRuntimeException {};
34     public static class MySubException extends MyException {};
35     public static class MySubError extends MyError {};
36     public static class MyNullPointerException extends NullPointerException JavaDoc {};
37     
38     public static class TestExtension extends DefaultAspect
39     {
40         int c1cnt=0;
41         int c2cnt=0;
42         int c3cnt=0;
43         int c4cnt=0;
44     
45         public Crosscut c1 = new ThrowCut()
46         {
47             public void THROW_ARGS(ANY x)
48             {
49                 c1cnt++;
50             }
51     
52             protected PointCutter pointCutter()
53             {
54                 return null;
55             }
56         };
57     
58         public Crosscut c2 = new ThrowCut()
59         {
60             public void THROW_ARGS(RuntimeException JavaDoc e)
61             { c2cnt++;}
62     
63             protected PointCutter pointCutter()
64             {
65                 return null;
66             }
67     
68         };
69     
70         public Crosscut c3 = new ThrowCut()
71         {
72             public void THROW_ARGS(IOException JavaDoc e)
73             { c3cnt++;}
74     
75             protected PointCutter pointCutter()
76             {
77                 return null;
78             }
79     
80         };
81     
82         public Crosscut c4 = new ThrowCut()
83         {
84             public void THROW_ARGS(Throwable JavaDoc e)
85             {c4cnt++;}
86     
87             protected PointCutter pointCutter()
88             {
89                 return null;
90             }
91     
92         };
93     }
94
95   /**
96    * Construct test with given name.
97    * @param name test name
98    */

99   public ExceptionCutUserDefinedTest(String JavaDoc name)
100   {
101     super(name);
102   }
103
104   /**
105    * Set up fixture.
106    */

107   protected
108   void setUp() throws Exception JavaDoc
109   {
110       ProseSystem.startup();
111   }
112
113     protected void tearDown() throws Exception JavaDoc
114     {
115         ProseSystem.teardown();
116     }
117
118     public void testCustomExtensionCut() throws Exception JavaDoc
119     {
120         // FIXME: w/o the follwing line problems: classes loaded dynamically are not returned by
121
Class JavaDoc c = MyRuntimeException.class;
122         c=MyException.class;
123         c=MyError.class;
124         c = MySubRuntimeException.class;
125         c = MySubException.class;
126         c = MySubError.class;
127         c = MyNullPointerException.class;
128         TestExtension x = new TestExtension();
129         ProseSystem.getAspectManager().insert(x);
130     
131         try { throw new MySubRuntimeException();} catch (MySubRuntimeException e){} // cnt1,4,2
132
try { throw new MyRuntimeException();} catch (MyRuntimeException e){} // cnt1,4,2
133
try { throw new MyNullPointerException();} catch (MyNullPointerException e){} // cnt1,4,2
134
try { throw new MyException();} catch (MyException e){} // cnt1,4,3
135
try { throw new MySubException();} catch (MySubException e){} // cnt1,4,3
136
try { throw new MyError();} catch (MyError e){} // cnt1,4
137
try { throw new MySubError();} catch (MySubError e){} // cnt1,4
138

139         ProseSystem.getAspectManager().withdraw(x);
140     
141         assertEquals("exception captured by ANY:",7,x.c1cnt);
142         assertEquals("exception captured by Runtime:",3,x.c2cnt);
143         assertEquals("exception captured by IO:",2,x.c3cnt);
144         assertEquals("exception captured by Throwable:",7,x.c4cnt);
145     }
146
147   /**
148    * Test suite.
149    * @return test instance
150    */

151   public static
152   Test suite()
153   {
154     return new TestSuite(ExceptionCutUserDefinedTest.class);
155   }
156 }
157
158
159
160 //======================================================================
161
//
162
// $Log: ExceptionCutUserDefinedTest.java,v $
163
// Revision 1.3 2004/05/12 17:26:51 anicoara
164
// Adapt Junit tests to 3.8.1 version and the new package structure
165
//
166
// Revision 1.1.1.1 2003/07/02 15:30:43 apopovic
167
// Imported from ETH Zurich
168
//
169
// Revision 1.1 2003/05/05 14:03:29 popovici
170
// renaming from runes to prose
171
//
172
// Revision 1.4 2003/04/27 13:08:55 popovici
173
// Specializers renamed to PointCutter
174
//
175
// Revision 1.3 2003/04/17 15:15:17 popovici
176
// Extension->Aspect renaming
177
//
178
// Revision 1.2 2003/04/17 12:49:43 popovici
179
// Refactoring of the crosscut package
180
// ExceptionCut renamed to ThrowCut
181
// McutSignature is now SignaturePattern
182
//
183
// Revision 1.1 2003/04/17 08:46:47 popovici
184
// Important functionality additions
185
// - Cflow specializers
186
// - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
187
// - Transactional capabilities
188
// - Total refactoring of Specializer evaluation, which permits fine-grained distinction
189
// between static and dynamic specializers.
190
// - Functionality pulled up in abstract classes
191
// - Uniformization of advice methods patterns and names
192
//
193
Popular Tags