Source Code Cross Referenced for StringToNumberConverterTest.java in  » IDE-Eclipse » jface » org » eclipse » core » tests » databinding » conversion » 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 » IDE Eclipse » jface » org.eclipse.core.tests.databinding.conversion 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2007 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         ******************************************************************************/package org.eclipse.core.tests.databinding.conversion;
011:
012:        import java.math.BigInteger;
013:
014:        import junit.framework.TestCase;
015:
016:        import org.eclipse.core.databinding.conversion.StringToNumberConverter;
017:
018:        import com.ibm.icu.text.NumberFormat;
019:
020:        /**
021:         * @since 1.1
022:         */
023:        //TODO test for ICU4Js BigDecimal
024:        public class StringToNumberConverterTest extends TestCase {
025:            private NumberFormat numberFormat;
026:            private NumberFormat numberIntegerFormat;
027:
028:            /*
029:             * (non-Javadoc)
030:             * 
031:             * @see junit.framework.TestCase#setUp()
032:             */
033:            protected void setUp() throws Exception {
034:                super .setUp();
035:                numberFormat = NumberFormat.getInstance();
036:                numberIntegerFormat = NumberFormat.getIntegerInstance();
037:            }
038:
039:            public void testToTypes() throws Exception {
040:                assertEquals("Integer.class", Integer.class,
041:                        StringToNumberConverter.toInteger(false).getToType());
042:                assertEquals("Integer.TYPE", Integer.TYPE,
043:                        StringToNumberConverter.toInteger(true).getToType());
044:                assertEquals("Double.class", Double.class,
045:                        StringToNumberConverter.toDouble(false).getToType());
046:                assertEquals("Double.TYPE", Double.TYPE,
047:                        StringToNumberConverter.toDouble(true).getToType());
048:                assertEquals("Long.class", Long.class, StringToNumberConverter
049:                        .toLong(false).getToType());
050:                assertEquals("Long.TYPE", Long.TYPE, StringToNumberConverter
051:                        .toLong(true).getToType());
052:                assertEquals("Float.class", Float.class,
053:                        StringToNumberConverter.toFloat(false).getToType());
054:                assertEquals("Float.TYPE", Float.TYPE, StringToNumberConverter
055:                        .toFloat(true).getToType());
056:                assertEquals("BigInteger.TYPE", BigInteger.class,
057:                        StringToNumberConverter.toBigInteger().getToType());
058:            }
059:
060:            public void testFromTypeIsString() throws Exception {
061:                assertEquals(String.class, StringToNumberConverter.toInteger(
062:                        false).getFromType());
063:            }
064:
065:            public void testConvertsToBigInteger() throws Exception {
066:                BigInteger input = BigInteger.valueOf(1000);
067:
068:                StringToNumberConverter converter = StringToNumberConverter
069:                        .toBigInteger();
070:                BigInteger result = (BigInteger) converter.convert(numberFormat
071:                        .format(input));
072:
073:                assertEquals(input, result);
074:            }
075:
076:            public void testConvertsToInteger() throws Exception {
077:                Integer input = new Integer(1000);
078:
079:                StringToNumberConverter converter = StringToNumberConverter
080:                        .toInteger(false);
081:                Integer result = (Integer) converter
082:                        .convert(numberIntegerFormat.format(input.longValue()));
083:                assertEquals(input, result);
084:            }
085:
086:            public void testConvertsToDouble() throws Exception {
087:                Double input = new Double(1000);
088:
089:                StringToNumberConverter converter = StringToNumberConverter
090:                        .toDouble(false);
091:                Double result = (Double) converter.convert(numberFormat
092:                        .format(input.doubleValue()));
093:
094:                assertEquals(input, result);
095:            }
096:
097:            public void testConvertsToLong() throws Exception {
098:                Long input = new Long(1000);
099:
100:                StringToNumberConverter converter = StringToNumberConverter
101:                        .toLong(false);
102:                Long result = (Long) converter.convert(numberIntegerFormat
103:                        .format(input.longValue()));
104:
105:                assertEquals(input, result);
106:            }
107:
108:            public void testConvertsToFloat() throws Exception {
109:                Float input = new Float(1000);
110:
111:                StringToNumberConverter converter = StringToNumberConverter
112:                        .toFloat(false);
113:                Float result = (Float) converter.convert(numberFormat
114:                        .format(input.floatValue()));
115:
116:                assertEquals(input, result);
117:            }
118:
119:            public void testConvertedToIntegerPrimitive() throws Exception {
120:                Integer input = new Integer(1000);
121:
122:                StringToNumberConverter converter = StringToNumberConverter
123:                        .toInteger(true);
124:                Integer result = (Integer) converter
125:                        .convert(numberIntegerFormat.format(input.longValue()));
126:                assertEquals(input, result);
127:            }
128:
129:            public void testConvertsToDoublePrimitive() throws Exception {
130:                Double input = new Double(1000);
131:
132:                StringToNumberConverter converter = StringToNumberConverter
133:                        .toDouble(true);
134:                Double result = (Double) converter.convert(numberFormat
135:                        .format(input.doubleValue()));
136:
137:                assertEquals(input, result);
138:            }
139:
140:            public void testConvertsToLongPrimitive() throws Exception {
141:                Long input = new Long(1000);
142:
143:                StringToNumberConverter converter = StringToNumberConverter
144:                        .toLong(true);
145:                Long result = (Long) converter.convert(numberIntegerFormat
146:                        .format(input.longValue()));
147:
148:                assertEquals(input, result);
149:            }
150:
151:            public void testConvertsToFloatPrimitive() throws Exception {
152:                Float input = new Float(1000);
153:
154:                StringToNumberConverter converter = StringToNumberConverter
155:                        .toFloat(true);
156:                Float result = (Float) converter.convert(numberFormat
157:                        .format(input.floatValue()));
158:
159:                assertEquals(input, result);
160:            }
161:
162:            public void testReturnsNullBoxedTypeForEmptyString()
163:                    throws Exception {
164:                StringToNumberConverter converter = StringToNumberConverter
165:                        .toInteger(false);
166:                try {
167:                    assertNull(converter.convert(""));
168:                } catch (Exception e) {
169:                    fail("exception should not have been thrown");
170:                }
171:            }
172:
173:            public void testThrowsIllegalArgumentExceptionIfAskedToConvertNonString()
174:                    throws Exception {
175:                StringToNumberConverter converter = StringToNumberConverter
176:                        .toInteger(false);
177:                try {
178:                    converter.convert(new Integer(1));
179:                    fail("exception should have been thrown");
180:                } catch (IllegalArgumentException e) {
181:                }
182:            }
183:
184:            /**
185:             * Asserts a use case where the integer starts with a valid value but ends
186:             * in an unparsable format.
187:             * 
188:             * @throws Exception
189:             */
190:            public void testInvalidInteger() throws Exception {
191:                StringToNumberConverter converter = StringToNumberConverter
192:                        .toInteger(false);
193:
194:                try {
195:                    converter.convert("1 1 1");
196:                    fail("exception should have been thrown");
197:                } catch (IllegalArgumentException e) {
198:                }
199:            }
200:
201:            public void testThrowsIllegalArgumentExceptionIfNumberIsOutOfRange()
202:                    throws Exception {
203:                StringToNumberConverter converter = StringToNumberConverter
204:                        .toInteger(false);
205:                try {
206:                    converter.convert(numberFormat.format(Long.MAX_VALUE));
207:                    fail("exception should have been thrown");
208:                } catch (IllegalArgumentException e) {
209:                }
210:            }
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.