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.afterxxx;
9   
10  import junit.framework.TestCase;
11  
12  /***
13   * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
14   */
15  public class TestBinding extends TestCase {
16  
17      private static String s_log;
18  
19      public void testReturnInt() {
20          s_log = "";
21          returnInt(1);
22          assertEquals("afterReturningInt 2", s_log);
23      }
24  
25      public void testReturnString() {
26          s_log = "";
27          returnString("hello");
28          assertEquals("afterReturningString hellohello", s_log);
29      }
30  
31      public void testThrowing() {
32          s_log = "";
33          try {
34              throwChecked();
35          } catch (Throwable t) {
36              //System.out.println(s_log);
37              assertEquals(
38                      "afterThrowingExact java.lang.ClassNotFoundException afterThrowingParentClass java.lang.ClassNotFoundException",
39                      s_log
40              );
41              return;
42          }
43          fail("should have encounter an exception");
44      }
45  
46      //-- Test methods
47      public int returnInt(int i) {
48          return 2 * i;
49      }
50  
51      public String returnString(String s) {
52          return s + s;
53      }
54  
55      public void throwChecked() throws ClassNotFoundException {
56          throw new ClassNotFoundException("checked exception");
57      }
58  
59      //-- JUnit
60      public static void log(String msg) {
61          s_log += msg;
62      }
63  
64      public static void main(String[] args) {
65          junit.textui.TestRunner.run(suite());
66      }
67  
68      public static junit.framework.Test suite() {
69          return new junit.framework.TestSuite(TestBinding.class);
70      }
71  }