Source Code Cross Referenced for ByteLocaleConverterTestCase.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 ByteLocaleConverter 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 ByteLocaleConverterTestCase extends
028:                BaseLocaleConverterTestCase {
029:
030:            // ---------------------------------------------------------- Constructors
031:
032:            public ByteLocaleConverterTestCase(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:                defaultIntegerPattern = "#,###";
046:                defaultIntegerValue = ",123";
047:
048:                localizedIntegerPattern = "#.###";
049:                localizedIntegerValue = ".123";
050:
051:                // Expected Values
052:                expectedDecimalValue = "123.56";
053:                expectedIntegerValue = "123";
054:
055:                defaultValue = new Byte("99");
056:                expectedValue = new Byte(expectedIntegerValue);
057:
058:            }
059:
060:            /**
061:             * Tear down instance variables required by this test case.
062:             */
063:            public void tearDown() {
064:                super .tearDown();
065:            }
066:
067:            // ------------------------------------------------------------------------
068:
069:            /**
070:             * Test Converter(defaultValue, locale, pattern, localizedPattern) constructor
071:             */
072:            public void testConstructorMain() {
073:
074:                // ------------- Construct with localized pattern ------------
075:                converter = new ByteLocaleConverter(defaultValue,
076:                        localizedLocale, localizedIntegerPattern, true);
077:
078:                convertValueNoPattern(converter, "(A)", localizedIntegerValue,
079:                        expectedValue);
080:                convertValueWithPattern(converter, "(A)",
081:                        localizedIntegerValue, localizedIntegerPattern,
082:                        expectedValue);
083:                convertInvalid(converter, "(A)", defaultValue);
084:                convertNull(converter, "(A)", defaultValue);
085:
086:                // **************************************************************************
087:                // Convert value in the wrong format - maybe you would expect it to throw an
088:                // exception and return the default - it doesn't, DecimalFormat parses it
089:                // quite happily turning ",123" into "0"
090:                // I guess this is one of the limitations of DecimalFormat 
091:                // **************************************************************************
092:                convertValueNoPattern(converter, "(B)", defaultIntegerValue,
093:                        new Byte("0"));
094:
095:                // **************************************************************************
096:                // Convert with non-localized pattern
097:                // **************************************************************************
098:                convertValueWithPattern(converter, "(B)", "123",
099:                        defaultIntegerPattern, new Byte("123"));
100:                convertValueWithPattern(converter, "(B-2)",
101:                        localizedIntegerValue, defaultIntegerPattern,
102:                        defaultValue);
103:
104:                // **************************************************************************
105:                // Convert with specified type
106:                // 
107:                // BaseLocaleConverter completely ignores the type - so even if we specify
108:                // Double.class here it still returns a Byte.
109:                //  **** SHOULD IMPLEMENT THIS BEHAVIOUR ****
110:                // **************************************************************************
111:                convertValueToType(converter, "(B)", Double.class,
112:                        localizedIntegerValue, localizedIntegerPattern,
113:                        expectedValue);
114:
115:                // ------------- Construct with non-localized pattern ------------
116:                converter = new ByteLocaleConverter(defaultValue,
117:                        localizedLocale, defaultIntegerPattern, false);
118:
119:                convertValueNoPattern(converter, "(C)", localizedIntegerValue,
120:                        expectedValue);
121:                convertValueWithPattern(converter, "(C)",
122:                        localizedIntegerValue, defaultIntegerPattern,
123:                        expectedValue);
124:                convertInvalid(converter, "(C)", defaultValue);
125:                convertNull(converter, "(C)", defaultValue);
126:
127:            }
128:
129:            /**
130:             * Test Converter() constructor
131:             * 
132:             * Uses the default locale, no default value
133:             * 
134:             */
135:            public void testConstructor_2() {
136:
137:                // ------------- Construct using default locale ------------
138:                converter = new ByteLocaleConverter();
139:
140:                // Perform Tests
141:                convertValueNoPattern(converter, defaultIntegerValue,
142:                        expectedValue);
143:                convertValueWithPattern(converter, defaultIntegerValue,
144:                        defaultIntegerPattern, expectedValue);
145:                convertInvalid(converter, null);
146:                convertNull(converter, null);
147:
148:            }
149:
150:            /**
151:             * Test Converter(locPattern) constructor
152:             * 
153:             * Uses the default locale, no default value
154:             * 
155:             */
156:            public void testConstructor_3() {
157:
158:                // ------------- Construct using localized pattern (default locale) --------
159:                converter = new ByteLocaleConverter(true);
160:
161:                // Perform Tests
162:                convertValueNoPattern(converter, defaultIntegerValue,
163:                        expectedValue);
164:                convertValueWithPattern(converter, defaultIntegerValue,
165:                        defaultIntegerPattern, expectedValue);
166:                convertInvalid(converter, null);
167:                convertNull(converter, null);
168:
169:            }
170:
171:            /**
172:             * Test Converter(Locale) constructor
173:             */
174:            public void testConstructor_4() {
175:
176:                // ------------- Construct using specified Locale --------
177:                converter = new ByteLocaleConverter(localizedLocale);
178:
179:                // Perform Tests
180:                convertValueNoPattern(converter, localizedIntegerValue,
181:                        expectedValue);
182:                convertValueWithPattern(converter, localizedIntegerValue,
183:                        defaultIntegerPattern, expectedValue);
184:                convertInvalid(converter, null);
185:                convertNull(converter, null);
186:
187:            }
188:
189:            /**
190:             * Test Converter(Locale, locPattern) constructor
191:             */
192:            public void testConstructor_5() {
193:
194:                // ------------- Construct using specified Locale --------
195:                converter = new ByteLocaleConverter(localizedLocale, true);
196:
197:                // Perform Tests
198:                convertValueNoPattern(converter, localizedIntegerValue,
199:                        expectedValue);
200:                convertValueWithPattern(converter, localizedIntegerValue,
201:                        localizedIntegerPattern, expectedValue);
202:                convertInvalid(converter, null);
203:                convertNull(converter, null);
204:
205:            }
206:
207:            /**
208:             * Test Converter(Locale, pattern) constructor
209:             */
210:            public void testConstructor_6() {
211:
212:                // ------------- Construct using specified Locale --------
213:                converter = new ByteLocaleConverter(localizedLocale,
214:                        defaultIntegerPattern);
215:
216:                // Perform Tests
217:                convertValueNoPattern(converter, localizedIntegerValue,
218:                        expectedValue);
219:                convertValueWithPattern(converter, localizedIntegerValue,
220:                        defaultIntegerPattern, expectedValue);
221:                convertInvalid(converter, null);
222:                convertNull(converter, null);
223:
224:            }
225:
226:            /**
227:             * Test Converter(Locale, pattern, locPattern) constructor
228:             */
229:            public void testConstructor_7() {
230:
231:                // ------------- Construct using specified Locale --------
232:                converter = new ByteLocaleConverter(localizedLocale,
233:                        localizedIntegerPattern, true);
234:
235:                // Perform Tests
236:                convertValueNoPattern(converter, localizedIntegerValue,
237:                        expectedValue);
238:                convertValueWithPattern(converter, localizedIntegerValue,
239:                        localizedIntegerPattern, expectedValue);
240:                convertInvalid(converter, null);
241:                convertNull(converter, null);
242:
243:            }
244:
245:            /**
246:             * Test Converter(defaultValue) constructor
247:             */
248:            public void testConstructor_8() {
249:
250:                // ------------- Construct using specified Locale --------
251:                converter = new ByteLocaleConverter(defaultValue);
252:
253:                // Perform Tests
254:                convertValueNoPattern(converter, defaultIntegerValue,
255:                        expectedValue);
256:                convertValueWithPattern(converter, defaultIntegerValue,
257:                        defaultIntegerPattern, expectedValue);
258:                convertInvalid(converter, defaultValue);
259:                convertNull(converter, defaultValue);
260:
261:            }
262:
263:            /**
264:             * Test Converter(defaultValue, locPattern) constructor
265:             */
266:            public void testConstructor_9() {
267:
268:                // ------------- Construct using specified Locale --------
269:                converter = new ByteLocaleConverter(defaultValue, true);
270:
271:                // Perform Tests
272:                convertValueNoPattern(converter, defaultIntegerValue,
273:                        expectedValue);
274:                convertValueWithPattern(converter, defaultIntegerValue,
275:                        defaultIntegerPattern, expectedValue);
276:                convertInvalid(converter, defaultValue);
277:                convertNull(converter, defaultValue);
278:
279:            }
280:
281:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.