Source Code Cross Referenced for AnnotationsTest.java in  » Ajax » GWT » com » google » gwt » core » ext » typeinfo » 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 » Ajax » GWT » com.google.gwt.core.ext.typeinfo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2007 Google Inc.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005:         * use this file except in compliance with the License. You may obtain a copy of
006:         * the License at
007:         * 
008:         * http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013:         * License for the specific language governing permissions and limitations under
014:         * the License.
015:         */
016:        package com.google.gwt.core.ext.typeinfo;
017:
018:        import junit.framework.TestCase;
019:
020:        import java.lang.annotation.Annotation;
021:        import java.lang.annotation.ElementType;
022:        import java.lang.annotation.Inherited;
023:        import java.lang.annotation.Retention;
024:        import java.lang.annotation.RetentionPolicy;
025:        import java.lang.annotation.Target;
026:        import java.util.HashMap;
027:        import java.util.Map;
028:
029:        /**
030:         * Test cases for the {@link Annotations} class.
031:         */
032:        public class AnnotationsTest extends TestCase {
033:
034:            @TestAnnotation1("1")
035:            private static class AnnotatedClass1 {
036:            }
037:
038:            @TestAnnotation2("2")
039:            private static class AnnotatedClass2 extends AnnotatedClass1 {
040:            }
041:
042:            @Inherited
043:            @Retention(RetentionPolicy.RUNTIME)
044:            @Target(ElementType.TYPE)
045:            private @interface TestAnnotation1 {
046:                String value();
047:            }
048:
049:            @Retention(RetentionPolicy.RUNTIME)
050:            @Target(ElementType.TYPE)
051:            private @interface TestAnnotation2 {
052:                String value();
053:            }
054:
055:            @Inherited
056:            @Retention(RetentionPolicy.RUNTIME)
057:            @Target(ElementType.TYPE)
058:            private @interface UnusedAnnotation {
059:                String value();
060:            }
061:
062:            /**
063:             * Initializes an {@link Annotations} instance from a given {@link Class}.
064:             */
065:            private static Annotations initializeAnnotationsFromClass(
066:                    Class<?> annotatedClass, Annotations parent) {
067:                Annotation[] jAnnotations = annotatedClass
068:                        .getDeclaredAnnotations();
069:                Annotations annotations = new Annotations();
070:                for (Annotation annotation : jAnnotations) {
071:                    annotations.addAnnotation(annotation.annotationType(),
072:                            annotation);
073:                }
074:
075:                if (parent != null) {
076:                    annotations.setParent(parent);
077:                }
078:
079:                return annotations;
080:            }
081:
082:            /**
083:             * Test method for
084:             * {@link com.google.gwt.core.ext.typeinfo.Annotations#addAnnotations(java.util.Map)}.
085:             */
086:            public void testAddAnnotations() {
087:                Annotations annotations = new Annotations();
088:                Map<Class<? extends Annotation>, Annotation> entries = new HashMap<Class<? extends Annotation>, Annotation>();
089:                entries.put(TestAnnotation1.class, AnnotatedClass1.class
090:                        .getAnnotation(TestAnnotation1.class));
091:                annotations.addAnnotations(entries);
092:                assertNotNull(annotations.getAnnotation(TestAnnotation1.class));
093:            }
094:
095:            /**
096:             * Test method for
097:             * {@link com.google.gwt.core.ext.typeinfo.Annotations#getAnnotation(java.lang.Class)}.
098:             * 
099:             * case 1: annotation is a declared case 2: annotation is inherited case 3:
100:             * annotation is not found
101:             */
102:            public void testGetAnnotationDeclared() {
103:                Annotations annotations = initializeAnnotationsFromClass(
104:                        AnnotatedClass1.class, null);
105:                assertNotNull(annotations.getAnnotation(TestAnnotation1.class));
106:                assertNull(annotations.getAnnotation(UnusedAnnotation.class));
107:            }
108:
109:            /**
110:             * Test method for
111:             * {@link com.google.gwt.core.ext.typeinfo.Annotations#getAnnotation(java.lang.Class)}.
112:             * 
113:             * case 1: annotation is a declared case 2: annotation is inherited case 3:
114:             * annotation is not found
115:             */
116:            public void testGetAnnotationInherited() {
117:                Annotations annotations1 = initializeAnnotationsFromClass(
118:                        AnnotatedClass1.class, null);
119:                Annotations annotations2 = initializeAnnotationsFromClass(
120:                        AnnotatedClass2.class, annotations1);
121:
122:                assertNotNull(annotations2.getAnnotation(TestAnnotation1.class));
123:                assertNull(annotations2.getAnnotation(UnusedAnnotation.class));
124:            }
125:
126:            /**
127:             * Test method for
128:             * {@link com.google.gwt.core.ext.typeinfo.Annotations#getAnnotations()}.
129:             */
130:            public void testGetAnnotations() {
131:                Annotations annotations1 = initializeAnnotationsFromClass(
132:                        AnnotatedClass1.class, null);
133:                Annotations annotations2 = initializeAnnotationsFromClass(
134:                        AnnotatedClass2.class, annotations1);
135:
136:                assertEquals(2, annotations2.getAnnotations().length);
137:            }
138:
139:            /**
140:             * Test method for
141:             * {@link com.google.gwt.core.ext.typeinfo.Annotations#getDeclaredAnnotations()}.
142:             */
143:            public void testGetDeclaredAnnotations() {
144:                Annotations annotations1 = initializeAnnotationsFromClass(
145:                        AnnotatedClass1.class, null);
146:                Annotations annotations2 = initializeAnnotationsFromClass(
147:                        AnnotatedClass2.class, annotations1);
148:
149:                assertEquals(1, annotations2.getDeclaredAnnotations().length);
150:                assertEquals(1, annotations1.getDeclaredAnnotations().length);
151:            }
152:
153:            /**
154:             * Test method for
155:             * {@link com.google.gwt.core.ext.typeinfo.Annotations#isAnnotationPresent(java.lang.Class)}.
156:             */
157:            public void testIsAnnotationPresent() {
158:                Annotations annotations1 = initializeAnnotationsFromClass(
159:                        AnnotatedClass1.class, null);
160:                Annotations annotations2 = initializeAnnotationsFromClass(
161:                        AnnotatedClass2.class, annotations1);
162:
163:                assertTrue(annotations2
164:                        .isAnnotationPresent(TestAnnotation1.class));
165:                assertTrue(annotations2
166:                        .isAnnotationPresent(TestAnnotation2.class));
167:                assertFalse(annotations2
168:                        .isAnnotationPresent(UnusedAnnotation.class));
169:            }
170:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.