KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > regression > jbaop248annotationoverride > AnnotationOverrideTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

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 /**
32  *
33  * @author <a HREF="mailto:kabir.khan@jboss.org">Kabir Khan</a>
34  * @version $Revision: 45977 $
35  */

36 public class AnnotationOverrideTestCase extends AOPTestWithSetup
37 {
38    public static void main(String JavaDoc[] 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 JavaDoc name)
51    {
52       super(name);
53    }
54
55    public void testAnnotationOverrides()throws Exception JavaDoc
56    {
57       checkAnnotations(Override JavaDoc.class);
58    }
59
60    public void testAnnotationIntroductions()throws Exception JavaDoc
61    {
62       checkAnnotations(Introduced.class);
63    }
64
65    private void checkAnnotations(Class JavaDoc annotation) throws Exception JavaDoc
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 JavaDoc annotation, Class JavaDoc expectedClass, int expectedValue) throws Exception JavaDoc
97    {
98       assertNotNull(annotation);
99       assertTrue(expectedClass.isAssignableFrom(annotation.getClass()));
100       
101       if (expectedClass.equals(Override JavaDoc.class))
102       {
103          assertEquals(expectedValue, ((Override JavaDoc)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