KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > ioc > util > AnnotationsTest


1 package org.jfox.ioc.util;
2
3 import java.lang.annotation.ElementType JavaDoc;
4 import java.lang.annotation.Retention JavaDoc;
5 import java.lang.annotation.RetentionPolicy JavaDoc;
6 import java.lang.annotation.Target JavaDoc;
7 import java.lang.reflect.Method JavaDoc;
8
9 import junit.framework.TestCase;
10
11 /**
12  * @author <a HREF="mailto:yy.young@gmail.com">Young Yang</a>
13  */

14
15 public class AnnotationsTest extends TestCase{
16     protected void setUp() throws Exception JavaDoc {
17         super.setUp();
18     }
19
20     protected void tearDown() throws Exception JavaDoc {
21         super.tearDown();
22     }
23
24     public void testIsAnnoated(){
25         Method JavaDoc method = null;
26         try {
27             method = TestClass.class.getMethod("testMethod",new Class JavaDoc[]{});
28         }
29         catch(Exception JavaDoc 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 JavaDoc(RetentionPolicy.RUNTIME)
40 @Target JavaDoc({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