Source Code Cross Referenced for SqlTimeConverterTestCase.java in  » Library » Apache-commons-beanutils-1.8.0-BETA-src » org » apache » commons » beanutils » converters » 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.converters 
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.converters;
019:
020:        import java.sql.Time;
021:        import java.util.Calendar;
022:        import java.util.Locale;
023:
024:        import junit.framework.TestSuite;
025:
026:        /**
027:         * Test Case for the {@link SqlTimeConverter} class.
028:         *
029:         * @version $Revision: 471689 $ $Date: 2006-11-06 10:52:49 +0000 (Mon, 06 Nov 2006) $
030:         */
031:
032:        public class SqlTimeConverterTestCase extends DateConverterTestBase {
033:
034:            /**
035:             * Construct a new Date test case.
036:             * @param name Test Name
037:             */
038:            public SqlTimeConverterTestCase(String name) {
039:                super (name);
040:            }
041:
042:            // ------------------------------------------------------------------------
043:
044:            /**
045:             * Create Test Suite
046:             * @return test suite
047:             */
048:            public static TestSuite suite() {
049:                return new TestSuite(SqlTimeConverterTestCase.class);
050:            }
051:
052:            // ------------------------------------------------------------------------
053:
054:            /**
055:             * Test Date Converter with no default value
056:             */
057:            public void testLocale() {
058:
059:                // Re-set the default Locale to Locale.US
060:                Locale defaultLocale = Locale.getDefault();
061:                Locale.setDefault(Locale.US);
062:
063:                String pattern = "h:mm a"; // SHORT style time format for US Locale
064:
065:                // Create & Configure the Converter
066:                DateTimeConverter converter = makeConverter();
067:                converter.setUseLocaleFormat(true);
068:
069:                // Valid String --> Type Conversion
070:                String testString = "3:06 pm";
071:                Object expected = toType(testString, pattern, null);
072:                validConversion(converter, expected, testString);
073:
074:                // Invalid Conversions
075:                invalidConversion(converter, null);
076:                invalidConversion(converter, "");
077:                invalidConversion(converter, "13:05");
078:                invalidConversion(converter, "11:05 p");
079:                invalidConversion(converter, "11.05 pm");
080:                invalidConversion(converter, new Integer(2));
081:
082:                // Test specified Locale
083:                converter.setLocale(Locale.UK);
084:                invalidConversion(converter, testString); // Test previous value now fails
085:                validConversion(converter, expected, "15:06"); // UK Short style is "HH:mm"
086:
087:                // Restore the default Locale
088:                Locale.setDefault(defaultLocale);
089:
090:            }
091:
092:            /**
093:             * Test default String to java.sql.Time conversion
094:             */
095:            public void testDefaultStringToTypeConvert() {
096:
097:                // Create & Configure the Converter
098:                DateTimeConverter converter = makeConverter();
099:                converter.setUseLocaleFormat(false);
100:
101:                // Valid String --> java.sql.Time Conversion
102:                String testString = "15:36:21";
103:                Object expected = toType(testString, "HH:mm:ss", null);
104:                validConversion(converter, expected, testString);
105:
106:                // Invalid String --> java.sql.Time Conversion
107:                invalidConversion(converter, "15:36");
108:
109:            }
110:
111:            /**
112:             * Create the Converter with no default value.
113:             * @return A new Converter
114:             */
115:            protected DateTimeConverter makeConverter() {
116:                return new SqlTimeConverter();
117:            }
118:
119:            /**
120:             * Create the Converter with a default value.
121:             * @param defaultValue The default value
122:             * @return A new Converter
123:             */
124:            protected DateTimeConverter makeConverter(Object defaultValue) {
125:                return new SqlTimeConverter(defaultValue);
126:            }
127:
128:            /**
129:             * Return the expected type
130:             * @return The expected type
131:             */
132:            protected Class getExpectedType() {
133:                return Time.class;
134:            }
135:
136:            /**
137:             * Convert from a Calendar to the appropriate Date type
138:             * 
139:             * @param value The Calendar value to convert
140:             * @return The converted value
141:             */
142:            protected Object toType(Calendar value) {
143:                return new Time(getTimeInMillis(value));
144:            }
145:
146:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.