Source Code Cross Referenced for TypeConverter_Test.java in  » Portal » uPortal_rel-2-6-1-GA » org » jasig » portal » 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 » Portal » uPortal_rel 2 6 1 GA » org.jasig.portal.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright 2001 The JA-SIG Collaborative.  All rights reserved.
002:         *  See license distributed with this file and
003:         *  available online at http://www.uportal.org/license.html
004:         */
005:
006:        package org.jasig.portal.lang;
007:
008:        import junit.framework.TestCase;
009:
010:        /**
011:         * The <code>TypeConverter_Test</code> class tests <code>TypeConverter</code> class.
012:         *
013:         *
014:         * @version $Revision: 34826 $
015:         *
016:         * @author <a href="mailto:jnielsen@sct.com">Jan Nielsen</a>
017:         **/
018:        public class TypeConverter_Test extends TestCase {
019:            /** Class version identifier. */
020:            public static final String RCS_ID = "@(#) $Header$";
021:
022:            /**
023:             * Run all the test cases defined in the class.
024:             *
025:             * @param args not used
026:             **/
027:            public static void main(String[] args) {
028:                junit.textui.TestRunner.run(suite());
029:            }
030:
031:            /**
032:             * Build a test suite using reflection.
033:             *
034:             * @return test suite for the class
035:             **/
036:            public static junit.framework.TestSuite suite() {
037:                return new junit.framework.TestSuite(TypeConverter_Test.class);
038:            }
039:
040:            /**
041:             * Setup for each test method.
042:             **/
043:            public void setUp() {
044:            }
045:
046:            /**
047:             * Tear down for each test method.
048:             **/
049:            public void tearDown() {
050:            }
051:
052:            public TypeConverter_Test(String name) {
053:                super (name);
054:            }
055:
056:            public void test_toString_boolean() {
057:                assertEquals(TypeConverter.TRUE, "true");
058:                assertEquals(TypeConverter.FALSE, "false");
059:
060:                assertEquals(TypeConverter.toString(true), TypeConverter.TRUE);
061:                assertEquals(TypeConverter.toString(false), TypeConverter.FALSE);
062:
063:                Object o1 = null;
064:                Object o2 = null;
065:
066:                o1 = (Object) TypeConverter.toString(true);
067:                o2 = (Object) TypeConverter.toString(true);
068:                if (o1 != o2) {
069:                    fail("Expected canonical 'true' value.");
070:                }
071:
072:                o1 = (Object) TypeConverter.toString(false);
073:                o2 = (Object) TypeConverter.toString(false);
074:                if (o1 != o2) {
075:                    fail("Expected canonical 'false' value.");
076:                }
077:            }
078:
079:            public void test_toBoolean() {
080:                assertTrue(TypeConverter.toBoolean("true"));
081:                assertTrue(!TypeConverter.toBoolean("false"));
082:                assertTrue(TypeConverter.toBoolean("True"));
083:                assertTrue(!TypeConverter.toBoolean("False"));
084:                assertTrue(TypeConverter.toBoolean("TRUE"));
085:                assertTrue(!TypeConverter.toBoolean("FALSE"));
086:
087:                String value = null;
088:
089:                try {
090:                    value = "false ";
091:                    TypeConverter.toBoolean(value);
092:                    fail("Expected " + value
093:                            + " to throw IllegalArgumentException.");
094:                } catch (IllegalArgumentException x) {
095:                    ;// correct
096:                }
097:
098:                try {
099:                    value = "true ";
100:                    TypeConverter.toBoolean(value);
101:                    fail("Expected " + value
102:                            + " to throw IllegalArgumentException.");
103:                } catch (IllegalArgumentException x) {
104:                    ;// correct
105:                }
106:
107:                try {
108:                    value = null;
109:                    TypeConverter.toBoolean(value);
110:                    fail("Expected " + value
111:                            + " to throw IllegalArgumentException.");
112:                } catch (IllegalArgumentException x) {
113:                    ;// correct
114:                }
115:            }
116:
117:            public void test_toString_char() {
118:                assertEquals(1, TypeConverter.toString('a').length());
119:            }
120:
121:            public void test_toChar_String() {
122:                try {
123:                    TypeConverter.toChar((String) null);
124:                } catch (IllegalArgumentException x) {
125:                    ;// correct
126:                }
127:
128:                try {
129:                    TypeConverter.toChar("");
130:                } catch (IllegalArgumentException x) {
131:                    ;// correct
132:                }
133:            }
134:
135:            public void test_toString_int() {
136:                assertEquals(Integer.toString(Integer.MAX_VALUE), TypeConverter
137:                        .toString(Integer.MAX_VALUE));
138:
139:                assertEquals(Integer.toString(Integer.MIN_VALUE), TypeConverter
140:                        .toString(Integer.MIN_VALUE));
141:
142:                assertEquals(Integer.toString(-1), TypeConverter.toString(-1));
143:
144:                assertEquals(Integer.toString(0), TypeConverter.toString(0));
145:
146:                assertEquals(Integer.toString(1), TypeConverter.toString(1));
147:            }
148:
149:            public void test_toInt_String() {
150:                assertEquals(Integer.MAX_VALUE, TypeConverter.toInt(Integer
151:                        .toString(Integer.MAX_VALUE)));
152:
153:                assertEquals(Integer.MIN_VALUE, TypeConverter.toInt(Integer
154:                        .toString(Integer.MIN_VALUE)));
155:
156:                assertEquals(-1, TypeConverter.toInt(Integer.toString(-1)));
157:
158:                assertEquals(0, TypeConverter.toInt(Integer.toString(0)));
159:
160:                assertEquals(1, TypeConverter.toInt(Integer.toString(1)));
161:
162:                try {
163:                    TypeConverter.toInt((String) null);
164:                    fail("Expected null to throw an IllegalArgumentException.");
165:                } catch (IllegalArgumentException x) {
166:                    ;// correct
167:                }
168:
169:                try {
170:                    TypeConverter.toInt("not an integer");
171:                    fail("Expected null to throw an IllegalArgumentException.");
172:                } catch (IllegalArgumentException x) {
173:                    ;// correct
174:                }
175:
176:                try {
177:                    TypeConverter.toInt(Long.toString(Long.MAX_VALUE));
178:                    fail("Expected null to throw an IllegalArgumentException.");
179:                } catch (IllegalArgumentException x) {
180:                    ;// correct
181:                }
182:
183:                try {
184:                    TypeConverter.toInt(Float.toString(Float.MAX_VALUE));
185:                    fail("Expected null to throw an IllegalArgumentException.");
186:                } catch (IllegalArgumentException x) {
187:                    ;// correct
188:                }
189:
190:                try {
191:                    TypeConverter.toInt(Double.toString(Double.MAX_VALUE));
192:                    fail("Expected null to throw an IllegalArgumentException.");
193:                } catch (IllegalArgumentException x) {
194:                    ;// correct
195:                }
196:            }
197:
198:            public void test_toString_long() {
199:                assertEquals(Long.toString(Long.MAX_VALUE), TypeConverter
200:                        .toString(Long.MAX_VALUE));
201:
202:                assertEquals(Long.toString(Long.MIN_VALUE), TypeConverter
203:                        .toString(Long.MIN_VALUE));
204:
205:                assertEquals(Long.toString(-1), TypeConverter.toString(-1));
206:
207:                assertEquals(Long.toString(0), TypeConverter.toString(0));
208:
209:                assertEquals(Long.toString(1), TypeConverter.toString(1));
210:            }
211:
212:            public void test_toLong_String() {
213:                assertEquals(Long.MAX_VALUE, TypeConverter.toLong(Long
214:                        .toString(Long.MAX_VALUE)));
215:
216:                assertEquals(Long.MIN_VALUE, TypeConverter.toLong(Long
217:                        .toString(Long.MIN_VALUE)));
218:
219:                assertEquals(-1, TypeConverter.toLong(Long.toString(-1)));
220:
221:                assertEquals(0, TypeConverter.toLong(Long.toString(0)));
222:
223:                assertEquals(1, TypeConverter.toLong(Long.toString(1)));
224:
225:                try {
226:                    TypeConverter.toLong((String) null);
227:                    fail("Expected null to throw an IllegalArgumentException.");
228:                } catch (IllegalArgumentException x) {
229:                    ;// correct
230:                }
231:
232:                try {
233:                    TypeConverter.toLong("not a long");
234:                    fail("Expected null to throw an IllegalArgumentException.");
235:                } catch (IllegalArgumentException x) {
236:                    ;// correct
237:                }
238:
239:                try {
240:                    TypeConverter.toLong(Double.toString(Double.MAX_VALUE));
241:                    fail("Expected null to throw an IllegalArgumentException.");
242:                } catch (IllegalArgumentException x) {
243:                    ;// correct
244:                }
245:
246:                try {
247:                    TypeConverter.toLong(Float.toString(Float.MAX_VALUE));
248:                    fail("Expected null to throw an IllegalArgumentException.");
249:                } catch (IllegalArgumentException x) {
250:                    ;// correct
251:                }
252:
253:                try {
254:                    TypeConverter.toLong(Float.toString(Float.MIN_VALUE));
255:                    fail("Expected null to throw an IllegalArgumentException.");
256:                } catch (IllegalArgumentException x) {
257:                    ;// correct
258:                }
259:
260:                try {
261:                    TypeConverter.toLong(Double.toString(Double.MAX_VALUE));
262:                    fail("Expected null to throw an IllegalArgumentException.");
263:                } catch (IllegalArgumentException x) {
264:                    ;// correct
265:                }
266:
267:                try {
268:                    TypeConverter.toLong(Double.toString(Double.MIN_VALUE));
269:                    fail("Expected null to throw an IllegalArgumentException.");
270:                } catch (IllegalArgumentException x) {
271:                    ;// correct
272:                }
273:            }
274:
275:            public void test_toString_float() {
276:                assertEquals(Float.toString(Float.MAX_VALUE), TypeConverter
277:                        .toString(Float.MAX_VALUE));
278:
279:                assertEquals(Float.toString(Float.MIN_VALUE), TypeConverter
280:                        .toString(Float.MIN_VALUE));
281:
282:                assertEquals(Float.toString(-1.0F), TypeConverter
283:                        .toString(-1.0F));
284:
285:                assertEquals(Float.toString(0.0F), TypeConverter.toString(0.0F));
286:
287:                assertEquals(Float.toString(1.0F), TypeConverter.toString(1.0F));
288:
289:                assertEquals("Infinity", TypeConverter
290:                        .toString(Float.POSITIVE_INFINITY));
291:
292:                assertEquals("-Infinity", TypeConverter
293:                        .toString(Float.NEGATIVE_INFINITY));
294:            }
295:
296:            public void test_toFloat_String() {
297:                float ERROR = 0.0F;
298:
299:                assertEquals(Float.MAX_VALUE, TypeConverter.toFloat(Float
300:                        .toString(Float.MAX_VALUE)), ERROR);
301:
302:                assertEquals(Float.MIN_VALUE, TypeConverter.toFloat(Float
303:                        .toString(Float.MIN_VALUE)), ERROR);
304:
305:                assertEquals(-1.0F, TypeConverter
306:                        .toFloat(Float.toString(-1.0F)), ERROR);
307:
308:                assertEquals(0.0F, TypeConverter.toFloat(Float.toString(0.0F)),
309:                        ERROR);
310:
311:                assertEquals(1.0F, TypeConverter.toFloat(Float.toString(1.0F)),
312:                        ERROR);
313:
314:                try {
315:                    TypeConverter.toFloat((String) null);
316:                    fail("Expected an IllegalArgumentException.");
317:                } catch (IllegalArgumentException x) {
318:                    ;// correct
319:                }
320:
321:                try {
322:                    TypeConverter.toFloat("not a float");
323:                    fail("Expected an IllegalArgumentException.");
324:                } catch (IllegalArgumentException x) {
325:                    ;// correct
326:                }
327:
328:                assertEquals(Float.POSITIVE_INFINITY, TypeConverter
329:                        .toFloat(Double.toString(Double.MAX_VALUE)), ERROR);
330:
331:                assertEquals(Float.POSITIVE_INFINITY, TypeConverter
332:                        .toFloat(Double.toString(Double.POSITIVE_INFINITY)),
333:                        ERROR);
334:
335:                assertEquals(0F, TypeConverter.toFloat(Double
336:                        .toString(Double.MIN_VALUE)), ERROR);
337:
338:                assertEquals(Float.NEGATIVE_INFINITY, TypeConverter
339:                        .toFloat(Double.toString(Double.NEGATIVE_INFINITY)),
340:                        ERROR);
341:            }
342:
343:            public void test_toString_double() {
344:                assertEquals(Double.toString(Double.MAX_VALUE), TypeConverter
345:                        .toString(Double.MAX_VALUE));
346:
347:                assertEquals(Double.toString(Double.MIN_VALUE), TypeConverter
348:                        .toString(Double.MIN_VALUE));
349:
350:                assertEquals(Double.toString(-1.0D), TypeConverter
351:                        .toString(-1.0D));
352:
353:                assertEquals(Double.toString(0.0D), TypeConverter
354:                        .toString(0.0D));
355:
356:                assertEquals(Double.toString(1.0D), TypeConverter
357:                        .toString(1.0D));
358:
359:                assertEquals("Infinity", TypeConverter
360:                        .toString(Double.POSITIVE_INFINITY));
361:
362:                assertEquals("-Infinity", TypeConverter
363:                        .toString(Double.NEGATIVE_INFINITY));
364:            }
365:
366:            public void test_toDouble_String() {
367:                float ERROR = 0.0F;
368:
369:                assertEquals(Double.MAX_VALUE, TypeConverter.toDouble(Double
370:                        .toString(Double.MAX_VALUE)), ERROR);
371:
372:                assertEquals(Double.MIN_VALUE, TypeConverter.toDouble(Double
373:                        .toString(Double.MIN_VALUE)), ERROR);
374:
375:                assertEquals(-1.0D, TypeConverter.toDouble(Double
376:                        .toString(-1.0D)), ERROR);
377:
378:                assertEquals(0.0D, TypeConverter
379:                        .toDouble(Double.toString(0.0D)), ERROR);
380:
381:                assertEquals(1.0D, TypeConverter
382:                        .toDouble(Double.toString(1.0D)), ERROR);
383:
384:                try {
385:                    TypeConverter.toDouble((String) null);
386:                    fail("Expected an IllegalArgumentException.");
387:                } catch (IllegalArgumentException x) {
388:                    ;// correct
389:                }
390:
391:                try {
392:                    TypeConverter.toDouble("not a float");
393:                    fail("Expected an IllegalArgumentException.");
394:                } catch (IllegalArgumentException x) {
395:                    ;// correct
396:                }
397:
398:                assertEquals(Double.POSITIVE_INFINITY, TypeConverter
399:                        .toDouble(Double.toString(Double.POSITIVE_INFINITY)),
400:                        ERROR);
401:
402:                assertEquals(Double.MIN_VALUE, TypeConverter.toDouble(Double
403:                        .toString(Double.MIN_VALUE)), ERROR);
404:
405:                assertEquals(Double.NEGATIVE_INFINITY, TypeConverter
406:                        .toDouble(Double.toString(Double.NEGATIVE_INFINITY)),
407:                        ERROR);
408:            }
409:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.