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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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 }