001: /**************************************************************************************
002: * Copyright (c) Jonas Bon?r, Alexandre Vasseur. All rights reserved. *
003: * http://aspectwerkz.codehaus.org *
004: * ---------------------------------------------------------------------------------- *
005: * The software in this package is published under the terms of the LGPL license *
006: * a copy of which has been included with this distribution in the license.txt file. *
007: **************************************************************************************/package test.thistarget;
008:
009: import junit.framework.TestCase;
010:
011: /**
012: * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a>
013: */
014: public class TargetTest extends TestCase {
015:
016: static String s_log = "";
017: static String s_logctorexe = "";
018:
019: public void testMethodExecutionTargetThis() {
020: // interface
021: ITarget iTarget = new TargetI();
022: s_log = "";
023: iTarget.target();
024: // this is both an interface, and an instance of TargetI
025: assertEquals(
026: "before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ",
027: s_log);
028:
029: // implementation of interface
030: TargetI targetI = new TargetI();
031: s_log = "";
032: targetI.target();
033: // this is both an interface, and an instance of TargetI
034: assertEquals(
035: "before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ",
036: s_log);
037:
038: // super class
039: SuperTarget super Target = new TargetSuper();
040: s_log = "";
041: super Target.target();
042: assertEquals(
043: "before_SuperTarget pre_SuperTarget SuperTarget post_SuperTarget after_SuperTarget ",
044: s_log);
045:
046: // super class abstract method
047: s_log = "";
048: super Target.targetAbstract();
049: assertEquals(
050: "before_SuperTargetA pre_SuperTargetA TargetSuperA post_SuperTargetA after_SuperTargetA ",
051: s_log);
052:
053: // none
054: Target target = new Target();
055: s_log = "";
056: target.target();
057: assertEquals("Target ", s_log);
058:
059: // static target
060: s_log = "";
061: TargetI.staticTarget();
062: assertEquals("", s_log);
063: }
064:
065: public void testMethodCallTargetThis() {
066: // interface
067: ITarget iTarget = new TargetI();
068: s_log = "";
069: iTarget.call();
070: // this is both an interface, and an instance of TargetI
071: // IS USING A RUNTIME CHECK with instanceof
072: assertEquals(
073: "before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ",
074: s_log);
075:
076: // implementation of interface
077: TargetI targetI = new TargetI();
078: s_log = "";
079: targetI.call();
080: // this is both an interface, and an instance of TargetI
081: assertEquals(
082: "before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ",
083: s_log);
084:
085: // super class
086: SuperTarget super Target = new TargetSuper();
087: s_log = "";
088: super Target.call();
089: assertEquals(
090: "before_SuperTarget pre_SuperTarget SuperTarget post_SuperTarget after_SuperTarget ",
091: s_log);
092:
093: // super class abstract method
094: s_log = "";
095: super Target.callAbstract();
096: assertEquals(
097: "before_SuperTargetA pre_SuperTargetA TargetSuperA post_SuperTargetA after_SuperTargetA ",
098: s_log);
099:
100: // none
101: Target target = new Target();
102: s_log = "";
103: target.call();
104: assertEquals("Target ", s_log);
105:
106: // static call
107: s_log = "";
108: TargetI.staticCall();
109: assertEquals("", s_log);
110: }
111:
112: public void testConstructorCallTargetThis() {
113: // interface
114: s_log = "";
115: ITarget iTarget = new TargetI();
116: // this is both an interface, and an instance of TargetI
117: assertEquals(
118: "before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ",
119: s_log);
120:
121: // implementation of interface
122: s_log = "";
123: TargetI targetI = new TargetI();
124: // this is both an interface, and an instance of TargetI
125: assertEquals(
126: "before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ",
127: s_log);
128:
129: // super class
130: s_log = "";
131: SuperTarget super Target = new TargetSuper();
132: assertEquals(
133: "before_SuperTarget pre_SuperTarget SuperTarget TargetSuper post_SuperTarget after_SuperTarget ",
134: s_log);
135:
136: // none
137: s_log = "";
138: Target target = new Target();
139: assertEquals("Target ", s_log);
140: }
141:
142: public void testConstructorExecutionTargetThis() {
143: // interface
144: s_logctorexe = "";
145: ITarget iTarget = new TargetI();
146: // this is both an interface, and an instance of TargetI
147: assertEquals(
148: "before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ",
149: s_logctorexe);
150:
151: // implementation of interface
152: s_logctorexe = "";
153: TargetI targetI = new TargetI();
154: // this is both an interface, and an instance of TargetI
155: assertEquals(
156: "before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ",
157: s_logctorexe);
158:
159: // super class
160: s_logctorexe = "";
161: SuperTarget super Target = new TargetSuper();
162: assertEquals(
163: "before_SuperTarget pre_SuperTarget SuperTarget post_SuperTarget after_SuperTarget before_SuperTarget pre_SuperTarget TargetSuper post_SuperTarget after_SuperTarget ",
164: s_logctorexe);
165:
166: // none
167: s_logctorexe = "";
168: Target target = new Target();
169: assertEquals("Target ", s_logctorexe);
170: }
171:
172: public void testMethodCallFromSubclassedThis() {
173: ThisI this I = new ThisI();
174: s_log = "";
175: this I.callFrom();
176: //note: first "TargetI" comes from the ctor - see ThisI impl
177: assertEquals(
178: "TargetI before_ITarget pre_ITarget TargetI post_ITarget after_ITarget ",
179: s_log);
180:
181: ThisSuper this Super = new ThisSuper();
182: s_log = "";
183: this Super.callFrom();
184: assertEquals(
185: "TargetI before_ITarget pre_ITarget TargetI post_ITarget after_ITarget ",
186: s_log);
187: }
188:
189: public static void main(String[] args) {
190: junit.textui.TestRunner.run(suite());
191: }
192:
193: public static junit.framework.Test suite() {
194: return new junit.framework.TestSuite(TargetTest.class);
195: }
196:
197: static void log(String s) {
198: s_log += s + " ";
199: }
200:
201: static void logCtorExe(String s) {
202: s_logctorexe += s + " ";
203: }
204: }
|