Source Code Cross Referenced for DoubleLocaleConverterTestCase.java in  » Library » Apache-commons-beanutils-1.8.0-BETA-src » org » apache » commons » beanutils » locale » 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.locale.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.locale.converters;
019:
020:        /**
021:         * Test Case for the DoubleLocaleConverter class.
022:         *
023:         * @author Niall Pemberton
024:         * @version $Revision: 469728 $ $Date: 2006-11-01 01:08:34 +0000 (Wed, 01 Nov 2006) $
025:         */
026:
027:        public class DoubleLocaleConverterTestCase extends
028:                BaseLocaleConverterTestCase {
029:
030:            // ---------------------------------------------------------- Constructors
031:
032:            public DoubleLocaleConverterTestCase(String name) {
033:                super (name);
034:            }
035:
036:            // -------------------------------------------------- Overall Test Methods
037:
038:            /**
039:             * Set up instance variables required by this test case.
040:             */
041:            public void setUp() throws Exception {
042:
043:                super .setUp();
044:
045:                defaultValue = new Double("9.99");
046:                expectedValue = new Double(expectedDecimalValue);
047:
048:            }
049:
050:            /**
051:             * Tear down instance variables required by this test case.
052:             */
053:            public void tearDown() {
054:                super .tearDown();
055:            }
056:
057:            // ------------------------------------------------------------------------
058:
059:            /**
060:             * Test Converter(defaultValue, locale, pattern, localizedPattern) constructor
061:             */
062:            public void testConstructorMain() {
063:
064:                // ------------- Construct with localized pattern ------------
065:                converter = new DoubleLocaleConverter(defaultValue,
066:                        localizedLocale, localizedDecimalPattern, true);
067:
068:                convertValueNoPattern(converter, "(A)", localizedDecimalValue,
069:                        expectedValue);
070:                convertValueWithPattern(converter, "(A)",
071:                        localizedDecimalValue, localizedDecimalPattern,
072:                        expectedValue);
073:                convertInvalid(converter, "(A)", defaultValue);
074:                convertNull(converter, "(A)", defaultValue);
075:
076:                // **************************************************************************
077:                // Convert value in the wrong format - maybe you would expect it to throw an
078:                // exception and return the default - it doesn't, DecimalFormat parses it
079:                // quite happily turning "1,234.56" into "1.234"
080:                // I guess this is one of the limitations of DecimalFormat
081:                // **************************************************************************
082:                convertValueNoPattern(converter, "(B)", defaultDecimalValue,
083:                        new Double("1.234"));
084:
085:                // **************************************************************************
086:                // Convert with non-localized pattern - this causes an exception in parse()
087:                // but it gets swallowed in convert() method and returns default.
088:                //  **** IS THIS THE EXPECTED BEHAVIOUR? ****
089:                // Maybe if the pattern is no good, we should use a default pattern rather
090:                // than just returning the default value.
091:                // **************************************************************************
092:                convertValueWithPattern(converter, "(B)",
093:                        localizedDecimalValue, defaultDecimalPattern,
094:                        defaultValue);
095:
096:                // **************************************************************************
097:                // Convert with specified type
098:                // 
099:                // BaseLocaleConverter completely ignores the type - so even if we specify
100:                // Double.class here it still returns a Double.
101:                //  **** SHOULD IMPLEMENT THIS BEHAVIOUR ****
102:                // **************************************************************************
103:                convertValueToType(converter, "(B)", Integer.class,
104:                        localizedDecimalValue, localizedDecimalPattern,
105:                        expectedValue);
106:
107:                // ------------- Construct with non-localized pattern ------------
108:                converter = new DoubleLocaleConverter(defaultValue,
109:                        localizedLocale, defaultDecimalPattern, false);
110:
111:                convertValueNoPattern(converter, "(C)", localizedDecimalValue,
112:                        expectedValue);
113:                convertValueWithPattern(converter, "(C)",
114:                        localizedDecimalValue, defaultDecimalPattern,
115:                        expectedValue);
116:                convertInvalid(converter, "(C)", defaultValue);
117:                convertNull(converter, "(C)", defaultValue);
118:
119:            }
120:
121:            /**
122:             * Test Converter() constructor
123:             * 
124:             * Uses the default locale, no default value
125:             * 
126:             */
127:            public void testConstructor_2() {
128:
129:                // ------------- Construct using default locale ------------
130:                converter = new DoubleLocaleConverter();
131:
132:                // Perform Tests
133:                convertValueNoPattern(converter, defaultDecimalValue,
134:                        expectedValue);
135:                convertValueWithPattern(converter, defaultDecimalValue,
136:                        defaultDecimalPattern, expectedValue);
137:                convertInvalid(converter, null);
138:                convertNull(converter, null);
139:
140:            }
141:
142:            /**
143:             * Test Converter(locPattern) constructor
144:             * 
145:             * Uses the default locale, no default value
146:             * 
147:             */
148:            public void testConstructor_3() {
149:
150:                // ------------- Construct using localized pattern (default locale) --------
151:                converter = new DoubleLocaleConverter(true);
152:
153:                // Perform Tests
154:                convertValueNoPattern(converter, defaultDecimalValue,
155:                        expectedValue);
156:                convertValueWithPattern(converter, defaultDecimalValue,
157:                        defaultDecimalPattern, expectedValue);
158:                convertInvalid(converter, null);
159:                convertNull(converter, null);
160:
161:            }
162:
163:            /**
164:             * Test Converter(Locale) constructor
165:             */
166:            public void testConstructor_4() {
167:
168:                // ------------- Construct using specified Locale --------
169:                converter = new DoubleLocaleConverter(localizedLocale);
170:
171:                // Perform Tests
172:                convertValueNoPattern(converter, localizedDecimalValue,
173:                        expectedValue);
174:                convertValueWithPattern(converter, localizedDecimalValue,
175:                        defaultDecimalPattern, expectedValue);
176:                convertInvalid(converter, null);
177:                convertNull(converter, null);
178:
179:            }
180:
181:            /**
182:             * Test Converter(Locale, locPattern) constructor
183:             */
184:            public void testConstructor_5() {
185:
186:                // ------------- Construct using specified Locale --------
187:                converter = new DoubleLocaleConverter(localizedLocale, true);
188:
189:                // Perform Tests
190:                convertValueNoPattern(converter, localizedDecimalValue,
191:                        expectedValue);
192:                convertValueWithPattern(converter, localizedDecimalValue,
193:                        localizedDecimalPattern, expectedValue);
194:                convertInvalid(converter, null);
195:                convertNull(converter, null);
196:
197:            }
198:
199:            /**
200:             * Test Converter(Locale, pattern) constructor
201:             */
202:            public void testConstructor_6() {
203:
204:                // ------------- Construct using specified Locale --------
205:                converter = new DoubleLocaleConverter(localizedLocale,
206:                        defaultDecimalPattern);
207:
208:                // Perform Tests
209:                convertValueNoPattern(converter, localizedDecimalValue,
210:                        expectedValue);
211:                convertValueWithPattern(converter, localizedDecimalValue,
212:                        defaultDecimalPattern, expectedValue);
213:                convertInvalid(converter, null);
214:                convertNull(converter, null);
215:
216:            }
217:
218:            /**
219:             * Test Converter(Locale, pattern, locPattern) constructor
220:             */
221:            public void testConstructor_7() {
222:
223:                // ------------- Construct using specified Locale --------
224:                converter = new DoubleLocaleConverter(localizedLocale,
225:                        localizedDecimalPattern, true);
226:
227:                // Perform Tests
228:                convertValueNoPattern(converter, localizedDecimalValue,
229:                        expectedValue);
230:                convertValueWithPattern(converter, localizedDecimalValue,
231:                        localizedDecimalPattern, expectedValue);
232:                convertInvalid(converter, null);
233:                convertNull(converter, null);
234:
235:            }
236:
237:            /**
238:             * Test Converter(defaultValue) constructor
239:             */
240:            public void testConstructor_8() {
241:
242:                // ------------- Construct using specified Locale --------
243:                converter = new DoubleLocaleConverter(defaultValue);
244:
245:                // Perform Tests
246:                convertValueNoPattern(converter, defaultDecimalValue,
247:                        expectedValue);
248:                convertValueWithPattern(converter, defaultDecimalValue,
249:                        defaultDecimalPattern, expectedValue);
250:                convertInvalid(converter, defaultValue);
251:                convertNull(converter, defaultValue);
252:
253:            }
254:
255:            /**
256:             * Test Converter(defaultValue, locPattern) constructor
257:             */
258:            public void testConstructor_9() {
259:
260:                // ------------- Construct using specified Locale --------
261:                converter = new DoubleLocaleConverter(defaultValue, true);
262:
263:                // Perform Tests
264:                convertValueNoPattern(converter, defaultDecimalValue,
265:                        expectedValue);
266:                convertValueWithPattern(converter, defaultDecimalValue,
267:                        defaultDecimalPattern, expectedValue);
268:                convertInvalid(converter, defaultValue);
269:                convertNull(converter, defaultValue);
270:
271:            }
272:
273:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.