1 package org.jfox.ioc.util; 2 3 import java.lang.annotation.ElementType ; 4 import java.lang.annotation.Retention ; 5 import java.lang.annotation.RetentionPolicy ; 6 import java.lang.annotation.Target ; 7 import java.lang.reflect.Method ; 8 9 import junit.framework.TestCase; 10 11 14 15 public class AnnotationsTest extends TestCase{ 16 protected void setUp() throws Exception { 17 super.setUp(); 18 } 19 20 protected void tearDown() throws Exception { 21 super.tearDown(); 22 } 23 24 public void testIsAnnoated(){ 25 Method method = null; 26 try { 27 method = TestClass.class.getMethod("testMethod",new Class []{}); 28 } 29 catch(Exception e){ 30 e.printStackTrace(); 31 assertTrue(false); 32 } 33 System.out.println(method.getAnnotations().length); 34 assertTrue(Annotations.isAnnotated(method, MyAnnotation.class)); 35 36 } 37 } 38 39 @Retention (RetentionPolicy.RUNTIME) 40 @Target ({ElementType.METHOD}) 41 @interface MyAnnotation { 42 43 } 44 45 class TestClass { 46 47 @MyAnnotation 48 public void testMethod(){ 49 50 } 51 52 } 53 54 | Popular Tags |