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.constructor;
9   
10  import junit.framework.TestCase;
11  
12  /***
13   * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a>
14   */
15  public class ConstructorAdviceTest extends TestCase {
16      private static String s_logCall = "";
17  
18      private static String s_logExecution = "";
19  
20      public ConstructorAdviceTest() {
21      }
22  
23      public ConstructorAdviceTest(String name) {
24          super(name);
25      }
26  
27      public void testCallAroundAdvice() {
28          s_logCall = "";
29          TestAroundAdvice test = new TestAroundAdvice(1L, new Object(), new String[] {});
30          assertEquals("beforeCall init afterCall ", s_logCall);
31          assertNotNull(test);
32      }
33  
34      public void testCallBeforeAdvice() {
35          s_logCall = "";
36          TestBeforeAdvice test = new TestBeforeAdvice();
37          assertEquals("preCall init ", s_logCall);
38          assertNotNull(test);
39      }
40  
41      public void testCallAfterAdvice() {
42          s_logCall = "";
43          TestAfterAdvice test = new TestAfterAdvice("test");
44          assertEquals("test postCall ", s_logCall);
45          assertNotNull(test);
46      }
47  
48      public void testCallBeforeAfterAdvice() {
49          s_logCall = "";
50          TestBeforeAfterAdvice test = new TestBeforeAfterAdvice(new String[] {
51              "test"
52          });
53          assertEquals("preCall test postCall ", s_logCall);
54          assertNotNull(test);
55      }
56  
57      public void testCallReturnFalseType() {
58          s_logCall = "";
59          TestReturnFalseType test = null;
60          try {
61              test = new TestReturnFalseType();
62          } catch (ClassCastException e) {
63              return;
64          }
65          fail("this point should not have been reached a class cast exception should have been thrown");
66      }
67  
68      //    public void testExecutionAroundAdvice() {
69      //        s_logExecution = "";
70      //        TestAroundAdvice test = new TestAroundAdvice(1L, new Object(), new String[]{});
71      //        assertEquals("beforeExecution init afterExecution ", s_logExecution);
72      //        assertNotNull(test);
73      //        assertTrue(test instanceof TestAroundAdvice);
74      //    }
75      //
76      //    public void testExecutionBeforeAdvice() {
77      //        s_logExecution = "";
78      //        TestBeforeAdvice test = new TestBeforeAdvice();
79      //        assertEquals("preExecution init ", s_logExecution);
80      //        assertNotNull(test);
81      //        assertTrue(test instanceof TestBeforeAdvice);
82      //    }
83      //
84      //    public void testExecutionAfterAdvice() {
85      //        s_logExecution = "";
86      //        TestAfterAdvice test = new TestAfterAdvice("test");
87      //        assertEquals("init postExecution ", s_logExecution);
88      //        assertNotNull(test);
89      //        assertTrue(test instanceof TestAfterAdvice);
90      //    }
91      //
92      //    public void testExecutionBeforeAfterAdvice() {
93      //        s_logExecution = "";
94      //        TestBeforeAfterAdvice test = new TestBeforeAfterAdvice(new String[]{"test"});
95      //        assertEquals("preExecution init postExecution ", s_logExecution);
96      //        assertNotNull(test);
97      //        assertTrue(test instanceof TestBeforeAfterAdvice);
98      //    }
99      //
100     //    public void testExecutionReturnFalseType() {
101     //        s_logExecution = "";
102     //        TestReturnFalseType test = null;
103     //        try {
104     //            test = new TestReturnFalseType();
105     //        }
106     //        catch (ClassCastException e) {
107     //            return;
108     //        }
109     //        fail("this point should not have been reached a class cast exception should have been
110     // thrown");
111     //    }
112     public static void main(String[] args) {
113         junit.textui.TestRunner.run(suite());
114     }
115 
116     public static junit.framework.Test suite() {
117         return new junit.framework.TestSuite(ConstructorAdviceTest.class);
118     }
119 
120     public static void logCall(final String wasHere) {
121         s_logCall += wasHere;
122     }
123 
124     public static void logExecution(final String wasHere) {
125         s_logExecution += wasHere;
126     }
127 }