Source Code Cross Referenced for NumericConverterFactoryTest.java in  » GIS » GeoTools-2.4.1 » org » geotools » util » 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 » GIS » GeoTools 2.4.1 » org.geotools.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.geotools.util;
002:
003:        import java.math.BigDecimal;
004:        import java.math.BigInteger;
005:
006:        import junit.framework.TestCase;
007:
008:        public class NumericConverterFactoryTest extends TestCase {
009:
010:            NumericConverterFactory factory;
011:
012:            protected void setUp() throws Exception {
013:                factory = new NumericConverterFactory();
014:            }
015:
016:            public void testIntegral() throws Exception {
017:
018:                //to byte
019:                assertEquals(new Byte((byte) 127), convert(
020:                        new Byte((byte) 127), Byte.class));
021:                assertEquals(new Byte((byte) 127), convert(new Short(
022:                        (short) 127), Byte.class));
023:                assertEquals(new Byte((byte) 127), convert(new Integer(127),
024:                        Byte.class));
025:                assertEquals(new Byte((byte) 127), convert(new Long(127),
026:                        Byte.class));
027:                assertEquals(new Byte((byte) 127), convert(BigInteger
028:                        .valueOf(127), Byte.class));
029:
030:                //to short
031:                assertEquals(new Short((short) 127), convert(new Byte(
032:                        (byte) 127), Short.class));
033:                assertEquals(new Short((short) 127), convert(new Short(
034:                        (short) 127), Short.class));
035:                assertEquals(new Short((short) 127), convert(new Integer(127),
036:                        Short.class));
037:                assertEquals(new Short((short) 127), convert(new Long(127),
038:                        Short.class));
039:                assertEquals(new Short((short) 127), convert(BigInteger
040:                        .valueOf(127), Short.class));
041:
042:                //to integer
043:                assertEquals(new Integer(127), convert(new Byte((byte) 127),
044:                        Integer.class));
045:                assertEquals(new Integer(127), convert(new Short((short) 127),
046:                        Integer.class));
047:                assertEquals(new Integer(127), convert(new Integer(127),
048:                        Integer.class));
049:                assertEquals(new Integer(127), convert(new Long(127),
050:                        Integer.class));
051:                assertEquals(new Integer(127), convert(BigInteger.valueOf(127),
052:                        Integer.class));
053:
054:                //to long
055:                assertEquals(new Long(127), convert(new Byte((byte) 127),
056:                        Long.class));
057:                assertEquals(new Long(127), convert(new Short((short) 127),
058:                        Long.class));
059:                assertEquals(new Long(127), convert(new Integer(127),
060:                        Long.class));
061:                assertEquals(new Long(127), convert(new Long(127), Long.class));
062:                assertEquals(new Long(127), convert(BigInteger.valueOf(127),
063:                        Long.class));
064:
065:                //to big integer
066:                assertEquals(BigInteger.valueOf(127), convert(new Byte(
067:                        (byte) 127), BigInteger.class));
068:                assertEquals(BigInteger.valueOf(127), convert(new Short(
069:                        (short) 127), BigInteger.class));
070:                assertEquals(BigInteger.valueOf(127), convert(new Integer(127),
071:                        BigInteger.class));
072:                assertEquals(BigInteger.valueOf(127), convert(new Long(127),
073:                        BigInteger.class));
074:                assertEquals(BigInteger.valueOf(127), convert(BigInteger
075:                        .valueOf(127), BigInteger.class));
076:            }
077:
078:            public void testFloat() throws Exception {
079:                //to float
080:                assertEquals(new Float(127.127), convert(new Float(127.127),
081:                        Float.class));
082:                assertEquals(new Float(127.127), convert(new Double(127.127),
083:                        Float.class));
084:                assertEquals(new Float(127.127), convert(
085:                        new BigDecimal(127.127), Float.class));
086:
087:                //to double
088:                assertEquals(new Double(127.127).doubleValue(),
089:                        ((Double) convert(new Float(127.127), Double.class))
090:                                .doubleValue(), 0.001);
091:                assertEquals(new Double(127.127), convert(new Double(127.127),
092:                        Double.class));
093:                assertEquals(new Double(127.127), convert(new BigDecimal(
094:                        127.127), Double.class));
095:
096:                //to big decimal
097:                assertEquals(new BigDecimal(127.127).doubleValue(),
098:                        ((BigDecimal) convert(new Float(127.127),
099:                                BigDecimal.class)).doubleValue(), 0.001);
100:                assertEquals(new BigDecimal(127.127), convert(new Double(
101:                        127.127), BigDecimal.class));
102:                assertEquals(new BigDecimal(127.127), convert(new BigDecimal(
103:                        127.127), BigDecimal.class));
104:            }
105:
106:            public void testIntegralToFloat() throws Exception {
107:                assertEquals(new Float(127.0), convert(new Byte((byte) 127),
108:                        Float.class));
109:                assertEquals(new Float(127.0), convert(new Short((short) 127),
110:                        Float.class));
111:                assertEquals(new Float(127.0), convert(new Integer(127),
112:                        Float.class));
113:                assertEquals(new Float(127.0), convert(new Long(127),
114:                        Float.class));
115:                assertEquals(new Float(127.0), convert(BigInteger.valueOf(127),
116:                        Float.class));
117:
118:                assertEquals(new Double(127.0), convert(new Byte((byte) 127),
119:                        Double.class));
120:                assertEquals(new Double(127.0), convert(new Short((short) 127),
121:                        Double.class));
122:                assertEquals(new Double(127.0), convert(new Integer(127),
123:                        Double.class));
124:                assertEquals(new Double(127.0), convert(new Long(127),
125:                        Double.class));
126:                assertEquals(new Double(127.0), convert(
127:                        BigInteger.valueOf(127), Double.class));
128:
129:                assertEquals(new BigDecimal(127.0), convert(
130:                        new Byte((byte) 127), BigDecimal.class));
131:                assertEquals(new BigDecimal(127.0), convert(new Short(
132:                        (short) 127), BigDecimal.class));
133:                assertEquals(new BigDecimal(127.0), convert(new Integer(127),
134:                        BigDecimal.class));
135:                assertEquals(new BigDecimal(127.0), convert(new Long(127),
136:                        BigDecimal.class));
137:                assertEquals(new BigDecimal(127.0), convert(BigInteger
138:                        .valueOf(127), BigDecimal.class));
139:            }
140:
141:            public void testFloatToIntegral() throws Exception {
142:                //to byte
143:                assertEquals(new Byte((byte) 127), convert(new Float(127.127),
144:                        Byte.class));
145:                assertEquals(new Byte((byte) 127), convert(new Double(127.127),
146:                        Byte.class));
147:                assertEquals(new Byte((byte) 127), convert(new BigDecimal(
148:                        127.127), Byte.class));
149:
150:                //to short
151:                assertEquals(new Short((short) 127), convert(
152:                        new Float(127.127), Short.class));
153:                assertEquals(new Short((short) 127), convert(
154:                        new Double(127.127), Short.class));
155:                assertEquals(new Short((short) 127), convert(new BigDecimal(
156:                        127.127), Short.class));
157:
158:                //to integer
159:                assertEquals(new Integer(127), convert(new Float(127.127),
160:                        Integer.class));
161:                assertEquals(new Integer(127), convert(new Double(127.127),
162:                        Integer.class));
163:                assertEquals(new Integer(127), convert(new BigDecimal(127.127),
164:                        Integer.class));
165:
166:                //to long
167:                assertEquals(new Long(127), convert(new Float(127.127),
168:                        Long.class));
169:                assertEquals(new Long(127), convert(new Double(127.127),
170:                        Long.class));
171:                assertEquals(new Long(127), convert(new BigDecimal(127.127),
172:                        Long.class));
173:
174:                //to big integer
175:                assertEquals(BigInteger.valueOf(127), convert(
176:                        new Float(127.127), BigInteger.class));
177:                assertEquals(BigInteger.valueOf(127), convert(new Double(
178:                        127.127), BigInteger.class));
179:                assertEquals(BigInteger.valueOf(127), convert(new BigDecimal(
180:                        127.127), BigInteger.class));
181:
182:            }
183:
184:            Object convert(Object source, Class target) throws Exception {
185:                return factory.createConverter(source.getClass(), target, null)
186:                        .convert(source, target);
187:            }
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.