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


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2003-2006, Geotools Project Managment Committee (PMC)
005:         *
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation; either
009:         *    version 2.1 of the License, or (at your option) any later version.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         */
016:        package org.geotools.feature.visitor;
017:
018:        import junit.framework.TestCase;
019:
020:        /*
021:         So far CalcResult contains the following conversion methods which call
022:         getValue() and then convert to the type we want. The ones marked below with a
023:         "!" haven't really found an implementation yet and no tests have been
024:         written.  They should work under normal circumstances, but will likely explode:
025:         public int toInt()
026:         public double toDouble();
027:         public String toString();
028:         public long toLong();
029:         public float toFloat();
030:         ! public Geometry toGeometry();
031:         ! public Point toPoint();
032:         ! public Set toSet();
033:         ! public List toList();
034:         ! public Object[] toArray();
035:         ! public Map toMap();
036:         */
037:
038:        //TODO: add more tests as needed
039:        /**
040:         * Purpose: these tests ensure that the output of CalcResult converts as expected.
041:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/test/java/org/geotools/feature/visitor/CalcResultTest.java $
042:         */
043:        public class CalcResultTest extends TestCase {
044:            MockCalcResult result = new MockCalcResult();
045:            Integer val1 = new Integer(4);
046:            Long val2 = new Long(5);
047:            Float val3 = new Float(6.0);
048:            Double val4 = new Double(7.0);
049:            String val5 = new String("8");
050:            String val6 = new String("Random text of arbitrary complexity.");
051:
052:            public void testInt() {
053:                //int --> int
054:                result.setValue(val1);
055:                assertEquals((int) 4, result.toInt());
056:
057:                //long --> int
058:                result.setValue(val2);
059:                assertEquals((int) 5, result.toInt());
060:
061:                //float --> int
062:                result.setValue(val3);
063:                assertEquals((int) 6, result.toInt());
064:
065:                //double --> int
066:                result.setValue(val4);
067:                assertEquals((int) 7, result.toInt());
068:
069:                //string --> int (a string that looks like a number, should we add this functionality?)
070:                result.setValue(val5);
071:                assertEquals((int) 0, result.toInt());
072:
073:                //string --> int (a real string which clearly isn't an int, so we expect nothing good)
074:                result.setValue(val6);
075:                assertEquals((int) 0, result.toInt());
076:            }
077:
078:            public void testLong() {
079:                //int --> long
080:                result.setValue(val1);
081:                assertEquals((long) 4, result.toLong());
082:
083:                //long --> long
084:                result.setValue(val2);
085:                assertEquals((long) 5, result.toLong());
086:
087:                //float --> long
088:                result.setValue(val3);
089:                assertEquals((long) 6, result.toLong());
090:
091:                //double --> long
092:                result.setValue(val4);
093:                assertEquals((long) 7, result.toLong());
094:
095:                //string --> long (a string that looks like a number, should we add this functionality?)
096:                result.setValue(val5);
097:                assertEquals((long) 0, result.toLong());
098:
099:                //string --> long (a real string which clearly isn't an int, so we expect nothing good)
100:                result.setValue(val6);
101:                assertEquals((long) 0, result.toLong());
102:            }
103:
104:            public void testFloat() {
105:                //int --> float
106:                result.setValue(val1);
107:                assertEquals((float) 4, result.toFloat(), 0);
108:
109:                //long --> float
110:                result.setValue(val2);
111:                assertEquals((float) 5, result.toFloat(), 0);
112:
113:                //float --> float
114:                result.setValue(val3);
115:                assertEquals((float) 6, result.toFloat(), 0);
116:
117:                //double --> float
118:                result.setValue(val4);
119:                assertEquals((float) 7, result.toFloat(), 0);
120:
121:                //string --> float (a string that looks like a number, should we add this functionality?)
122:                result.setValue(val5);
123:                assertEquals((float) 0, result.toFloat(), 0);
124:
125:                //string --> float (a real string which clearly isn't an int, so we expect nothing good)
126:                result.setValue(val6);
127:                assertEquals((float) 0, result.toFloat(), 0);
128:            }
129:
130:            public void testDouble() {
131:                //int --> double
132:                result.setValue(val1);
133:                assertEquals((double) 4, result.toDouble(), 0);
134:
135:                //long --> double
136:                result.setValue(val2);
137:                assertEquals((double) 5, result.toDouble(), 0);
138:
139:                //float --> double
140:                result.setValue(val3);
141:                assertEquals((double) 6, result.toDouble(), 0);
142:
143:                //double --> double
144:                result.setValue(val4);
145:                assertEquals((double) 7, result.toDouble(), 0);
146:
147:                //string --> double (a string that looks like a number, should we add this functionality?)
148:                result.setValue(val5);
149:                assertEquals((double) 0, result.toDouble(), 0);
150:
151:                //string --> double (a real string which clearly isn't an int, so we expect nothing good)
152:                result.setValue(val6);
153:                assertEquals((double) 0, result.toDouble(), 0);
154:            }
155:
156:            public void testString() {
157:                //int --> string
158:                result.setValue(val1);
159:                assertEquals("4", result.toString());
160:
161:                //long --> string
162:                result.setValue(val2);
163:                assertEquals("5", result.toString());
164:
165:                //float --> string
166:                result.setValue(val3);
167:                assertEquals("6.0", result.toString());
168:
169:                //double --> string
170:                result.setValue(val4);
171:                assertEquals("7.0", result.toString());
172:
173:                //string --> string
174:                result.setValue(val5);
175:                assertEquals("8", result.toString());
176:
177:                //string --> string
178:                result.setValue(val6);
179:                assertEquals("Random text of arbitrary complexity.", result
180:                        .toString());
181:            }
182:
183:            /**
184:             * A simple results set which allows us to test the AbstractCalcResult type
185:             * conversions
186:             */
187:            public class MockCalcResult extends AbstractCalcResult {
188:                Object value;
189:
190:                public MockCalcResult() {
191:                }
192:
193:                public Object getValue() {
194:                    return value;
195:                }
196:
197:                public void setValue(Object value) {
198:                    this.value = value;
199:                }
200:            }
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.