Source Code Cross Referenced for Class5Test.java in  » Apache-Harmony-Java-SE » java-package » java » lang » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » java package » java.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        package java.lang;
018:
019:        import java.lang.annotation.Annotation;
020:        import java.lang.annotation.Inherited;
021:        import java.lang.annotation.Retention;
022:        import java.lang.annotation.RetentionPolicy;
023:        import java.lang.reflect.AnnotatedElement;
024:        import java.util.Arrays;
025:        import java.util.List;
026:
027:        import notfound.MissingAntn;
028:
029:        import org.apache.harmony.lang.AnnotatedElementTestFrame;
030:        import org.apache.harmony.lang.AnnotatedElementTestFrame.TagAntn;
031:        import org.apache.harmony.lang.AnnotatedElementTestFrame.ValAntn;
032:
033:        /**
034:         * Test of the {@link java.lang.reflect.AnnotatedElement AnnotatedElement} 
035:         * functionality in {@link java.lang.Class java.lang.Class} class.
036:         * 
037:         * @author Alexey V. Varlamov
038:         * @version $Revision$
039:         */
040:        public class Class5Test extends AnnotatedElementTestFrame {
041:
042:            public static void main(String[] args) {
043:                junit.textui.TestRunner.run(Class5Test.class);
044:            }
045:
046:            @TagAntn
047:            interface First {
048:            }
049:
050:            protected @Override
051:            AnnotatedElement getElement1() throws Throwable {
052:                return First.class;
053:            }
054:
055:            protected @Override
056:            AnnotatedElement getElement2() throws Throwable {
057:                @TagAntn
058:                @ValAntn
059:                class Second {
060:                }
061:                return Second.class;
062:            }
063:
064:            protected @Override
065:            AnnotatedElement getElement3() throws Throwable {
066:                return Third.class;
067:            }
068:
069:            protected @Override
070:            AnnotatedElement getElement4() throws Throwable {
071:                @MissingAntn
072:                class Fourth {
073:                }
074:                return Fourth.class;
075:            }
076:
077:            protected @Override
078:            AnnotatedElement getElement5() throws Throwable {
079:                @MissingClassValAntn
080:                class X {
081:                }
082:                return X.class;
083:            }
084:
085:            protected @Override
086:            AnnotatedElement getElement6() throws Throwable {
087:                @MissingTypeAntn
088:                class X {
089:                }
090:                return X.class;
091:            }
092:
093:            /**
094:             * For Class instances, getAnnotations() must return
095:             * annotations declared + inherited from superclasses.
096:             */
097:            public void testGetAnnotationsInherited() throws Throwable {
098:                Annotation[] an = C4.class.getDeclaredAnnotations();
099:                assertNotNull("declared in C4", an);
100:                assertEquals("number of Declared Annotations in C4", 1,
101:                        an.length);
102:                assertSame("declared in C4", TagAntn.class, an[0]
103:                        .annotationType());
104:
105:                Annotation[] an2 = C4.class.getAnnotations();
106:                assertNotNull("all in C4", an2);
107:                assertEquals("number of all Annotations in C4", 3, an2.length);
108:
109:                List<Class> la = Arrays.asList(new Class[] {
110:                        an2[0].annotationType(), an2[1].annotationType(),
111:                        an2[2].annotationType() });
112:                assertTrue("1st annotation", la.contains(SuperTagAntn.class));
113:                assertTrue("2nd annotation", la.contains(TagAntn.class));
114:                assertTrue("3rd annotation", la.contains(SuperValAntn.class));
115:            }
116:
117:            /**
118:             * For Class instances, getAnnotations() 
119:             * must not return annotations inherited from superinterfaces.
120:             */
121:            public void testGetAnnotationsInherited2() throws Throwable {
122:                Annotation[] an = I3.class.getAnnotations();
123:                assertNotNull("all in I3", an);
124:                assertEquals("number of Annotations in I3", 1, an.length);
125:                assertSame("annotation of I3", TagAntn.class, an[0]
126:                        .annotationType());
127:
128:                Annotation[] an2 = CI1.class.getAnnotations();
129:                assertNotNull("all in CI1", an2);
130:                assertEquals("number of all Annotations in CI1", 1, an2.length);
131:                assertSame("annotation of CI1", ValAntn.class, an2[0]
132:                        .annotationType());
133:
134:                Annotation[] an3 = CI2.class.getAnnotations();
135:                assertNotNull("all in CI2", an3);
136:                assertEquals("number of all Annotations in CI2", 1, an3.length);
137:                assertSame("annotation of CI2", SuperValAntn.class, an3[0]
138:                        .annotationType());
139:                assertSame("annotation value of CI2", CI2.class,
140:                        ((SuperValAntn) an3[0]).value());
141:            }
142:
143:            /**
144:             * For Class instances, annotations inherited from a superclass
145:             * may be overriden by descendants. 
146:             * In this case getAnnotations() must return
147:             * annotations declared + non-overriden inherited.
148:             */
149:            public void testGetAnnotationsInheritedOverriden() throws Throwable {
150:                Annotation[] an = C6.class.getDeclaredAnnotations();
151:                assertNotNull("declared in C6", an);
152:                assertEquals("number of Declared Annotations in C6", 1,
153:                        an.length);
154:                assertSame("declared in C6", SuperValAntn.class, an[0]
155:                        .annotationType());
156:
157:                Annotation[] an2 = C6.class.getAnnotations();
158:                assertNotNull("all in C6", an2);
159:                assertEquals("number of all Annotations in C6", 2, an2.length);
160:
161:                List<Class> la = Arrays.asList(new Class[] {
162:                        an2[0].annotationType(), an2[1].annotationType(), });
163:                assertTrue("C6 1st annotation", la.contains(SuperTagAntn.class));
164:                assertTrue("C6 2rd annotation", la.contains(SuperValAntn.class));
165:
166:                Annotation[] an3 = C7.class.getAnnotations();
167:                assertNotNull("declared in C7", an3);
168:                assertEquals("number of all Annotations in C7", 2, an3.length);
169:
170:                List<Class> la3 = Arrays.asList(new Class[] {
171:                        an3[0].annotationType(), an3[1].annotationType(), });
172:                assertTrue("C7 1st annotation", la3
173:                        .contains(SuperTagAntn.class));
174:                assertTrue("C7 2rd annotation", la3
175:                        .contains(SuperValAntn.class));
176:            }
177:
178:            /**
179:             * For Class instances, isAnnotationPresent() must account for
180:             * annotations declared + inherited from superclasses.
181:             */
182:            public void testIsAnnotationPresentInherited() throws Throwable {
183:                assertTrue("case 1", C4.class
184:                        .isAnnotationPresent(SuperTagAntn.class));
185:                assertTrue("case 2", C4.class
186:                        .isAnnotationPresent(SuperValAntn.class));
187:                assertTrue("case 3", C4.class
188:                        .isAnnotationPresent(TagAntn.class));
189:                assertTrue("case 4", C6.class
190:                        .isAnnotationPresent(SuperTagAntn.class));
191:                assertTrue("case 5", C6.class
192:                        .isAnnotationPresent(SuperValAntn.class));
193:                assertTrue("case 6", C5.class
194:                        .isAnnotationPresent(SuperTagAntn.class));
195:            }
196:
197:            /**
198:             * For Class instances, isAnnotationPresent() must not account for
199:             * non-inheritable annotations from superclasses.
200:             */
201:            public void testIsAnnotationPresentInherited_Negative()
202:                    throws Throwable {
203:                assertFalse("case 1", C4.class
204:                        .isAnnotationPresent(ValAntn.class));
205:                assertFalse("case 2", C4.class.isAnnotationPresent(None.class));
206:                assertFalse("case 3", C5.class
207:                        .isAnnotationPresent(TagAntn.class));
208:                assertFalse("case 4", C6.class
209:                        .isAnnotationPresent(TagAntn.class));
210:                assertFalse("case 5", C6.class
211:                        .isAnnotationPresent(ValAntn.class));
212:                assertFalse("case 6", C5.class.isAnnotationPresent(None.class));
213:            }
214:
215:            /**
216:             * For Class instances, getAnnotation() must account for
217:             * annotations declared + inherited from superclasses.
218:             */
219:            public void testGetAnnotationInherited() throws Throwable {
220:                SuperValAntn an = C5.class.getAnnotation(SuperValAntn.class);
221:                assertNotNull(an);
222:                assertSame("value of inherited annotation", C3.class, an
223:                        .value());
224:            }
225:
226:            /**
227:             * For Class instances, annotations inherited from a superclass
228:             * may be overriden by descendants. 
229:             * In this case getAnnotation() must return latest overriden annotation.
230:             */
231:            public void testGetAnnotationInheritedOverriden() throws Throwable {
232:                SuperValAntn an = C6.class.getAnnotation(SuperValAntn.class);
233:                assertNotNull("overriden in C6", an);
234:                assertSame("value of overriden annotation in C6", C6.class, an
235:                        .value());
236:
237:                SuperValAntn an2 = C7.class.getAnnotation(SuperValAntn.class);
238:                assertNotNull("overriden in C7", an2);
239:                assertSame("value of overriden annotation in C7", C6.class, an2
240:                        .value());
241:            }
242:        }
243:
244:        @interface Third {
245:        }
246:
247:        @Inherited
248:        @Retention(RetentionPolicy.RUNTIME)
249:        @interface SuperTagAntn {
250:        }
251:
252:        @Inherited
253:        @Retention(RetentionPolicy.RUNTIME)
254:        @interface SuperValAntn {
255:            Class value();
256:        }
257:
258:        @SuperTagAntn
259:        class C1 {
260:        }
261:
262:        @ValAntn
263:        class C2 extends C1 {
264:        }
265:
266:        @SuperValAntn(C3.class)
267:        class C3 extends C2 {
268:        }
269:
270:        @TagAntn
271:        class C4 extends C3 {
272:        }
273:
274:        class C5 extends C4 {
275:        }
276:
277:        @SuperValAntn(C6.class)
278:        class C6 extends C5 {
279:        }
280:
281:        class C7 extends C6 {
282:        }
283:
284:        @SuperTagAntn
285:        interface I1 {
286:        }
287:
288:        @SuperValAntn(I2.class)
289:        interface I2 {
290:        }
291:
292:        @TagAntn
293:        interface I3 extends I1, I2 {
294:        }
295:
296:        @ValAntn
297:        class CI1 implements  I3 {
298:        }
299:
300:        @SuperValAntn(CI2.class)
301:        class CI2 extends CI1 {
302:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.