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.intercept.handler;
08:
09: import junit.framework.TestCase;
10: import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
11: import org.codehaus.aspectwerkz.intercept.BeforeAdvice;
12: import org.codehaus.aspectwerkz.intercept.Advisable;
13:
14: /**
15: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
16: */
17: public class InterceptTest extends TestCase {
18: private static String LOG = "";
19:
20: public static void log(String msg) {
21: LOG += msg;
22: }
23:
24: public void testIsAdvisable() {
25: assertTrue(this instanceof Advisable);
26: }
27:
28: public void testAddBefore() {
29: LOG = "";
30: adviseWithBefore();
31: assertEquals("adviseWithBefore ", LOG);
32:
33: ((Advisable) this ).aw_addAdvice(
34: "handler(java.lang.IllegalArgumentException)",
35: new BeforeAdvice() {
36: public void invoke(JoinPoint jp) throws Throwable {
37: InterceptTest.log("before_catch_block ");
38: }
39: });
40:
41: LOG = "";
42: adviseWithBefore();
43: assertEquals("before_catch_block adviseWithBefore ", LOG);
44: }
45:
46: public static void main(String[] args) {
47: junit.textui.TestRunner.run(suite());
48: }
49:
50: public static junit.framework.Test suite() {
51: return new junit.framework.TestSuite(InterceptTest.class);
52: }
53:
54: public void adviseWithBefore() {
55: try {
56: throw new IllegalArgumentException("noop");
57: } catch (IllegalArgumentException e) {
58: log("adviseWithBefore ");
59: }
60: }
61: }
|