001: /**************************************************************************************
002: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
003: * http://aspectwerkz.codehaus.org *
004: * ---------------------------------------------------------------------------------- *
005: * The software in this package is published under the terms of the LGPL license *
006: * a copy of which has been included with this distribution in the license.txt file. *
007: **************************************************************************************/package test.afterxxx;
008:
009: import junit.framework.TestCase;
010:
011: public class Test extends TestCase {
012: private static String s_log;
013:
014: public static void log(String msg) {
015: s_log += msg;
016: }
017:
018: public void testAll() {
019: s_log = "";
020: all();
021: assertEquals("logAround ", s_log);
022: }
023:
024: public void testAroundFinally() {
025: s_log = "";
026: aroundFinally();
027: assertEquals("logAround logAfterFinally ", s_log);
028: }
029:
030: public void testAroundFinallyReturning() {
031: s_log = "";
032: aroundFinallyReturning();
033: assertEquals("logAround logAfterReturning logAfterFinally ",
034: s_log);
035: }
036:
037: public void testAroundReturning() {
038: s_log = "";
039: aroundReturning();
040: assertEquals(
041: "logAround logAfterReturningString logAfterReturning ",
042: s_log);
043: }
044:
045: public void testAroundFinallyReturningThrowing() {
046: s_log = "";
047: try {
048: aroundFinallyReturningThrowing();
049: } catch (UnsupportedOperationException e) {
050: }
051: assertEquals("logAround logAfterThrowingRTE logAfterFinally ",
052: s_log);
053: }
054:
055: public void testAroundReturningThrowing() {
056: s_log = "";
057: try {
058: aroundReturningThrowing();
059: } catch (UnsupportedOperationException e) {
060: }
061: assertEquals("logAround logAfterThrowingRTE ", s_log);
062: }
063:
064: public void testFinally() {
065: s_log = "";
066: _finally();
067: assertEquals("logAfterFinally ", s_log);
068: }
069:
070: public void testFinallyReturning() {
071: s_log = "";
072: finallyReturning();
073: assertEquals(
074: "logAfterReturningString logAfterReturning logAfter logAfterFinally ",
075: s_log);
076: }
077:
078: public void testFinallyReturningThrowing() {
079: s_log = "";
080: try {
081: finallyReturningThrowing();
082: } catch (UnsupportedOperationException e) {
083: }
084: assertEquals("logAfterThrowingRTE logAfterFinally ", s_log);
085: }
086:
087: public void testReturning() {
088: s_log = "";
089: returning();
090: assertEquals("logAfterReturningString logAfterReturning ",
091: s_log);
092: }
093:
094: public void testReturningThrowing() {
095: s_log = "";
096: try {
097: returningThrowing();
098: } catch (Exception e) {
099: }
100: assertEquals("", s_log);
101: }
102:
103: public Test(String name) {
104: super (name);
105: }
106:
107: public static void main(String[] args) {
108: junit.textui.TestRunner.run(suite());
109: }
110:
111: public static junit.framework.Test suite() {
112: return new junit.framework.TestSuite(Test.class);
113: }
114:
115: void all() {
116: }
117:
118: void aroundFinally() {
119: }
120:
121: static Object aroundFinallyReturning() {
122: return null;
123: }
124:
125: Object aroundReturning() {
126: return "aroundReturning";
127: }
128:
129: static Object aroundFinallyReturningThrowing() {
130: throw new UnsupportedOperationException();
131: }
132:
133: Object aroundReturningThrowing() {
134: throw new UnsupportedOperationException();
135: }
136:
137: void _finally() {
138: }
139:
140: static Object finallyReturning() {
141: return "finallyReturning";
142: }
143:
144: static Object finallyReturningThrowing() {
145: throw new UnsupportedOperationException();
146: }
147:
148: Object returningThrowing() throws Exception {
149: throw new Exception();
150: }
151:
152: Object returning() {
153: return "returning";
154: }
155: }
|