KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > intercept > handler > InterceptTest


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.intercept.handler;
9
10 import junit.framework.TestCase;
11 import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
12 import org.codehaus.aspectwerkz.intercept.BeforeAdvice;
13 import org.codehaus.aspectwerkz.intercept.Advisable;
14
15 /**
16  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
17  */

18 public class InterceptTest extends TestCase {
19     private static String JavaDoc LOG = "";
20
21     public static void log(String JavaDoc msg) {
22         LOG += msg;
23     }
24
25     public void testIsAdvisable() {
26         assertTrue(this instanceof Advisable);
27     }
28
29     public void testAddBefore() {
30         LOG = "";
31         adviseWithBefore();
32         assertEquals("adviseWithBefore ", LOG);
33
34         ((Advisable) this).aw_addAdvice(
35                 "handler(java.lang.IllegalArgumentException)",
36                 new BeforeAdvice() {
37                     public void invoke(JoinPoint jp) throws Throwable JavaDoc {
38                         InterceptTest.log("before_catch_block ");
39                     }
40                 }
41         );
42
43         LOG = "";
44         adviseWithBefore();
45         assertEquals("before_catch_block adviseWithBefore ", LOG);
46     }
47
48     public static void main(String JavaDoc[] args) {
49         junit.textui.TestRunner.run(suite());
50     }
51
52     public static junit.framework.Test suite() {
53         return new junit.framework.TestSuite(InterceptTest.class);
54     }
55
56     public void adviseWithBefore() {
57         try {
58             throw new IllegalArgumentException JavaDoc("noop");
59         } catch (IllegalArgumentException JavaDoc e) {
60             log("adviseWithBefore ");
61         }
62     }
63 }
64
Popular Tags