Source Code Cross Referenced for ConstructorUtilsTestCase.java in  » Library » Apache-commons-beanutils-1.8.0-BETA-src » org » apache » commons » beanutils » 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 » Library » Apache commons beanutils 1.8.0 BETA src » org.apache.commons.beanutils 
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:        package org.apache.commons.beanutils;
019:
020:        import java.lang.reflect.Constructor;
021:        import java.lang.reflect.Modifier;
022:
023:        import junit.framework.Test;
024:        import junit.framework.TestCase;
025:        import junit.framework.TestSuite;
026:
027:        /**
028:         * <p> Test case for <code>ConstructorUtils</code> </p>
029:         *
030:         */
031:        public class ConstructorUtilsTestCase extends TestCase {
032:
033:            // ---------------------------------------------------------- Constructors
034:
035:            /**
036:             * Construct a new instance of this test case.
037:             *
038:             * @param name Name of the test case
039:             */
040:            public ConstructorUtilsTestCase(String name) {
041:                super (name);
042:            }
043:
044:            // -------------------------------------------------- Overall Test Methods
045:
046:            /**
047:             * Set up instance variables required by this test case.
048:             */
049:            public void setUp() throws Exception {
050:                super .setUp();
051:            }
052:
053:            /**
054:             * Return the tests included in this test suite.
055:             */
056:            public static Test suite() {
057:                return (new TestSuite(ConstructorUtilsTestCase.class));
058:            }
059:
060:            /**
061:             * Tear down instance variables required by this test case.
062:             */
063:            public void tearDown() throws Exception {
064:                super .tearDown();
065:            }
066:
067:            // ------------------------------------------------ Individual Test Methods
068:
069:            public void testInvokeConstructor() throws Exception {
070:                {
071:                    Object obj = ConstructorUtils.invokeConstructor(
072:                            TestBean.class, "TEST");
073:                    assertNotNull(obj);
074:                    assertTrue(obj instanceof  TestBean);
075:                    assertEquals("TEST", ((TestBean) obj).getStringProperty());
076:                }
077:                {
078:                    Object obj = ConstructorUtils.invokeConstructor(
079:                            TestBean.class, new Float(17.3f));
080:                    assertNotNull(obj);
081:                    assertTrue(obj instanceof  TestBean);
082:                    assertEquals(17.3f, ((TestBean) obj).getFloatProperty(),
083:                            0.0f);
084:                }
085:            }
086:
087:            public void testInvokeConstructorWithArgArray() throws Exception {
088:                Object[] args = { new Float(17.3f), "TEST" };
089:                Object obj = ConstructorUtils.invokeConstructor(TestBean.class,
090:                        args);
091:                assertNotNull(obj);
092:                assertTrue(obj instanceof  TestBean);
093:                assertEquals(17.3f, ((TestBean) obj).getFloatProperty(), 0.0f);
094:                assertEquals("TEST", ((TestBean) obj).getStringProperty());
095:            }
096:
097:            public void testInvokeConstructorWithTypeArray() throws Exception {
098:                {
099:                    Object[] args = { Boolean.TRUE, "TEST" };
100:                    Class[] types = { Boolean.TYPE, String.class };
101:                    Object obj = ConstructorUtils.invokeConstructor(
102:                            TestBean.class, args, types);
103:                    assertNotNull(obj);
104:                    assertTrue(obj instanceof  TestBean);
105:                    assertEquals(true, ((TestBean) obj).getBooleanProperty());
106:                    assertEquals("TEST", ((TestBean) obj).getStringProperty());
107:                }
108:                {
109:                    Object[] args = { Boolean.TRUE, "TEST" };
110:                    Class[] types = { Boolean.class, String.class };
111:                    Object obj = ConstructorUtils.invokeConstructor(
112:                            TestBean.class, args, types);
113:                    assertNotNull(obj);
114:                    assertTrue(obj instanceof  TestBean);
115:                    assertEquals(true, ((TestBean) obj).isBooleanSecond());
116:                    assertEquals("TEST", ((TestBean) obj).getStringProperty());
117:                }
118:            }
119:
120:            public void testInvokeExactConstructor() throws Exception {
121:                {
122:                    Object obj = ConstructorUtils.invokeExactConstructor(
123:                            TestBean.class, "TEST");
124:                    assertNotNull(obj);
125:                    assertTrue(obj instanceof  TestBean);
126:                    assertEquals("TEST", ((TestBean) obj).getStringProperty());
127:                }
128:                {
129:                    try {
130:                        Object obj = ConstructorUtils.invokeExactConstructor(
131:                                TestBean.class, new Float(17.3f));
132:                        fail("Expected NoSuchMethodException");
133:                    } catch (NoSuchMethodException e) {
134:                        // expected
135:                    }
136:                }
137:                {
138:                    Object obj = ConstructorUtils.invokeExactConstructor(
139:                            TestBean.class, Boolean.TRUE);
140:                    assertNotNull(obj);
141:                    assertTrue(obj instanceof  TestBean);
142:                    assertEquals(true, ((TestBean) obj).isBooleanSecond());
143:                }
144:            }
145:
146:            public void testInvokeExactConstructorWithArgArray()
147:                    throws Exception {
148:                {
149:                    Object[] args = { new Float(17.3f), "TEST" };
150:                    try {
151:                        Object obj = ConstructorUtils.invokeExactConstructor(
152:                                TestBean.class, args);
153:                        fail("Expected NoSuchMethodException");
154:                    } catch (NoSuchMethodException e) {
155:                        // expected
156:                    }
157:                }
158:                {
159:                    Object[] args = { Boolean.TRUE, "TEST" };
160:                    Object obj = ConstructorUtils.invokeExactConstructor(
161:                            TestBean.class, args);
162:                    assertNotNull(obj);
163:                    assertTrue(obj instanceof  TestBean);
164:                    assertEquals(true, ((TestBean) obj).isBooleanSecond());
165:                    assertEquals("TEST", ((TestBean) obj).getStringProperty());
166:                }
167:            }
168:
169:            public void testInvokeExactConstructorWithTypeArray()
170:                    throws Exception {
171:                {
172:                    Object[] args = { Boolean.TRUE, "TEST" };
173:                    Class[] types = { Boolean.TYPE, String.class };
174:                    Object obj = ConstructorUtils.invokeExactConstructor(
175:                            TestBean.class, args, types);
176:                    assertNotNull(obj);
177:                    assertTrue(obj instanceof  TestBean);
178:                    assertEquals(true, ((TestBean) obj).getBooleanProperty());
179:                    assertEquals("TEST", ((TestBean) obj).getStringProperty());
180:                }
181:                {
182:                    Object[] args = { Boolean.TRUE, "TEST" };
183:                    Class[] types = { Boolean.class, String.class };
184:                    Object obj = ConstructorUtils.invokeExactConstructor(
185:                            TestBean.class, args, types);
186:                    assertNotNull(obj);
187:                    assertTrue(obj instanceof  TestBean);
188:                    assertEquals(true, ((TestBean) obj).isBooleanSecond());
189:                    assertEquals("TEST", ((TestBean) obj).getStringProperty());
190:                }
191:                {
192:                    Object[] args = { new Float(17.3f), "TEST" };
193:                    Class[] types = { Float.TYPE, String.class };
194:                    Object obj = ConstructorUtils.invokeExactConstructor(
195:                            TestBean.class, args, types);
196:                    assertNotNull(obj);
197:                    assertTrue(obj instanceof  TestBean);
198:                    assertEquals(17.3f, ((TestBean) obj).getFloatProperty(),
199:                            0.0f);
200:                    assertEquals("TEST", ((TestBean) obj).getStringProperty());
201:                }
202:                {
203:                    Object[] args = { new Float(17.3f), "TEST" };
204:                    Class[] types = { Float.class, String.class };
205:                    try {
206:                        Object obj = ConstructorUtils.invokeExactConstructor(
207:                                TestBean.class, args, types);
208:                        fail("Expected NoSuchMethodException");
209:                    } catch (NoSuchMethodException e) {
210:                        // expected
211:                    }
212:                }
213:            }
214:
215:            public void testGetAccessibleConstructor() throws Exception {
216:                {
217:                    Constructor ctor = ConstructorUtils
218:                            .getAccessibleConstructor(TestBean.class,
219:                                    String.class);
220:                    assertNotNull(ctor);
221:                    assertTrue(Modifier.isPublic(ctor.getModifiers()));
222:                }
223:                {
224:                    Constructor ctor = ConstructorUtils
225:                            .getAccessibleConstructor(TestBean.class,
226:                                    Integer.class);
227:                    assertNotNull(ctor);
228:                    assertTrue(Modifier.isPublic(ctor.getModifiers()));
229:                }
230:                {
231:                    Constructor ctor = ConstructorUtils
232:                            .getAccessibleConstructor(TestBean.class,
233:                                    Integer.TYPE);
234:                    assertNull(ctor);
235:                }
236:            }
237:
238:            public void testGetAccessibleConstructorWithTypeArray()
239:                    throws Exception {
240:                {
241:                    Class[] types = { Boolean.TYPE, String.class };
242:                    Constructor ctor = ConstructorUtils
243:                            .getAccessibleConstructor(TestBean.class, types);
244:                    assertNotNull(ctor);
245:                    assertTrue(Modifier.isPublic(ctor.getModifiers()));
246:                }
247:                {
248:                    Class[] types = { Boolean.TYPE, Boolean.TYPE, String.class };
249:                    Constructor ctor = ConstructorUtils
250:                            .getAccessibleConstructor(TestBean.class, types);
251:                    assertNull(ctor);
252:                }
253:            }
254:
255:            public void testGetAccessibleConstructorWithConstructorArg()
256:                    throws Exception {
257:                {
258:                    Class[] types = { Integer.class };
259:                    Constructor c1 = TestBean.class.getConstructor(types);
260:                    Constructor ctor = ConstructorUtils
261:                            .getAccessibleConstructor(c1);
262:                    assertNotNull(ctor);
263:                    assertTrue(Modifier.isPublic(ctor.getModifiers()));
264:                }
265:                {
266:                    Class[] types = { Integer.class };
267:                    Constructor c1 = TestBean.class
268:                            .getDeclaredConstructor(types);
269:                    Constructor ctor = ConstructorUtils
270:                            .getAccessibleConstructor(c1);
271:                    assertNotNull(ctor);
272:                    assertTrue(Modifier.isPublic(ctor.getModifiers()));
273:                }
274:                {
275:                    Class[] types = { Integer.TYPE };
276:                    Constructor c1 = TestBean.class
277:                            .getDeclaredConstructor(types);
278:                    Constructor ctor = ConstructorUtils
279:                            .getAccessibleConstructor(c1);
280:                    assertNull(ctor);
281:                }
282:            }
283:
284:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.