diff options
Diffstat (limited to 'tests/src')
| -rw-r--r-- | tests/src/cgeo/geocaching/connector/gc/GCLoginTest.java | 6 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/location/GeocoderTest.java | 48 |
2 files changed, 51 insertions, 3 deletions
diff --git a/tests/src/cgeo/geocaching/connector/gc/GCLoginTest.java b/tests/src/cgeo/geocaching/connector/gc/GCLoginTest.java index 07ba646..fc23ab3 100644 --- a/tests/src/cgeo/geocaching/connector/gc/GCLoginTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/GCLoginTest.java @@ -6,10 +6,10 @@ import cgeo.geocaching.enumerations.StatusCode; import org.apache.commons.lang3.StringUtils; -import junit.framework.TestCase; - import android.test.suitebuilder.annotation.Suppress; +import junit.framework.TestCase; + public class GCLoginTest extends TestCase { final GCLogin instance = GCLogin.getInstance(); @@ -20,7 +20,7 @@ public class GCLoginTest extends TestCase { assertThat(instance.login()).isEqualTo(StatusCode.NO_ERROR); } - public void testHomeLocation() { + public static void testHomeLocation() { assertThat(StringUtils.isNotBlank(GCLogin.retrieveHomeLocation())).isTrue(); } diff --git a/tests/src/cgeo/geocaching/location/GeocoderTest.java b/tests/src/cgeo/geocaching/location/GeocoderTest.java new file mode 100644 index 0000000..f53c074 --- /dev/null +++ b/tests/src/cgeo/geocaching/location/GeocoderTest.java @@ -0,0 +1,48 @@ +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.annotation.TargetApi; +import android.location.Address; +import android.location.Geocoder; +import android.os.Build; + +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.00050); + + @TargetApi(Build.VERSION_CODES.GINGERBREAD) + public static void testAndroidGeocoder() { + // Some emulators don't have access to Google Android geocoder + if (Geocoder.isPresent()) { + testGeocoder(new AndroidGeocoder(CgeoApplication.getInstance()).getFromLocationName(TEST_ADDRESS), "Android"); + } + } + + public static void testGCGeocoder() { + testGeocoder(GCGeocoder.getFromLocationName(TEST_ADDRESS), "GC"); + } + + public static 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"); + } + +} |
