1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.strategy.parser.location;
|
10
|
|
11
|
import org.apache.log4j.Logger;
|
12
|
import org.junit.Assert;
|
13
|
import org.junit.Before;
|
14
|
import org.junit.BeforeClass;
|
15
|
import org.junit.Test;
|
16
|
|
17
|
import eu.etaxonomy.cdm.strategy.parser.location.CoordinateConverter.ConversionResults;
|
18
|
|
19
|
/**
|
20
|
* @author a.mueller
|
21
|
* @date 07.06.2010
|
22
|
*
|
23
|
*/
|
24
|
public class CoordinateConverterTest {
|
25
|
private static final Logger logger = Logger.getLogger(CoordinateConverterTest.class);
|
26
|
|
27
|
private CoordinateConverter coordinateConverter;
|
28
|
|
29
|
/**
|
30
|
* @throws java.lang.Exception
|
31
|
*/
|
32
|
@BeforeClass
|
33
|
public static void setUpBeforeClass() throws Exception {
|
34
|
}
|
35
|
|
36
|
/**
|
37
|
* @throws java.lang.Exception
|
38
|
*/
|
39
|
@Before
|
40
|
public void setUp() throws Exception {
|
41
|
coordinateConverter = new CoordinateConverter();
|
42
|
}
|
43
|
|
44
|
// ************************ TESTS ********************************************** /
|
45
|
|
46
|
/**
|
47
|
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.location.CoordinateConverter#CoordinateConverter()}.
|
48
|
*/
|
49
|
@Test
|
50
|
public void testCoordinateConverter() {
|
51
|
Assert.assertNotNull("converter should not be null",coordinateConverter);
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.location.CoordinateConverter#tryConvert(java.lang.String)}.
|
56
|
*/
|
57
|
@Test
|
58
|
public void testTryConvert() {
|
59
|
ConversionResults conversionResults = coordinateConverter.tryConvert("35\u00B034'20\"S");
|
60
|
Assert.assertTrue(conversionResults.conversionComments, conversionResults.patternRecognised);
|
61
|
Assert.assertTrue("Southern must be negative", conversionResults.convertedCoord < 0);
|
62
|
Assert.assertFalse("Southern must be latitude", conversionResults.isLongitude);
|
63
|
|
64
|
conversionResults = coordinateConverter.tryConvert("35\u00BA34.744");
|
65
|
Assert.assertTrue(conversionResults.conversionComments, conversionResults.patternRecognised);
|
66
|
Assert.assertNull("Longitude must be undefined", conversionResults.isLongitude);
|
67
|
|
68
|
conversionResults = coordinateConverter.tryConvert("95\u00B034.744");
|
69
|
Assert.assertTrue("Longitude must be defined", conversionResults.isLongitude);
|
70
|
|
71
|
|
72
|
conversionResults = coordinateConverter.tryConvert("-35\u00B034'55.67S");
|
73
|
Assert.assertTrue(conversionResults.conversionComments, conversionResults.patternRecognised);
|
74
|
|
75
|
conversionResults = coordinateConverter.tryConvert("35\u00B011'34.744SN");
|
76
|
Assert.assertTrue(conversionResults.conversionComments, conversionResults.patternRecognised);
|
77
|
|
78
|
conversionResults = coordinateConverter.tryConvert("35\u00B011'34.744SW");
|
79
|
Assert.assertTrue("Western must be longitude", conversionResults.isLongitude);
|
80
|
|
81
|
conversionResults = coordinateConverter.tryConvert("35\u00B0 1'34.744SW");
|
82
|
Assert.assertTrue("Pattern with whitespace must be recognised", conversionResults.patternRecognised);
|
83
|
Assert.assertTrue("Pattern with whitespace must be recognised", conversionResults.conversionSuccessful);
|
84
|
|
85
|
conversionResults = coordinateConverter.tryConvert("35D11M34.744S");
|
86
|
Assert.assertNull("isLongitude must be undefined. S stands for second.", conversionResults.isLongitude);
|
87
|
|
88
|
conversionResults = coordinateConverter.tryConvert("35\u00B0 1\u00B434.744SW");
|
89
|
Assert.assertTrue("Pattern with acute accent must be recognised", conversionResults.patternRecognised);
|
90
|
Assert.assertTrue("Pattern with acute accent must be recognised", conversionResults.conversionSuccessful);
|
91
|
|
92
|
conversionResults = coordinateConverter.tryConvert("35\u00B01\u00B434\u00B4\u00B4W");
|
93
|
Assert.assertTrue("Pattern with acute accent for seconds must be recognised", conversionResults.patternRecognised);
|
94
|
Assert.assertTrue("Pattern with acute accent for seconds must be recognised", conversionResults.conversionSuccessful);
|
95
|
|
96
|
}
|
97
|
|
98
|
/**
|
99
|
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.location.CoordinateConverter#addCustomPattern(eu.etaxonomy.cdm.strategy.parser.location.CoordinateConverter.CustomPatternIn)}.
|
100
|
*/
|
101
|
@Test
|
102
|
public void testAddCustomPattern() {
|
103
|
logger.warn("testAddCustomPattern not yet implemented"); // TODO
|
104
|
}
|
105
|
|
106
|
}
|