1 22 package org.jboss.test.aop.regression.jbaop248annotationoverride; 23 24 import org.jboss.test.aop.AOPTestWithSetup; 25 26 import junit.framework.Test; 27 import junit.framework.TestSuite; 28 import junit.textui.TestRunner; 29 30 31 36 public class AnnotationOverrideTestCase extends AOPTestWithSetup 37 { 38 public static void main(String [] args) 39 { 40 TestRunner.run(suite()); 41 } 42 43 public static Test suite() 44 { 45 TestSuite suite = new TestSuite("AnnotationOverrideTestCase"); 46 suite.addTestSuite(AnnotationOverrideTestCase.class); 47 return suite; 48 } 49 50 public AnnotationOverrideTestCase(String name) 51 { 52 super(name); 53 } 54 55 public void testAnnotationOverrides()throws Exception 56 { 57 checkAnnotations(Override .class); 58 } 59 60 public void testAnnotationIntroductions()throws Exception 61 { 62 checkAnnotations(Introduced.class); 63 } 64 65 private void checkAnnotations(Class annotation) throws Exception 66 { 67 TestInterceptor.annotation = annotation; 68 69 TestInterceptor.reset(); 70 POJO pojo = new POJO(); 71 checkValue(TestInterceptor.classAnnotation, TestInterceptor.annotation, 1); 72 checkValue(TestInterceptor.joinpointAnnotation, TestInterceptor.annotation, 10); 73 74 TestInterceptor.reset(); 75 pojo.field = 6; 76 checkValue(TestInterceptor.classAnnotation, TestInterceptor.annotation, 1); 77 checkValue(TestInterceptor.joinpointAnnotation, TestInterceptor.annotation, 20); 78 79 TestInterceptor.reset(); 80 assertEquals(6, pojo.field); 81 checkValue(TestInterceptor.classAnnotation, TestInterceptor.annotation, 1); 82 checkValue(TestInterceptor.joinpointAnnotation, TestInterceptor.annotation, 20); 83 84 TestInterceptor.reset(); 85 pojo.method(); 86 checkValue(TestInterceptor.classAnnotation, TestInterceptor.annotation, 1); 87 checkValue(TestInterceptor.joinpointAnnotation, TestInterceptor.annotation, 30); 88 89 TestInterceptor.reset(); 90 pojo.notAnnotatedMethod(); 91 checkValue(TestInterceptor.classAnnotation, TestInterceptor.annotation, 1); 92 assertNull(TestInterceptor.joinpointAnnotation); 93 94 } 95 96 private void checkValue(Object annotation, Class expectedClass, int expectedValue) throws Exception 97 { 98 assertNotNull(annotation); 99 assertTrue(expectedClass.isAssignableFrom(annotation.getClass())); 100 101 if (expectedClass.equals(Override .class)) 102 { 103 assertEquals(expectedValue, ((Override )annotation).value()); 104 } 105 else if (expectedClass.equals(Introduced.class)) 106 { 107 assertEquals(expectedValue, ((Introduced)annotation).value()); 108 } 109 else 110 { 111 fail("Should not happen"); 112 } 113 114 } 115 } 116 | Popular Tags |