aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2014-12-12 01:52:11 +0100
committerSamuel Tardieu <sam@rfc1149.net>2014-12-12 02:27:25 +0100
commit06901f30736d56f7fc42083ce8b5eac6f6d8b7b4 (patch)
tree365c4240675bf01739105651144e2dda8c5c8821 /tests
parentf1787fec5d99a97e212e12b0aa34732f7b69cf13 (diff)
downloadcgeo-06901f30736d56f7fc42083ce8b5eac6f6d8b7b4.zip
cgeo-06901f30736d56f7fc42083ce8b5eac6f6d8b7b4.tar.gz
cgeo-06901f30736d56f7fc42083ce8b5eac6f6d8b7b4.tar.bz2
Add tests for geocoders
Part of #4522.
Diffstat (limited to 'tests')
-rw-r--r--tests/src/cgeo/geocaching/location/GeocoderTest.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/src/cgeo/geocaching/location/GeocoderTest.java b/tests/src/cgeo/geocaching/location/GeocoderTest.java
new file mode 100644
index 0000000..cce093a
--- /dev/null
+++ b/tests/src/cgeo/geocaching/location/GeocoderTest.java
@@ -0,0 +1,43 @@
+package cgeo.geocaching.location;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import cgeo.CGeoTestCase;
+import cgeo.geocaching.CgeoApplication;
+
+import org.apache.commons.lang3.StringUtils;
+import org.assertj.core.data.Offset;
+
+import rx.Observable;
+
+import android.location.Address;
+import android.test.suitebuilder.annotation.Suppress;
+
+public class GeocoderTest extends CGeoTestCase {
+
+ private static final String TEST_ADDRESS = "46 rue Barrault, Paris, France";
+ private static final double TEST_LATITUDE = 48.82677;
+ private static final double TEST_LONGITUDE = 2.34644;
+ private static final Offset<Double> TEST_OFFSET = Offset.offset(0.00010);
+
+ @Suppress // Some emulators don't have access to Google Android geocoder
+ public void testAndroidGeocoder() {
+ testGeocoder(new AndroidGeocoder(CgeoApplication.getInstance()).getFromLocationName(TEST_ADDRESS), "Android");
+ }
+
+ public void testGCGeocoder() {
+ testGeocoder(GCGeocoder.getFromLocationName(TEST_ADDRESS), "GC");
+ }
+
+ public void testMapQuestGeocoder() {
+ testGeocoder(MapQuestGeocoder.getFromLocationName(TEST_ADDRESS), "MapQuest");
+ }
+
+ public static void testGeocoder(final Observable<Address> addressObservable, final String geocoder) {
+ final Address address = addressObservable.toBlocking().first();
+ assertThat(address.getLatitude()).as("latitude for " + geocoder + " geocoder").isCloseTo(TEST_LATITUDE, TEST_OFFSET);
+ assertThat(address.getLongitude()).as("longitude for " + geocoder + " geocoder").isCloseTo(TEST_LONGITUDE, TEST_OFFSET);
+ assertThat(StringUtils.lowerCase(address.getAddressLine(0))).as("street address for " + geocoder + " geocoder").startsWith("46 rue barrault");
+ }
+
+}