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.handler;
9   
10  import junit.framework.TestCase;
11  
12  /***
13   * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
14   */
15  public class HandlerTest extends TestCase {
16      private static String s_log = "";
17  
18      public HandlerTest() {
19      }
20  
21      public HandlerTest(String name) {
22          super(name);
23      }
24  
25      public void testBeforeAdvice() {
26          s_log = "";
27          try {
28              throw new HandlerTestBeforeException();
29          } catch (HandlerTestBeforeException e) {
30              log("catch ");
31          }
32          assertEquals("before catch ", s_log);
33      }
34  
35      public void testBeforeAdvice2() {
36          s_log = "";
37          try {
38              try {
39                  throw new HandlerTestBeforeException();
40              } catch (HandlerTestBeforeException e) {
41                  log("catch ");
42              } finally {
43                  log("finally ");
44              }
45          } finally {
46              log("finally2 ");
47          }
48          assertEquals("before before2 catch finally finally2 ", s_log);
49      }
50  
51      public void testBeforeAdvice3() {
52          s_log = "";
53          try {
54              throw new HandlerTestBeforeException();
55          } catch (HandlerTestBeforeException e) {
56              log("catch ");
57          } finally {
58              log("finally ");
59          }
60          assertEquals("before before3 catch finally ", s_log);
61      }
62      public static void main(String[] args) {
63          junit.textui.TestRunner.run(suite());
64      }
65  
66      public static junit.framework.Test suite() {
67          return new junit.framework.TestSuite(HandlerTest.class);
68      }
69  
70      public static void log(final String wasHere) {
71          s_log += wasHere;
72      }
73  }