01: /**************************************************************************************
02: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
03: * http://aspectwerkz.codehaus.org *
04: * ---------------------------------------------------------------------------------- *
05: * The software in this package is published under the terms of the LGPL license *
06: * a copy of which has been included with this distribution in the license.txt file. *
07: **************************************************************************************/package test.aj;
08:
09: import junit.framework.TestCase;
10:
11: /**
12: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
13: */
14: public class Test extends TestCase {
15:
16: private static String s_logString = "";
17:
18: public Test(String name) {
19: super (name);
20: }
21:
22: public void testBefore() throws Exception {
23: s_logString = "";
24: before();
25: assertEquals("before before() ", s_logString);
26: }
27:
28: public void testAfterFinally() throws Exception {
29: s_logString = "";
30: afterFinally();
31: assertEquals("afterFinally() after-finally ", s_logString);
32: }
33:
34: public void testAfterReturning() throws Exception {
35: s_logString = "";
36: afterReturning();
37: assertEquals("afterReturning() after-returning ", s_logString);
38: }
39:
40: public void testAfterThrowing() throws Exception {
41: s_logString = "";
42: try {
43: afterThrowing();
44: } catch (RuntimeException e) {
45: assertEquals("afterThrowing() after-throwing ", s_logString);
46: return;
47: }
48: fail("RuntimeException should have been catched");
49: }
50:
51: public void testAround() throws Exception {
52: s_logString = "";
53: around();
54: assertEquals("before-around around() after-around ",
55: s_logString);
56: }
57:
58: public static void main(String[] 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 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 afterThrowing() {
81: log("afterThrowing() ");
82: throw new RuntimeException();
83: }
84:
85: public Object afterReturning() {
86: log("afterReturning() ");
87: return "string";
88: }
89:
90: public void afterFinally() {
91: log("afterFinally() ");
92: }
93: }
|