Source Code Cross Referenced for FormatTest.java in  » GIS » GeoTools-2.4.1 » org » geotools » measure » 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.measure 
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:         *    (C) 2002, Institut de Recherche pour le Développement
006:         *    
007:         *    This library is free software; you can redistribute it and/or
008:         *    modify it under the terms of the GNU Lesser General Public
009:         *    License as published by the Free Software Foundation; either
010:         *    version 2.1 of the License, or (at your option) any later version.
011:         *
012:         *    This library is distributed in the hope that it will be useful,
013:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         *    Lesser General Public License for more details.
016:         */
017:        package org.geotools.measure;
018:
019:        // J2SE dependencies
020:        import java.text.Format;
021:        import java.text.ParseException;
022:        import java.util.Date;
023:        import java.util.Locale;
024:        import java.util.TimeZone;
025:
026:        // JUnit dependencies
027:        import junit.framework.Test;
028:        import junit.framework.TestCase;
029:        import junit.framework.TestSuite;
030:        import junit.textui.TestRunner;
031:
032:        // OpenGIS dependencies
033:        import org.opengis.geometry.MismatchedDimensionException;
034:
035:        // Geotools dependencies
036:        import org.geotools.geometry.GeneralDirectPosition;
037:        import org.geotools.referencing.crs.DefaultCompoundCRS;
038:        import org.geotools.referencing.crs.AbstractCRS;
039:        import org.geotools.referencing.crs.DefaultGeographicCRS;
040:        import org.geotools.referencing.crs.DefaultTemporalCRS;
041:        import org.geotools.referencing.crs.DefaultVerticalCRS;
042:        import org.geotools.referencing.cs.DefaultTimeCS;
043:        import org.geotools.referencing.datum.DefaultTemporalDatum;
044:        import org.geotools.resources.Arguments;
045:
046:        /**
047:         * Tests formatting done by the {@link CoordinateFormat} class.
048:         *
049:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/test/java/org/geotools/measure/FormatTest.java $
050:         * @version $Id: FormatTest.java 27848 2007-11-12 13:10:32Z desruisseaux $
051:         * @author Martin Desruisseaux
052:         */
053:        public final class FormatTest extends TestCase {
054:            /**
055:             * Run the suite from the command line.
056:             */
057:            public static void main(String[] args) {
058:                org.geotools.util.logging.Logging.GEOTOOLS
059:                        .forceMonolineConsoleOutput();
060:                final Arguments arguments = new Arguments(args);
061:                args = arguments.getRemainingArguments(0);
062:                Locale.setDefault(arguments.locale);
063:                TestRunner.run(suite());
064:            }
065:
066:            /**
067:             * Returns the test suite.
068:             */
069:            public static Test suite() {
070:                return new TestSuite(FormatTest.class);
071:            }
072:
073:            /**
074:             * Constructs a test case with the given name.
075:             */
076:            public FormatTest(final String name) {
077:                super (name);
078:            }
079:
080:            /**
081:             * Test {@link AngleFormat}.
082:             */
083:            public void testAngleFormat() throws ParseException {
084:                AngleFormat f = new AngleFormat("DD.ddd\u00B0", Locale.CANADA);
085:                assertFormat("20.000\u00B0", new Angle(20.000), f);
086:                assertFormat("20.749\u00B0", new Angle(20.749), f);
087:                assertFormat("-12.247\u00B0", new Angle(-12.247), f);
088:                assertFormat("13.214\u00B0N", new Latitude(13.214), f);
089:                assertFormat("12.782\u00B0S", new Latitude(-12.782), f);
090:
091:                f = new AngleFormat("DD.ddd\u00B0", Locale.FRANCE);
092:                assertFormat("19,457\u00B0E", new Longitude(19.457), f);
093:                assertFormat("78,124\u00B0S", new Latitude(-78.124), f);
094:
095:                f = new AngleFormat("DDddd", Locale.CANADA);
096:                assertFormat("19457E", new Longitude(19.457), f);
097:                assertFormat("78124S", new Latitude(-78.124), f);
098:
099:                f = new AngleFormat("DD\u00B0MM.m", Locale.CANADA);
100:                assertFormat("12\u00B030.0", new Angle(12.50), f);
101:                assertFormat("-10\u00B015.0", new Angle(-10.25), f);
102:            }
103:
104:            /**
105:             * Formats an object and parse the result. The format
106:             * output is compared with the expected output.
107:             */
108:            private static void assertFormat(final String expected,
109:                    final Object value, final Format format)
110:                    throws ParseException {
111:                final String label = value.toString();
112:                final String text = format.format(value);
113:                assertEquals("Formatting of \"" + label + '"', expected, text);
114:                assertEquals("Parsing of \"" + label + '"', value, format
115:                        .parseObject(text));
116:            }
117:
118:            /**
119:             * Tests formatting of a 4-dimensional coordinates.
120:             */
121:            public void testCoordinateFormat() {
122:                final Date epoch = new Date(1041375600000L); // January 1st, 2003
123:                final DefaultTemporalDatum datum = new DefaultTemporalDatum(
124:                        "Time", epoch);
125:                final AbstractCRS crs = new DefaultCompoundCRS(
126:                        "WGS84 3D + time", DefaultGeographicCRS.WGS84,
127:                        DefaultVerticalCRS.ELLIPSOIDAL_HEIGHT,
128:                        new DefaultTemporalCRS("Time", datum,
129:                                DefaultTimeCS.DAYS));
130:                final CoordinateFormat format = new CoordinateFormat(
131:                        Locale.FRANCE);
132:                format.setCoordinateReferenceSystem(crs);
133:                format.setTimeZone(TimeZone.getTimeZone("GMT+01:00"));
134:                final GeneralDirectPosition position = new GeneralDirectPosition(
135:                        new double[] { 23.78, -12.74, 127.9, 3.2 });
136:                assertEquals("23°46,8'E 12°44,4'S 127,9\u00A0m 4 janv. 2003",
137:                        format.format(position));
138:                /*
139:                 * Try a point with wrong dimension.
140:                 */
141:                final GeneralDirectPosition wrong = new GeneralDirectPosition(
142:                        new double[] { 23.78, -12.74, 127.9, 3.2, 8.5 });
143:                try {
144:                    assertNotNull(format.format(wrong));
145:                    fail("Excepted a mismatched dimension exception.");
146:                } catch (MismatchedDimensionException e) {
147:                    // This is the expected dimension.
148:                }
149:                /*
150:                 * Try a null CRS. Should formats everything as numbers.
151:                 */
152:                format.setCoordinateReferenceSystem(null);
153:                assertEquals("23,78 -12,74 127,9 3,2", format.format(position));
154:                assertEquals("23,78 -12,74 127,9 3,2 8,5", format.format(wrong));
155:                /*
156:                 * Try again the original CRS, but different separator.
157:                 */
158:                format.setCoordinateReferenceSystem(crs);
159:                format.setTimeZone(TimeZone.getTimeZone("GMT+01:00"));
160:                format.setSeparator("; ");
161:                assertEquals(
162:                        "23°46,8'E; 12°44,4'S; 127,9\u00A0m; 4 janv. 2003",
163:                        format.format(position));
164:            }
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.