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