Source Code Cross Referenced for BaseLocaleConverterTestCase.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:        import junit.framework.TestCase;
021:        import java.util.Locale;
022:        import org.apache.commons.beanutils.locale.BaseLocaleConverter;
023:
024:        /**
025:         * Base Test Case for the DecimalLocaleConverter classes. This class doesn't
026:         * define any real tests; it just provides useful methods for the real
027:         * test case classes to inherit.
028:         *
029:         * @author Niall Pemberton
030:         * @version $Revision: 469728 $ $Date: 2006-11-01 01:08:34 +0000 (Wed, 01 Nov 2006) $
031:         */
032:
033:        public class BaseLocaleConverterTestCase extends TestCase {
034:
035:            // Original Default Locale
036:            protected Locale origLocale;
037:
038:            // Converter
039:            protected BaseLocaleConverter converter;
040:            protected Object result;
041:            protected Object defaultValue;
042:            protected Object expectedValue;
043:
044:            // Localized values
045:            protected Locale localizedLocale;
046:            protected String localizedDecimalPattern;
047:            protected String localizedIntegerPattern;
048:            protected String localizedDecimalValue;
049:            protected String localizedIntegerValue;
050:
051:            // Locale values
052:            protected Locale defaultLocale;
053:            protected String defaultDecimalPattern;
054:            protected String defaultIntegerPattern;
055:            protected String defaultDecimalValue;
056:            protected String defaultIntegerValue;
057:
058:            // Expected values
059:            protected String expectedDecimalValue;
060:            protected String expectedIntegerValue;
061:
062:            // ---------------------------------------------------------- Constructors
063:
064:            public BaseLocaleConverterTestCase(String name) {
065:                super (name);
066:            }
067:
068:            // -------------------------------------------------- Overall Test Methods
069:
070:            /**
071:             * Set up instance variables required by this test case.
072:             */
073:            public void setUp() throws Exception {
074:
075:                // Default Locale (Use US)
076:                defaultLocale = Locale.US;
077:                defaultDecimalPattern = "#,###.00";
078:                defaultIntegerPattern = "#,###";
079:                defaultDecimalValue = "1,234.56";
080:                defaultIntegerValue = "1,234";
081:
082:                // Use German Locale (uses different separators to US)
083:                localizedLocale = Locale.GERMAN;
084:                localizedDecimalPattern = "#.###,00";
085:                localizedIntegerPattern = "#.###";
086:                localizedDecimalValue = "1.234,56";
087:                localizedIntegerValue = "1.234";
088:
089:                // Expected Values
090:                expectedDecimalValue = "1234.56";
091:                expectedIntegerValue = "1234";
092:
093:                // Reset default to the one specified
094:                origLocale = Locale.getDefault();
095:
096:                // Initialize
097:                converter = null;
098:                result = null;
099:                defaultValue = null;
100:                expectedValue = null;
101:
102:                if (defaultLocale.equals(origLocale)) {
103:                    origLocale = null;
104:                } else {
105:                    // System.out.println("Changing default locale from " + origLocale + " to " + defaultLocale);
106:                    Locale.setDefault(defaultLocale);
107:                }
108:
109:            }
110:
111:            /**
112:             * Tear down instance variables required by this test case.
113:             */
114:            public void tearDown() {
115:
116:                converter = null;
117:                result = null;
118:                defaultValue = null;
119:                expectedValue = null;
120:
121:                // Set the Default Locale back to the original value 
122:                if (origLocale != null) {
123:                    // System.out.println("Restoring default locale to " + origLocale);
124:                    Locale.setDefault(origLocale);
125:                }
126:
127:            }
128:
129:            // -------------------------------------------------- Generic Test Methods
130:
131:            /**
132:             * Test Converting Value WITH a pattern
133:             */
134:            protected void convertValueWithPattern(
135:                    BaseLocaleConverter converter, Object value,
136:                    String pattern, Object expectedValue) {
137:                convertValueWithPattern(converter, "", value, pattern,
138:                        expectedValue);
139:            }
140:
141:            /**
142:             * Test Converting Value WITH a pattern
143:             */
144:            protected void convertValueWithPattern(
145:                    BaseLocaleConverter converter, String msgId, Object value,
146:                    String pattern, Object expectedValue) {
147:
148:                // Convert value with no pattern
149:                try {
150:                    result = converter.convert(value, pattern);
151:                } catch (Exception e) {
152:                    fail("Pattern conversion threw " + msgId + " threw " + e);
153:                }
154:                assertEquals("Check conversion value with pattern " + msgId,
155:                        expectedValue, result);
156:
157:            }
158:
159:            /**
160:             * Test Converting Value WITHOUT a pattern
161:             */
162:            protected void convertValueNoPattern(BaseLocaleConverter converter,
163:                    Object value, Object expectedValue) {
164:                convertValueNoPattern(converter, "", value, expectedValue);
165:            }
166:
167:            /**
168:             * Test Converting Value WITHOUT a pattern
169:             */
170:            protected void convertValueNoPattern(BaseLocaleConverter converter,
171:                    String msgId, Object value, Object expectedValue) {
172:
173:                // Convert value with no pattern
174:                try {
175:                    result = converter.convert(value);
176:                } catch (Exception e) {
177:                    fail("No Pattern conversion threw " + msgId + " threw " + e);
178:                }
179:                assertEquals("Check conversion value without pattern " + msgId,
180:                        expectedValue, result);
181:
182:            }
183:
184:            /**
185:             * Test Converting Value To a spcified Type
186:             */
187:            protected void convertValueToType(BaseLocaleConverter converter,
188:                    Class clazz, Object value, String pattern,
189:                    Object expectedValue) {
190:                convertValueToType(converter, "", clazz, value, pattern,
191:                        expectedValue);
192:            }
193:
194:            /**
195:             * Test Converting Value To a spcified Type
196:             */
197:            protected void convertValueToType(BaseLocaleConverter converter,
198:                    String msgId, Class clazz, Object value, String pattern,
199:                    Object expectedValue) {
200:
201:                // Convert value with no pattern
202:                try {
203:                    result = converter.convert(clazz, value, pattern);
204:                } catch (Exception e) {
205:                    fail("Type  conversion threw " + msgId + " threw " + e);
206:                }
207:                assertEquals("Check conversion value to type " + msgId,
208:                        expectedValue, result);
209:
210:            }
211:
212:            /**
213:             * Test Converting Null value.
214:             */
215:            protected void convertNull(BaseLocaleConverter converter,
216:                    Object expectedValue) {
217:                convertNull(converter, "", expectedValue);
218:            }
219:
220:            /**
221:             * Test Converting Null value.
222:             */
223:            protected void convertNull(BaseLocaleConverter converter,
224:                    String msgId, Object expectedValue) {
225:
226:                // Convert value with no pattern
227:                try {
228:                    result = converter.convert(null);
229:                } catch (Exception e) {
230:                    fail("Null conversion " + msgId + " threw " + e);
231:                }
232:
233:                if (expectedValue == null) {
234:                    assertNull("Check null conversion is null " + msgId
235:                            + " result=" + result, result);
236:                } else {
237:                    assertEquals("Check null conversion is default " + msgId,
238:                            expectedValue, result);
239:                }
240:
241:            }
242:
243:            /**
244:             * Test Converting an invalid value.
245:             */
246:            protected void convertInvalid(BaseLocaleConverter converter,
247:                    Object expectedValue) {
248:                convertInvalid(converter, "", expectedValue);
249:            }
250:
251:            /**
252:             * Test Converting an invalid value.
253:             */
254:            protected void convertInvalid(BaseLocaleConverter converter,
255:                    String msgId, Object expectedValue) {
256:
257:                // Convert value with no pattern
258:                try {
259:                    result = converter.convert("xyz");
260:                    if (expectedValue == null) {
261:                        fail("Expected ConversionException if no default value "
262:                                + msgId);
263:                    }
264:                } catch (Exception e) {
265:                    if (expectedValue != null) {
266:                        fail("Expected default value " + msgId + " threw " + e);
267:                    }
268:                }
269:
270:                if (expectedValue != null) {
271:                    assertEquals(
272:                            "Check invalid conversion is default " + msgId,
273:                            expectedValue, result);
274:                }
275:
276:            }
277:
278:            /**
279:             * This class isn't intended to perform any real tests; it just provides
280:             * methods for the real test cases to inherit. However junit complains
281:             * if a class named ..TestCase contains no test methods, so here we
282:             * define a dummy one to keep it happy.
283:             */
284:            public void testNothing() {
285:            }
286:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.