1 8 package test; 9 10 import junit.framework.TestCase; 11 import org.codehaus.aspectwerkz.annotation.Before; 12 import org.codehaus.aspectwerkz.annotation.Around; 13 import org.codehaus.aspectwerkz.joinpoint.StaticJoinPoint; 14 import org.codehaus.aspectwerkz.transform.inlining.weaver.SerialVersionUidVisitor; 15 16 import java.io.Serializable ; 17 import java.lang.reflect.Field ; 18 19 22 public class CtorExecution extends TestCase implements Serializable { 23 24 static int s_count = 0; 25 26 public CtorExecution m_ref; 27 28 public int m_i; 30 public CtorExecution(CtorExecution ref) { 31 postInit(this); 32 } 34 35 static void postInit(CtorExecution target) { 36 ; 37 } 38 39 public CtorExecution() { 40 this(new CtorExecution((CtorExecution)null)); 42 new CtorExecution((CtorExecution)null); 43 postInit(this); 44 } 45 46 public CtorExecution(String s) { 47 super((new CtorExecution()).string(s)); 51 (new CtorExecution()).string(s); 52 } 53 54 public CtorExecution(int i) { 55 super(""+(new CtorExecution()).m_i++); 57 (new CtorExecution()).m_i++; 58 } 59 60 public String string(String s) { 61 return s; 62 } 63 64 public void testSome() { 65 s_count = 0; 66 CtorExecution me = new CtorExecution(); 67 me = new CtorExecution(me); 68 me = new CtorExecution("foo"); 69 me = new CtorExecution(2); 70 assertEquals(116, s_count); } 72 73 public void testSerialVer() throws Throwable { 74 Class x = CtorExecution.class; 75 long l = SerialVersionUidVisitor.calculateSerialVersionUID(x); 76 79 Field f = x.getDeclaredField("serialVersionUID"); 80 long uid = ((Long )f.get(null)).longValue(); 81 assertEquals(3813928159352352835L, uid); 83 } 84 85 public static class Aspect { 86 @Before("within(test.CtorExecution)") 87 void before(StaticJoinPoint sjp) { 88 s_count++; 89 } 91 92 @Around("execution(test.CtorExecution.new(..))" + 93 " || (call(test.CtorExecution.new(..)) && within(test.CtorExecution))") 94 Object around(StaticJoinPoint sjp) throws Throwable { 95 s_count++; 96 return sjp.proceed(); 98 } 99 100 } 101 102 public static void main(String [] args) { 103 junit.textui.TestRunner.run(suite()); 104 } 105 106 public static junit.framework.Test suite() { 107 return new junit.framework.TestSuite(CtorExecution.class); 108 } 109 110 } 111 | Popular Tags |