Revision 138715e0
Added by Andreas Müller over 3 years ago
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/location/PointTest.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2009 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
... | ... | |
32 | 32 |
|
33 | 33 |
private Point point1; |
34 | 34 |
private Point point2; |
35 |
|
|
35 |
|
|
36 | 36 |
private Integer errorRadius; |
37 | 37 |
private Double longitude1; |
38 | 38 |
private Double latitude1; |
39 | 39 |
private Double longitude2; |
40 | 40 |
private Double latitude2; |
41 |
|
|
41 |
|
|
42 | 42 |
private ReferenceSystem referenceSystem; |
43 |
|
|
44 |
|
|
43 |
|
|
44 |
|
|
45 | 45 |
/** |
46 | 46 |
* @throws java.lang.Exception |
47 | 47 |
*/ |
... | ... | |
59 | 59 |
public void setUp() throws Exception { |
60 | 60 |
longitude1 = 23.123556; |
61 | 61 |
latitude1 = -13.975556; |
62 |
|
|
62 |
|
|
63 | 63 |
longitude2 = 28.48556; |
64 | 64 |
latitude2 = 12.656; |
65 |
|
|
65 |
|
|
66 | 66 |
errorRadius = 5; |
67 | 67 |
referenceSystem = ReferenceSystem.GOOGLE_EARTH(); |
68 |
|
|
68 |
|
|
69 | 69 |
point1 = Point.NewInstance(longitude1, latitude1, referenceSystem, errorRadius); |
70 | 70 |
point2 = Point.NewInstance(); |
71 |
|
|
72 |
|
|
73 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 | 74 |
} |
75 | 75 |
|
76 |
//********************** TESTS *****************************
|
|
77 |
|
|
76 |
//********************** TESTS ***************************** |
|
77 |
|
|
78 | 78 |
@Test |
79 | 79 |
public void testNewInstance(){ |
80 | 80 |
Assert.assertNotNull("ReferenceSystem must not be null", referenceSystem); |
... | ... | |
85 | 85 |
Assert.assertEquals("", latitude1, point1.getLatitude()); |
86 | 86 |
Assert.assertEquals("", errorRadius, point1.getErrorRadius()); |
87 | 87 |
Assert.assertEquals("", referenceSystem, point1.getReferenceSystem()); |
88 |
|
|
88 |
|
|
89 | 89 |
Assert.assertNull("LongitudeSexagesimal should be null", point2.getLongitudeSexagesimal()); |
90 | 90 |
Assert.assertNull("LatitudeSexagesimal should be null", point2.getLatitudeSexagesimal()); |
91 | 91 |
} |
... | ... | |
105 | 105 |
point2.setLatitude(null); |
106 | 106 |
Assert.assertEquals(null, point2.getLatitude()); |
107 | 107 |
} |
108 |
|
|
108 |
|
|
109 | 109 |
@Test |
110 | 110 |
public void testGetSetErrorRadius(){ |
111 | 111 |
point2.setErrorRadius(7); |
... | ... | |
113 | 113 |
point2.setErrorRadius(null); |
114 | 114 |
Assert.assertEquals(null, point2.getErrorRadius()); |
115 | 115 |
} |
116 |
|
|
116 |
|
|
117 | 117 |
@Test |
118 | 118 |
public void testGetSetReferenceSystem(){ |
119 | 119 |
ReferenceSystem newRefSystem = ReferenceSystem.NewInstance(); |
... | ... | |
122 | 122 |
point2.setReferenceSystem(null); |
123 | 123 |
Assert.assertEquals(null, point2.getReferenceSystem()); |
124 | 124 |
} |
125 |
|
|
125 |
|
|
126 | 126 |
@Test |
127 | 127 |
public void testGetLongitudeSexagesimal(){ |
128 | 128 |
Assert.assertEquals("23\u00B07'24.801\"E", point1.getLongitudeSexagesimal().toString(true, false)); |
129 |
|
|
130 |
|
|
129 |
|
|
130 |
|
|
131 | 131 |
point2.setLongitudeSexagesimal(Sexagesimal.NewInstance(5, 22, null, Direction.WEST)); |
132 | 132 |
Assert.assertEquals((Integer)22, point2.getLongitudeSexagesimal().minutes); |
133 | 133 |
Assert.assertEquals((Integer)0, point2.getLongitudeSexagesimal().seconds); |
134 |
|
|
135 |
Double latitudeDouble = -45.57389326;
|
|
134 |
|
|
135 |
Double latitudeDouble = -45.57389326; |
|
136 | 136 |
point1.setLatitudeSexagesimal(Sexagesimal.valueOf(latitudeDouble, true)); |
137 | 137 |
//Not true because of rounding errors |
138 | 138 |
// Assert.assertEquals("latitudeDouble must be equal", latitudeDouble, point1.getLatitude()); |
139 |
|
|
139 |
|
|
140 | 140 |
Sexagesimal sexagesimal1 = Sexagesimal.NewInstance(0, 0, 0, Direction.WEST); |
141 | 141 |
Sexagesimal sexagesimal2 = Sexagesimal.NewInstance(2, 2, 2, Direction.WEST); |
142 | 142 |
Assert.assertNotSame("", sexagesimal1, sexagesimal2); |
143 |
|
|
144 |
|
|
143 |
|
|
144 |
|
|
145 | 145 |
} |
146 | 146 |
|
147 | 147 |
@Test |
... | ... | |
178 | 178 |
try { |
179 | 179 |
point1.setLatitudeByParsing("37\u00B07'44\"N"); |
180 | 180 |
Assert.assertEquals("Result should be 37\u00B07'44\"N not 37\u00B07'44.999\"N", "37\u00B07'44\"N", point1.getLatitudeSexagesimal().toString()); |
181 |
|
|
181 |
|
|
182 | 182 |
point1.setLatitudeByParsing("37\u00B07'45\"N"); |
183 | 183 |
Assert.assertEquals("Result should be 37\u00B07'45\"N not 37\u00B07'45.\"N", "37\u00B07'45\"N", point1.getLatitudeSexagesimal().toString()); |
184 |
|
|
184 |
|
|
185 | 185 |
} catch (ParseException e) { |
186 | 186 |
Assert.fail("No parsing error should occur"); |
187 | 187 |
} |
188 |
|
|
189 |
|
|
190 |
|
|
191 | 188 |
|
192 | 189 |
|
193 |
|
|
194 |
|
|
195 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 | 196 |
// Assert.assertTrue("Southern must be negative", conversionResults.convertedCoord < 0); |
197 | 197 |
// Assert.assertFalse("Southern must be latitude", conversionResults.isLongitude); |
198 | 198 |
// |
... | ... | |
203 | 203 |
// conversionResults = coordinateConverter.tryConvert("95\u00B034.744"); |
204 | 204 |
// Assert.assertTrue("Longitude must be defined", conversionResults.isLongitude); |
205 | 205 |
// |
206 |
//
|
|
206 |
// |
|
207 | 207 |
// conversionResults = coordinateConverter.tryConvert("-35\u00B034'55.67S"); |
208 | 208 |
// Assert.assertTrue(conversionResults.conversionComments, conversionResults.patternRecognised); |
209 | 209 |
// |
... | ... | |
212 | 212 |
// |
213 | 213 |
// conversionResults = coordinateConverter.tryConvert("35\u00B011'34.744SW"); |
214 | 214 |
// Assert.assertTrue("Western must be longitude", conversionResults.isLongitude); |
215 |
//
|
|
215 |
// |
|
216 | 216 |
// conversionResults = coordinateConverter.tryConvert("35D11M34.744S"); |
217 | 217 |
// Assert.assertNull("isLongitude must be undefined. S stands for second.", conversionResults.isLongitude); |
218 | 218 |
|
219 | 219 |
} |
220 |
|
|
220 |
|
|
221 | 221 |
|
222 | 222 |
@Test |
223 | 223 |
public void testDoubleParsing(){ |
... | ... | |
233 | 233 |
} catch (ParseException e) { |
234 | 234 |
Assert.fail("No parsing error should occur"); |
235 | 235 |
} |
236 |
|
|
236 |
|
|
237 | 237 |
try { |
238 | 238 |
point1.setLongitudeByParsing("-120.4"); |
239 | 239 |
Assert.assertEquals("", "-120.4", point1.getLongitude().toString()); |
... | ... | |
248 | 248 |
} catch (ParseException e) { |
249 | 249 |
Assert.assertTrue("Latitude can not be > 90", true); |
250 | 250 |
} |
251 |
|
|
251 |
|
|
252 | 252 |
try { |
253 | 253 |
point1.setLongitudeByParsing("191"); |
254 | 254 |
Assert.fail("Longitude can be > 180°"); |
... | ... | |
261 | 261 |
Assert.fail("String '2°39'38,5956\"S'should be parsable"); |
262 | 262 |
} |
263 | 263 |
} |
264 |
|
|
264 |
|
|
265 | 265 |
/** |
266 | 266 |
* I don't exactly know what should happen here. |
267 |
* Please see http://dev.e-taxonomy.eu/trac/ticket/2267#comment:3 on why this test was created
|
|
268 |
*
|
|
267 |
* Please see https://dev.e-taxonomy.eu/redmine/issues/2267#comment:3 on why this test was created
|
|
268 |
* |
|
269 | 269 |
* @throws ParseException |
270 | 270 |
*/ |
271 | 271 |
@Test |
... | ... | |
274 | 274 |
point1.setLatitudeByParsing(example); |
275 | 275 |
Assert.assertEquals(example, point1.getLatitudeSexagesimal().toString()); |
276 | 276 |
} |
277 |
|
|
277 |
|
|
278 | 278 |
@Test |
279 | 279 |
public void testStaticParsing(){ |
280 | 280 |
try{ |
... | ... | |
285 | 285 |
Assert.fail("No parsing error should occur"); |
286 | 286 |
} |
287 | 287 |
} |
288 |
|
|
289 |
|
|
290 |
|
|
288 |
|
|
289 |
|
|
290 |
|
|
291 | 291 |
} |
Also available in: Unified diff
replace links to trac tickets by links to redmine tickets in javadoc