aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/traccar/geocoder
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/traccar/geocoder')
-rw-r--r--src/test/java/org/traccar/geocoder/AddressFormatTest.java33
-rw-r--r--src/test/java/org/traccar/geocoder/GeocoderTest.java88
2 files changed, 121 insertions, 0 deletions
diff --git a/src/test/java/org/traccar/geocoder/AddressFormatTest.java b/src/test/java/org/traccar/geocoder/AddressFormatTest.java
new file mode 100644
index 000000000..0cc5168ef
--- /dev/null
+++ b/src/test/java/org/traccar/geocoder/AddressFormatTest.java
@@ -0,0 +1,33 @@
+package org.traccar.geocoder;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class AddressFormatTest {
+
+ private void test(Address address, String format, String expected) {
+ assertEquals(expected, new AddressFormat(format).format(address));
+ }
+
+ @Test
+ public void testFormat() {
+
+ Address address = new Address();
+ address.setCountry("NZ");
+ address.setSettlement("Auckland");
+ address.setStreet("Queen St");
+ address.setHouse("1A");
+
+ test(address, "%h %r %t %d %s %c %p", "1A Queen St Auckland NZ");
+ test(address, "%h %r %t", "1A Queen St Auckland");
+ test(address, "%h %r, %t", "1A Queen St, Auckland");
+ test(address, "%h %r, %t %p", "1A Queen St, Auckland");
+ test(address, "%t %d %c", "Auckland NZ");
+ test(address, "%t, %d, %c", "Auckland, NZ");
+ test(address, "%d %c", "NZ");
+ test(address, "%d, %c", "NZ");
+ test(address, "%p", "");
+ }
+
+}
diff --git a/src/test/java/org/traccar/geocoder/GeocoderTest.java b/src/test/java/org/traccar/geocoder/GeocoderTest.java
new file mode 100644
index 000000000..85d9bf62f
--- /dev/null
+++ b/src/test/java/org/traccar/geocoder/GeocoderTest.java
@@ -0,0 +1,88 @@
+package org.traccar.geocoder;
+
+import java.util.Locale;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class GeocoderTest {
+
+ static {
+ Locale.setDefault(Locale.US);
+ }
+
+ @Ignore
+ @Test
+ public void testGoogle() {
+ Geocoder geocoder = new GoogleGeocoder(null, null, 0, new AddressFormat());
+ String address = geocoder.getAddress(31.776797, 35.211489, null);
+ assertEquals("1 Ibn Shaprut St, Jerusalem, Jerusalem District, IL", address);
+ }
+
+ @Ignore
+ @Test
+ public void testNominatim() {
+ Geocoder geocoder = new NominatimGeocoder(null, null, null, 0, new AddressFormat());
+ String address = geocoder.getAddress(40.7337807, -73.9974401, null);
+ assertEquals("35 West 9th Street, NYC, New York, US", address);
+ }
+
+ @Ignore
+ @Test
+ public void testGisgraphy() {
+ Geocoder geocoder = new GisgraphyGeocoder(new AddressFormat());
+ String address = geocoder.getAddress(48.8530000, 2.3400000, null);
+ assertEquals("Rue du Jardinet, Paris, Île-de-France, FR", address);
+ }
+
+ @Ignore
+ @Test
+ public void testOpenCage() {
+ Geocoder geocoder = new OpenCageGeocoder(
+ "http://api.opencagedata.com/geocode/v1", "SECRET", 0, new AddressFormat());
+ String address = geocoder.getAddress(34.116302, -118.051519, null);
+ assertEquals("Charleston Road, California, US", address);
+ }
+
+ @Ignore
+ @Test
+ public void testGeocodeFarm() {
+ Geocoder geocoder = new GeocodeFarmGeocoder(null, null, 0, new AddressFormat());
+ String address = geocoder.getAddress(34.116302, -118.051519, null);
+ assertEquals("Estrella Avenue, Arcadia, California, United States", address);
+ }
+
+ @Ignore
+ @Test
+ public void testGeocodeXyz() {
+ Geocoder geocoder = new GeocodeXyzGeocoder(null, 0, new AddressFormat());
+ String address = geocoder.getAddress(34.116302, -118.051519, null);
+ assertEquals("605 ESTRELLA AVE, ARCADIA, California United States of America, US", address);
+ }
+
+ @Ignore
+ @Test
+ public void testBan() {
+ Geocoder geocoder = new BanGeocoder(0, new AddressFormat("%f [%d], %c"));
+ String address = geocoder.getAddress(48.8575, 2.2944, null);
+ assertEquals("8 Avenue Gustave Eiffel 75007 Paris [75, Paris, Île-de-France], FR", address);
+ }
+
+ @Ignore
+ @Test
+ public void testHere() {
+ Geocoder geocoder = new HereGeocoder("", "", null, 0, new AddressFormat());
+ String address = geocoder.getAddress(48.8575, 2.2944, null);
+ assertEquals("6 Avenue Gustave Eiffel, Paris, Île-de-France, FRA", address);
+ }
+
+ @Ignore
+ @Test
+ public void testMapmyIndia() {
+ Geocoder geocoder = new MapmyIndiaGeocoder("", "", 0, new AddressFormat("%f"));
+ String address = geocoder.getAddress(28.6129602407977, 77.2294557094574, null);
+ assertEquals("New Delhi, Delhi. 1 m from India Gate pin-110001 (India)", address);
+ }
+}