1 8 package test.staticinitialization; 9 10 import org.codehaus.aspectwerkz.expression.ExpressionContext; 11 import org.codehaus.aspectwerkz.expression.ExpressionInfo; 12 import org.codehaus.aspectwerkz.expression.ExpressionNamespace; 13 import org.codehaus.aspectwerkz.expression.PointcutType; 14 import org.codehaus.aspectwerkz.reflect.ClassInfo; 15 import org.codehaus.aspectwerkz.reflect.MethodInfo; 16 import org.codehaus.aspectwerkz.reflect.impl.java.JavaClassInfo; 17 18 import junit.framework.TestCase; 19 import test.CallerSideAdviceTest; 20 21 22 27 public class StaticInitializationExpressionTest extends TestCase { 28 private static final String NAMESPACE = "TESTING"; 29 30 static { 31 Object some = new Object (); 32 } 33 34 public void testStaticInitializerExpression() { 35 ClassInfo declaringType = JavaClassInfo.getClassInfo(StaticInitializationExpressionTest.class); 36 37 assertTrue("should found <clinit>", declaringType.hasStaticInitializer()); 38 39 assertTrue( 40 new ExpressionInfo( 41 "staticinitialization(test.staticinitialization.StaticInitializationExpressionTest)", 42 NAMESPACE).getExpression().match( 43 new ExpressionContext(PointcutType.STATIC_INITIALIZATION, declaringType.staticInitializer(), null)) 44 ); 45 46 47 assertTrue( 48 new ExpressionInfo( 49 "staticinitialization(test.*.*) && within(test.staticinitialization.StaticInitializationExpressionTest)", 50 NAMESPACE).getExpression().match( 51 new ExpressionContext(PointcutType.STATIC_INITIALIZATION, declaringType.staticInitializer(), declaringType)) 52 ); 53 54 assertTrue( 55 new ExpressionInfo( 56 "staticinitialization(test.staticinitialization.StaticInitializationExpressionTest)", 57 NAMESPACE).getAdvisedClassFilterExpression().match( 58 new ExpressionContext(PointcutType.STATIC_INITIALIZATION, null, declaringType)) 59 ); 60 61 assertTrue( 62 new ExpressionInfo( 63 "staticinitialization(test.staticinitialization.StaticInitializationExpressionTest)", 64 NAMESPACE).getAdvisedClassFilterExpression().match( 65 new ExpressionContext(PointcutType.STATIC_INITIALIZATION, null, declaringType.staticInitializer())) 66 ); 67 } 68 69 public static void main(String [] args) { 70 junit.textui.TestRunner.run(suite()); 71 } 72 73 public static junit.framework.Test suite() { 74 return new junit.framework.TestSuite(StaticInitializationExpressionTest.class); 75 } 76 } 77 | Popular Tags |