KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > thistarget > TargetTest


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.thistarget;
9
10 import junit.framework.TestCase;
11
12 /**
13  * @author <a HREF="mailto:alex@gnilux.com">Alexandre Vasseur</a>
14  */

15 public class TargetTest extends TestCase {
16
17     static String JavaDoc s_log = "";
18     static String JavaDoc s_logctorexe = "";
19
20     public void testMethodExecutionTargetThis() {
21         // interface
22
ITarget iTarget = new TargetI();
23         s_log = "";
24         iTarget.target();
25         // this is both an interface, and an instance of TargetI
26
assertEquals("before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ", s_log);
27
28         // implementation of interface
29
TargetI targetI = new TargetI();
30         s_log = "";
31         targetI.target();
32         // this is both an interface, and an instance of TargetI
33
assertEquals("before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ", s_log);
34
35         // super class
36
SuperTarget superTarget = new TargetSuper();
37         s_log = "";
38         superTarget.target();
39         assertEquals("before_SuperTarget pre_SuperTarget SuperTarget post_SuperTarget after_SuperTarget ", s_log);
40
41         // super class abstract method
42
s_log = "";
43         superTarget.targetAbstract();
44         assertEquals("before_SuperTargetA pre_SuperTargetA TargetSuperA post_SuperTargetA after_SuperTargetA ", s_log);
45
46         // none
47
Target target = new Target();
48         s_log = "";
49         target.target();
50         assertEquals("Target ", s_log);
51
52         // static target
53
s_log = "";
54         TargetI.staticTarget();
55         assertEquals("", s_log);
56     }
57
58     public void testMethodCallTargetThis() {
59         // interface
60
ITarget iTarget = new TargetI();
61         s_log = "";
62         iTarget.call();
63         // this is both an interface, and an instance of TargetI
64
// IS USING A RUNTIME CHECK with instanceof
65
assertEquals("before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ", s_log);
66
67         // implementation of interface
68
TargetI targetI = new TargetI();
69         s_log = "";
70         targetI.call();
71         // this is both an interface, and an instance of TargetI
72
assertEquals("before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ", s_log);
73
74         // super class
75
SuperTarget superTarget = new TargetSuper();
76         s_log = "";
77         superTarget.call();
78         assertEquals("before_SuperTarget pre_SuperTarget SuperTarget post_SuperTarget after_SuperTarget ", s_log);
79
80         // super class abstract method
81
s_log = "";
82         superTarget.callAbstract();
83         assertEquals("before_SuperTargetA pre_SuperTargetA TargetSuperA post_SuperTargetA after_SuperTargetA ", s_log);
84
85         // none
86
Target target = new Target();
87         s_log = "";
88         target.call();
89         assertEquals("Target ", s_log);
90
91         // static call
92
s_log = "";
93         TargetI.staticCall();
94         assertEquals("", s_log);
95     }
96
97
98     public void testConstructorCallTargetThis() {
99         // interface
100
s_log = "";
101         ITarget iTarget = new TargetI();
102         // this is both an interface, and an instance of TargetI
103
assertEquals("before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ", s_log);
104
105         // implementation of interface
106
s_log = "";
107         TargetI targetI = new TargetI();
108         // this is both an interface, and an instance of TargetI
109
assertEquals("before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ", s_log);
110
111         // super class
112
s_log = "";
113         SuperTarget superTarget = new TargetSuper();
114         assertEquals("before_SuperTarget pre_SuperTarget SuperTarget TargetSuper post_SuperTarget after_SuperTarget ", s_log);
115
116         // none
117
s_log = "";
118         Target target = new Target();
119         assertEquals("Target ", s_log);
120     }
121
122     public void testConstructorExecutionTargetThis() {
123         // interface
124
s_logctorexe = "";
125         ITarget iTarget = new TargetI();
126         // this is both an interface, and an instance of TargetI
127
assertEquals("before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ", s_logctorexe);
128
129         // implementation of interface
130
s_logctorexe = "";
131         TargetI targetI = new TargetI();
132         // this is both an interface, and an instance of TargetI
133
assertEquals("before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ", s_logctorexe);
134
135         // super class
136
s_logctorexe = "";
137         SuperTarget superTarget = new TargetSuper();
138         assertEquals("before_SuperTarget pre_SuperTarget SuperTarget post_SuperTarget after_SuperTarget before_SuperTarget pre_SuperTarget TargetSuper post_SuperTarget after_SuperTarget ", s_logctorexe);
139
140         // none
141
s_logctorexe = "";
142         Target target = new Target();
143         assertEquals("Target ", s_logctorexe);
144     }
145
146     public void testMethodCallFromSubclassedThis() {
147         ThisI thisI = new ThisI();
148         s_log = "";
149         thisI.callFrom();
150         //note: first "TargetI" comes from the ctor - see ThisI impl
151
assertEquals("TargetI before_ITarget pre_ITarget TargetI post_ITarget after_ITarget ", s_log);
152
153         ThisSuper thisSuper = new ThisSuper();
154         s_log = "";
155         thisSuper.callFrom();
156         assertEquals("TargetI before_ITarget pre_ITarget TargetI post_ITarget after_ITarget ", s_log);
157     }
158
159
160     public static void main(String JavaDoc[] args) {
161         junit.textui.TestRunner.run(suite());
162     }
163
164     public static junit.framework.Test suite() {
165         return new junit.framework.TestSuite(TargetTest.class);
166     }
167
168     static void log(String JavaDoc s) {
169         s_log += s + " ";
170     }
171
172     static void logCtorExe(String JavaDoc s) {
173         s_logctorexe += s + " ";
174     }
175 }
176
Popular Tags