KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > aj > Test


1 /**************************************************************************************
2  * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
3  * http://aspectwerkz.codehaus.org *
4  * ---------------------------------------------------------------------------------- *
5  * The software in this package is published under the terms of the LGPL license *
6  * a copy of which has been included with this distribution in the license.txt file. *
7  **************************************************************************************/

8 package test.aj;
9
10 import junit.framework.TestCase;
11
12 /**
13  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
14  */

15 public class Test extends TestCase {
16     
17     private static String JavaDoc s_logString = "";
18
19     public Test(String JavaDoc name) {
20         super(name);
21     }
22
23    public void testBefore() throws Exception JavaDoc {
24        s_logString = "";
25        before();
26        assertEquals("before before() ", s_logString);
27     }
28
29     public void testAfterFinally() throws Exception JavaDoc {
30         s_logString = "";
31         afterFinally();
32         assertEquals("afterFinally() after-finally ", s_logString);
33      }
34
35     public void testAfterReturning() throws Exception JavaDoc {
36         s_logString = "";
37         afterReturning();
38         assertEquals("afterReturning() after-returning ", s_logString);
39      }
40
41     public void testAfterThrowing() throws Exception JavaDoc {
42         s_logString = "";
43         try {
44             afterThrowing();
45         } catch (RuntimeException JavaDoc e) {
46             assertEquals("afterThrowing() after-throwing ", s_logString);
47             return;
48         }
49         fail("RuntimeException should have been catched");
50      }
51
52     public void testAround() throws Exception JavaDoc {
53         s_logString = "";
54         around();
55         assertEquals("before-around around() after-around ", s_logString);
56      }
57
58     public static void main(String JavaDoc[] args) {
59         junit.textui.TestRunner.run(suite());
60     }
61
62     public static junit.framework.Test suite() {
63         return new junit.framework.TestSuite(Test.class);
64     }
65
66     public static void log(final String JavaDoc wasHere) {
67         s_logString += wasHere;
68     }
69
70     public long around() {
71         log("around() ");
72         return 0x1L;
73     }
74
75     public int before() {
76         log("before() ");
77         return -0x1;
78     }
79
80     public String JavaDoc afterThrowing() {
81         log("afterThrowing() ");
82         throw new RuntimeException JavaDoc();
83     }
84
85     public Object JavaDoc afterReturning() {
86         log("afterReturning() ");
87         return "string";
88     }
89
90     public void afterFinally() {
91         log("afterFinally() ");
92     }
93 }
94
Popular Tags