1 8 package test.thistarget; 9 10 import junit.framework.TestCase; 11 import org.codehaus.aspectwerkz.definition.Pointcut; 12 13 16 public class TargetReferencedAndRuntimeCheckTest extends TestCase { 17 18 private static String s_log = ""; 19 20 public static interface I0Target { 22 public void call(); 23 } 24 25 public static interface I1Target { 26 } 27 28 public static interface I2Target { 29 } 30 31 public static class ImplementsTwoTarget implements I0Target, I1Target, I2Target { 32 public void call() { 33 log("ImplementsTwoTarget"); 34 } 35 } 36 37 public static class ImplementsOneTarget implements I0Target, I1Target { 38 public void call() { 39 log("ImplementsOneTarget"); 40 } 41 } 42 43 public static class ImplementsZeroTarget implements I0Target { 44 public void call() { 45 log("ImplementsZeroTarget"); 46 } 47 } 48 49 51 public static class Aspect { 52 53 56 Pointcut referenceI1Target(I1Target myTarget) { 57 return null; 58 } 59 60 63 Pointcut referenceI2Target(I2Target myTarget) { 64 return null; 65 } 66 67 70 void before(Object t) { log("before_I1TargetAndI2Target"); 72 ThisTargetAspect.validate(t, I1Target.class); 73 ThisTargetAspect.validate(t, I2Target.class); 74 } 75 76 79 void before2(I1Target t) { 80 log("before_I1Target"); 81 ThisTargetAspect.validate(t, I1Target.class); 82 } 83 } 84 85 public void testRuntimeChecks() { 86 I0Target i1 = new ImplementsTwoTarget(); 87 s_log = ""; 88 i1.call(); 89 assertEquals("before_I1TargetAndI2Target before_I1Target ImplementsTwoTarget ", s_log); 90 91 I0Target i2 = new ImplementsOneTarget(); 92 s_log = ""; 93 i2.call(); 94 assertEquals("before_I1Target ImplementsOneTarget ", s_log); 95 96 I0Target i3 = new ImplementsZeroTarget(); 97 s_log = ""; 98 i3.call(); 99 assertEquals("ImplementsZeroTarget ", s_log); 100 } 101 102 103 104 105 106 108 public static void main(String [] args) { 109 junit.textui.TestRunner.run(suite()); 110 } 111 112 public static junit.framework.Test suite() { 113 return new junit.framework.TestSuite(TargetReferencedAndRuntimeCheckTest.class); 114 } 115 116 static void log(String s) { 117 s_log += s + " "; 118 } 119 120 121 } 122 | Popular Tags |