Source Code Cross Referenced for ConstructorTest.java in  » Apache-Harmony-Java-SE » java-package » java » lang » reflect » 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.reflect 
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:
018:        /**
019:         * @author Serguei S.Zapreyev
020:         * @version $Revision$
021:         * 
022:         * This MethodTest class ("Software") is furnished under license and may only be
023:         * used or copied in accordance with the terms of that license.
024:         *  
025:         */package java.lang.reflect;
026:
027:        import junit.framework.TestCase;
028:
029:        /*
030:         * Created on 01.28.2006
031:         */
032:
033:        @SuppressWarnings(value={"all"})
034:        public class ConstructorTest extends TestCase {
035:
036:            /**
037:             *  
038:             */
039:            public void test_equals_Obj() {
040:                class X {
041:                    public X() {
042:                        return;
043:                    }
044:                }
045:                class Y {
046:                    public Y() {
047:                        return;
048:                    }
049:                }
050:                try {
051:                    Constructor m1 = X.class
052:                            .getDeclaredConstructor(new Class[] { java.lang.reflect.ConstructorTest.class });
053:                    Constructor m2 = Y.class
054:                            .getDeclaredConstructor(new Class[] { java.lang.reflect.ConstructorTest.class });
055:                    assertTrue(
056:                            "Error1: lack of coincidence of the equal constructors is detected",
057:                            m1.equals(m1));
058:                    assertTrue(
059:                            "Error2: coincidence of the unequal constructors is detected",
060:                            !m1.equals(m2));
061:                } catch (NoSuchMethodException e) {
062:                    fail("Error3: unfound constructor" + e.toString());
063:                }
064:            }
065:
066:            /**
067:             *  
068:             */
069:            public void test_getDeclaringClass_V() {
070:                class X {
071:                    public X() {
072:                        return;
073:                    }
074:                }
075:                new X();
076:                try {
077:                    Constructor m = X.class
078:                            .getDeclaredConstructor(new Class[] { java.lang.reflect.ConstructorTest.class });
079:                    assertTrue("Error1", m.getDeclaringClass().getName()
080:                            .equals("java.lang.reflect.ConstructorTest$2X"));
081:                } catch (NoSuchMethodException _) {
082:                    fail("Error2");
083:                }
084:            }
085:
086:            /**
087:             *  
088:             */
089:            public void test_getExceptionTypes_V() {
090:                class X {
091:                    class Y extends Throwable {
092:                        private static final long serialVersionUID = 0L;
093:                    };
094:
095:                    public X() throws Throwable, Y {
096:                        return;
097:                    }
098:
099:                    public X(Y a1) {
100:                        return;
101:                    }
102:                }
103:                try {
104:                    Constructor m = X.class
105:                            .getDeclaredConstructor(new Class[] { java.lang.reflect.ConstructorTest.class });
106:                    assertTrue(
107:                            "Error1",
108:                            (m.getExceptionTypes()[0].getName().equals(
109:                                    "java.lang.reflect.ConstructorTest$3X$Y") || m
110:                                    .getExceptionTypes()[0].getName().equals(
111:                                    "java.lang.Throwable"))
112:                                    && (m.getExceptionTypes()[1]
113:                                            .getName()
114:                                            .equals(
115:                                                    "java.lang.reflect.ConstructorTest$3X$Y") || m
116:                                            .getExceptionTypes()[1].getName()
117:                                            .equals("java.lang.Throwable")));
118:                } catch (Exception e) {
119:                    fail("Error2" + e.toString());
120:                }
121:                try {
122:                    Constructor m = X.class
123:                            .getDeclaredConstructor(new Class[] {
124:                                    java.lang.reflect.ConstructorTest.class,
125:                                    X.Y.class });
126:                    assertTrue("Error3", m.getExceptionTypes().length == 0);
127:                } catch (Exception e) {
128:                    fail("Error4" + e.toString());
129:                }
130:            }
131:
132:            /**
133:             *  
134:             */
135:            public void test_getModifiers_V() {
136:                class X {
137:                    public X() {
138:                        return;
139:                    }
140:                }
141:                new X();
142:                try {
143:                    Constructor m = X.class
144:                            .getDeclaredConstructor(new Class[] { java.lang.reflect.ConstructorTest.class });
145:                    assertTrue("Error1", java.lang.reflect.Modifier.isPublic(m
146:                            .getModifiers()));
147:                } catch (Exception e) {
148:                    fail("Error2" + e.toString());
149:                }
150:            }
151:
152:            /**
153:             *  
154:             */
155:            public void test_getName_V() {
156:                class X {
157:                    public X() {
158:                        return;
159:                    }
160:
161:                    public X(X a1) {
162:                        return;
163:                    }
164:                }
165:                new X();
166:                Constructor af[] = X.class.getDeclaredConstructors();
167:                assertEquals("num of ctors", 2, af.length);
168:                for (int i = 0; i < af.length; i++) {
169:                    assertEquals("name",
170:                            "java.lang.reflect.ConstructorTest$5X", af[i]
171:                                    .getName());
172:                }
173:            }
174:
175:            /**
176:             *  
177:             */
178:            public void test_getParameterTypes_V() {
179:                class X {
180:                    public X(boolean a1, byte a2, char a3, double a4, float a5,
181:                            int a6, long a7, short a8, X a9, ConstructorTest a10) {
182:                        return;
183:                    }
184:                }
185:                try {
186:                    Class ac[] = X.class.getDeclaredConstructor(
187:                            new Class[] {
188:                                    java.lang.reflect.ConstructorTest.class,
189:                                    boolean.class, byte.class, char.class,
190:                                    double.class, float.class, int.class,
191:                                    long.class, short.class, X.class,
192:                                    ConstructorTest.class })
193:                            .getParameterTypes();
194:                    int res = 0;
195:                    for (int i = 0; i < ac.length; i++) {
196:                        if (ac[i].getName().equals("boolean"))
197:                            res += 1;
198:                        if (ac[i].getName().equals("byte"))
199:                            res += 10;
200:                        if (ac[i].getName().equals("char"))
201:                            res += 100;
202:                        if (ac[i].getName().equals("double"))
203:                            res += 1000;
204:                        if (ac[i].getName().equals("float"))
205:                            res += 10000;
206:                        if (ac[i].getName().equals("int"))
207:                            res += 100000;
208:                        if (ac[i].getName().equals("long"))
209:                            res += 1000000;
210:                        if (ac[i].getName().equals("short"))
211:                            res += 10000000;
212:                        if (ac[i].getName().equals(
213:                                "java.lang.reflect.ConstructorTest$6X"))
214:                            res += 100000000;
215:                        if (ac[i].getName().equals(
216:                                "java.lang.reflect.ConstructorTest"))
217:                            res += 1000000000;
218:                    }
219:                    assertTrue("Error1", res == 2111111111);
220:                } catch (Exception e) {
221:                    fail("Error2: " + e.toString());
222:                }
223:            }
224:
225:            /**
226:             *  
227:             */
228:            public void test_hashCode_V() {
229:                class X {
230:                    public X(X a9) {
231:                        return;
232:                    }
233:                }
234:                try {
235:                    Constructor m = X.class.getDeclaredConstructor(new Class[] {
236:                            java.lang.reflect.ConstructorTest.class, X.class });
237:                    assertTrue("Error1", m.hashCode() == m.getDeclaringClass()
238:                            .getName().hashCode());
239:                } catch (NoSuchMethodException _) {
240:                    fail("Error2");
241:                }
242:            }
243:
244:            /**
245:             *  
246:             */
247:            public void test_newInstance_Obj() {
248:                class X1 {
249:                    public X1() {
250:                        return;
251:                    }
252:
253:                    public X1(X1 a9) {
254:                        return;
255:                    }
256:                }
257:                X1 x = new X1(new X1());
258:                try {
259:                    Constructor m = X1.class
260:                            .getDeclaredConstructor(new Class[] {
261:                                    java.lang.reflect.ConstructorTest.class,
262:                                    X1.class });
263:                    Object o = m
264:                            .newInstance(new Object[] {
265:                                    new java.lang.reflect.ConstructorTest(),
266:                                    new X1() });
267:                    assertTrue("Error1", o instanceof  X1);
268:                } catch (Exception e) {
269:                    fail("Error2: " + e.toString());
270:                }
271:            }
272:
273:            /**
274:             *  
275:             */
276:            public void test_toString_Obj() {
277:                class X {
278:                    public X() {
279:                        return;
280:                    }
281:
282:                    public X(X a9) {
283:                        return;
284:                    }
285:                }
286:                try {
287:                    Constructor m = X.class.getDeclaredConstructor(new Class[] {
288:                            java.lang.reflect.ConstructorTest.class, X.class });
289:                    assertTrue(
290:                            "Error1 " + m.toString(),
291:                            m
292:                                    .toString()
293:                                    .equals(
294:                                            "public java.lang.reflect.ConstructorTest$8X(java.lang.reflect.ConstructorTest,java.lang.reflect.ConstructorTest$8X)"));
295:                } catch (Exception e) {
296:                    fail("Error2: " + e.toString());
297:                }
298:            }
299:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.