1 8 package test.thistarget; 9 10 import junit.framework.TestCase; 11 12 15 public class TargetTest extends TestCase { 16 17 static String s_log = ""; 18 static String s_logctorexe = ""; 19 20 public void testMethodExecutionTargetThis() { 21 ITarget iTarget = new TargetI(); 23 s_log = ""; 24 iTarget.target(); 25 assertEquals("before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ", s_log); 27 28 TargetI targetI = new TargetI(); 30 s_log = ""; 31 targetI.target(); 32 assertEquals("before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ", s_log); 34 35 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 s_log = ""; 43 superTarget.targetAbstract(); 44 assertEquals("before_SuperTargetA pre_SuperTargetA TargetSuperA post_SuperTargetA after_SuperTargetA ", s_log); 45 46 Target target = new Target(); 48 s_log = ""; 49 target.target(); 50 assertEquals("Target ", s_log); 51 52 s_log = ""; 54 TargetI.staticTarget(); 55 assertEquals("", s_log); 56 } 57 58 public void testMethodCallTargetThis() { 59 ITarget iTarget = new TargetI(); 61 s_log = ""; 62 iTarget.call(); 63 assertEquals("before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ", s_log); 66 67 TargetI targetI = new TargetI(); 69 s_log = ""; 70 targetI.call(); 71 assertEquals("before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ", s_log); 73 74 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 s_log = ""; 82 superTarget.callAbstract(); 83 assertEquals("before_SuperTargetA pre_SuperTargetA TargetSuperA post_SuperTargetA after_SuperTargetA ", s_log); 84 85 Target target = new Target(); 87 s_log = ""; 88 target.call(); 89 assertEquals("Target ", s_log); 90 91 s_log = ""; 93 TargetI.staticCall(); 94 assertEquals("", s_log); 95 } 96 97 98 public void testConstructorCallTargetThis() { 99 s_log = ""; 101 ITarget iTarget = new TargetI(); 102 assertEquals("before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ", s_log); 104 105 s_log = ""; 107 TargetI targetI = new TargetI(); 108 assertEquals("before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ", s_log); 110 111 s_log = ""; 113 SuperTarget superTarget = new TargetSuper(); 114 assertEquals("before_SuperTarget pre_SuperTarget SuperTarget TargetSuper post_SuperTarget after_SuperTarget ", s_log); 115 116 s_log = ""; 118 Target target = new Target(); 119 assertEquals("Target ", s_log); 120 } 121 122 public void testConstructorExecutionTargetThis() { 123 s_logctorexe = ""; 125 ITarget iTarget = new TargetI(); 126 assertEquals("before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ", s_logctorexe); 128 129 s_logctorexe = ""; 131 TargetI targetI = new TargetI(); 132 assertEquals("before_ITarget before_TargetI pre_ITarget pre_TargetI TargetI post_TargetI post_ITarget after_TargetI after_ITarget ", s_logctorexe); 134 135 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 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 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 [] 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 s) { 169 s_log += s + " "; 170 } 171 172 static void logCtorExe(String s) { 173 s_logctorexe += s + " "; 174 } 175 } 176 | Popular Tags |