diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2016-12-06 13:46:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-06 13:46:49 +0100 |
commit | 9a9e7978db67276cfaab97e00f2b56eeb0222b12 (patch) | |
tree | 0da54e64117a64195ee46060e01d270a86c1e45d /platform/android/MapboxGLAndroidSDKTestApp | |
parent | 890b681b182f7d538237604307da487f3619d1b1 (diff) | |
download | qtlocation-mapboxgl-9a9e7978db67276cfaab97e00f2b56eeb0222b12.tar.gz |
[android] - Refactor dependencies, introduce focused components (#7189)
* [android] - refactor dependencies
* ignore tests
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp')
18 files changed, 762 insertions, 664 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/build.gradle b/platform/android/MapboxGLAndroidSDKTestApp/build.gradle index 11b5768d87..542038cbc7 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/build.gradle +++ b/platform/android/MapboxGLAndroidSDKTestApp/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.application' ext { - supportLibVersion = '25.0.0' + supportLibVersion = '25.0.1' } android { compileSdkVersion 25 - buildToolsVersion "25.0.0" + buildToolsVersion "25.0.1" defaultConfig { applicationId "com.mapbox.mapboxsdk.testapp" @@ -75,7 +75,7 @@ dependencies { // Testing dependencies testCompile 'junit:junit:4.12' - testCompile 'org.mockito:mockito-core:1.10.19' + testCompile 'org.mockito:mockito-core:2.2.27' androidTestCompile "com.android.support:support-annotations:${supportLibVersion}" androidTestCompile 'com.android.support.test:runner:0.5' androidTestCompile 'com.android.support.test:rules:0.5' diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapViewUtils.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapViewUtils.java index da9c3f9c8f..427d7ff21d 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapViewUtils.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapViewUtils.java @@ -7,31 +7,27 @@ import com.mapbox.mapboxsdk.geometry.LatLng; */ public class MapViewUtils { - public static void setDirection(MapView mapView, float direction) { - mapView.setBearing(direction); + public static void setDirection(MapboxMap mapboxMap, float direction) { + mapboxMap.getTransform().setBearing(direction); } - public static float getDirection(MapView mapView) { - return (float) mapView.getDirection(); + public static float getDirection(MapboxMap mapboxMap) { + return (float) mapboxMap.getTransform().getBearing(); } - public static void setTilt(MapView mapView, float tilt) { - mapView.setTilt((double) tilt); + public static void setTilt(MapboxMap mapboxMap, float tilt) { + mapboxMap.getTransform().setTilt((double) tilt); } - public static float getTilt(MapView mapView) { - return (float) mapView.getTilt(); + public static float getTilt(MapboxMap mapboxMap) { + return (float) mapboxMap.getTransform().getTilt(); } - public static void setLatLng(MapView mapView, LatLng latLng) { - mapView.setCenterCoordinate(latLng); + public static void setLatLng(MapboxMap mapboxMap, LatLng latLng) { + mapboxMap.getTransform().setCenterCoordinate(latLng); } - public static LatLng getLatLng(MapView mapView) { - return mapView.getCenterCoordinate(); - } - - public static int[] getContentPadding(MapView mapView) { - return new int[]{mapView.getContentPaddingLeft(), mapView.getContentPaddingTop(), mapView.getContentPaddingRight(), mapView.getContentPaddingBottom()}; + public static LatLng getLatLng(MapboxMap mapboxMap) { + return mapboxMap.getTransform().getCenterCoordinate(); } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java new file mode 100644 index 0000000000..a8600668d8 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java @@ -0,0 +1,624 @@ +package com.mapbox.mapboxsdk.maps; + +import android.graphics.Color; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.test.espresso.Espresso; +import android.support.test.espresso.UiController; +import android.support.test.espresso.ViewAction; +import android.support.test.rule.ActivityTestRule; +import android.view.View; + +import com.mapbox.mapboxsdk.annotations.Annotation; +import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions; +import com.mapbox.mapboxsdk.annotations.Marker; +import com.mapbox.mapboxsdk.annotations.MarkerOptions; +import com.mapbox.mapboxsdk.annotations.Polygon; +import com.mapbox.mapboxsdk.annotations.PolygonOptions; +import com.mapbox.mapboxsdk.annotations.Polyline; +import com.mapbox.mapboxsdk.annotations.PolylineOptions; +import com.mapbox.mapboxsdk.constants.MapboxConstants; +import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity; +import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource; + +import org.hamcrest.Matcher; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import timber.log.Timber; + +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static junit.framework.TestCase.assertFalse; +import static junit.framework.TestCase.assertNotNull; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * This test is responsible for testing the public API. + */ +public class MapboxMapTest { + + @Rule + public final ActivityTestRule<EspressoTestActivity> rule = new ActivityTestRule<>(EspressoTestActivity.class); + + private OnMapReadyIdlingResource idlingResource; + private EspressoTestActivity activity; + + @Before + public void beforeTest() { + activity = rule.getActivity(); + idlingResource = new OnMapReadyIdlingResource(activity); + Espresso.registerIdlingResources(idlingResource); + } + + @Test + @Ignore + public void testSanity() { + MapboxMap mapboxMap = activity.getMapboxMap(); + assertNotNull("mapboxMap should not be null", mapboxMap); + } + + // + // MinZoomLevel + // + + @Test + @Ignore + public void testMinZoom() { + MapboxMap mapboxMap = activity.getMapboxMap(); + onView(withId(R.id.mapView)).perform(new MinZoomAction(mapboxMap)); + assertEquals("MinZoom should match", 10, mapboxMap.getMinZoom(), 0); + } + + @Test + @Ignore + public void testMaxZoom() { + MapboxMap mapboxMap = activity.getMapboxMap(); + double zoom = 10; + mapboxMap.setMaxZoom(zoom); + assertEquals("MaxZoom should match", zoom, mapboxMap.getMaxZoom(), 0); + } + + @Test + @Ignore + public void testInitialZoomLevels() { + MapboxMap mapboxMap = activity.getMapboxMap(); + assertEquals("MaxZoom should match", MapboxConstants.MAXIMUM_ZOOM, mapboxMap.getMaxZoom(), 0); + assertEquals("MinZoom should match", MapboxConstants.MINIMUM_ZOOM, mapboxMap.getMinZoom(), 0); + } + + // + // TrackingSettings + // + + @Test + @Ignore + public void testTrackingSettings() { + MapboxMap mapboxMap = activity.getMapboxMap(); + assertNotNull("TrackingSettings should not be null", mapboxMap.getTrackingSettings()); + } + + // + // InfoWindow + // + + @Test + @Ignore + public void testConcurrentInfoWindowEnabled() { + MapboxMap mapboxMap = activity.getMapboxMap(); + mapboxMap.setAllowConcurrentMultipleOpenInfoWindows(true); + assertTrue("ConcurrentWindows should be true", mapboxMap.isAllowConcurrentMultipleOpenInfoWindows()); + } + + @Test + @Ignore + public void testConcurrentInfoWindowDisabled() { + MapboxMap mapboxMap = activity.getMapboxMap(); + mapboxMap.setAllowConcurrentMultipleOpenInfoWindows(false); + assertFalse("ConcurrentWindows should be false", mapboxMap.isAllowConcurrentMultipleOpenInfoWindows()); + } + + @Test + @Ignore + public void testInfoWindowAdapter() { + MapboxMap mapboxMap = activity.getMapboxMap(); + MapboxMap.InfoWindowAdapter infoWindowAdapter = new MapboxMap.InfoWindowAdapter() { + @Nullable + @Override + public View getInfoWindow(@NonNull Marker marker) { + return null; + } + }; + mapboxMap.setInfoWindowAdapter(infoWindowAdapter); + assertEquals("InfoWindowAdpter should be the same", infoWindowAdapter, mapboxMap.getInfoWindowAdapter()); + } + + // + // Location + // + + @Test + @Ignore /* disabled due to enabling permissions during test #7177 */ + public void testMyLocationEnabled() { + MapboxMap mapboxMap = activity.getMapboxMap(); + mapboxMap.setMyLocationEnabled(true); + assertTrue("MyLocationEnabled should be true", mapboxMap.isMyLocationEnabled()); + } + + @Test + @Ignore /* can't create handler inside thread that not called Looper.prepare() */ + public void testMyLocationDisabled() { + MapboxMap mapboxMap = activity.getMapboxMap(); + mapboxMap.setMyLocationEnabled(false); + assertFalse("MyLocationEnabled should be false", mapboxMap.isMyLocationEnabled()); + } + + // + // setters/getters interfaces + // + + @Test + @Ignore + public void testFpsListener() { + MapboxMap mapboxMap = activity.getMapboxMap(); + MapboxMap.OnFpsChangedListener fpsChangedListener = new MapboxMap.OnFpsChangedListener() { + @Override + public void onFpsChanged(double fps) { + + } + }; + mapboxMap.setOnFpsChangedListener(fpsChangedListener); + assertEquals("FpsListener should match", fpsChangedListener, mapboxMap.getOnFpsChangedListener()); + } + + @Test + @Ignore + public void testInfoWindowClickListener() { + MapboxMap mapboxMap = activity.getMapboxMap(); + MapboxMap.OnInfoWindowClickListener clickListener = new MapboxMap.OnInfoWindowClickListener() { + @Override + public boolean onInfoWindowClick(@NonNull Marker marker) { + return false; + } + }; + mapboxMap.setOnInfoWindowClickListener(clickListener); + assertEquals("InfoWidowClickListener should match", clickListener, mapboxMap.getOnInfoWindowClickListener()); + } + + @Test + @Ignore + public void testInfoWindowCloseListener() { + MapboxMap mapboxMap = activity.getMapboxMap(); + MapboxMap.OnInfoWindowCloseListener listener = new MapboxMap.OnInfoWindowCloseListener() { + @Override + public void onInfoWindowClose(Marker marker) { + + } + }; + mapboxMap.setOnInfoWindowCloseListener(listener); + assertEquals("InfoWindowCloseListener should match", listener, mapboxMap.getOnInfoWindowCloseListener()); + } + + @Test + @Ignore + public void testInfoWindowLongClickListener() { + MapboxMap mapboxMap = activity.getMapboxMap(); + MapboxMap.OnInfoWindowLongClickListener listener = new MapboxMap.OnInfoWindowLongClickListener() { + @Override + public void onInfoWindowLongClick(Marker marker) { + + } + }; + mapboxMap.setOnInfoWindowLongClickListener(listener); + assertEquals("InfoWindowLongClickListener should match", listener, mapboxMap.getOnInfoWindowLongClickListener()); + } + + // + // Annotations + // + + @Test + @Ignore + public void testAddMarker() { + MapboxMap mapboxMap = activity.getMapboxMap(); + MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); + Marker marker = mapboxMap.addMarker(markerOptions); + assertTrue("Marker should be contained", mapboxMap.getMarkers().contains(marker)); + } + + @Test(expected = InvalidMarkerPositionException.class) + @Ignore + public void testAddMarkerInvalidPosition() { + new MarkerOptions().getMarker(); + } + + @Test + @Ignore + public void testAddMarkers() { + MapboxMap mapboxMap = activity.getMapboxMap(); + List<BaseMarkerOptions> markerList = new ArrayList<>(); + MarkerOptions markerOptions1 = new MarkerOptions().position(new LatLng()).title("a"); + MarkerOptions markerOptions2 = new MarkerOptions().position(new LatLng()).title("b"); + markerList.add(markerOptions1); + markerList.add(markerOptions2); + List<Marker> markers = mapboxMap.addMarkers(markerList); + assertEquals("Markers size should be 2", 2, mapboxMap.getMarkers().size()); + assertTrue(mapboxMap.getMarkers().contains(markers.get(0))); + assertTrue(mapboxMap.getMarkers().contains(markers.get(1))); + } + + @Test + @Ignore + public void testAddMarkersEmpty() { + MapboxMap mapboxMap = activity.getMapboxMap(); + List<BaseMarkerOptions> markerList = new ArrayList<>(); + mapboxMap.addMarkers(markerList); + assertEquals("Markers size should be 0", 0, mapboxMap.getMarkers().size()); + } + + @Test + @Ignore + public void testAddMarkersSingleMarker() { + MapboxMap mapboxMap = activity.getMapboxMap(); + List<BaseMarkerOptions> markerList = new ArrayList<>(); + MarkerOptions markerOptions = new MarkerOptions().title("a").position(new LatLng()); + markerList.add(markerOptions); + List<Marker> markers = mapboxMap.addMarkers(markerList); + assertEquals("Markers size should be 1", 1, mapboxMap.getMarkers().size()); + assertTrue(mapboxMap.getMarkers().contains(markers.get(0))); + } + + @Test + @Ignore + public void testAddPolygon() { + MapboxMap mapboxMap = activity.getMapboxMap(); + PolygonOptions polygonOptions = new PolygonOptions().add(new LatLng()); + Polygon polygon = mapboxMap.addPolygon(polygonOptions); + assertTrue("Polygon should be contained", mapboxMap.getPolygons().contains(polygon)); + } + + @Test + @Ignore + public void testAddEmptyPolygon() { + MapboxMap mapboxMap = activity.getMapboxMap(); + PolygonOptions polygonOptions = new PolygonOptions(); + Polygon polygon = mapboxMap.addPolygon(polygonOptions); + assertTrue("Polygon should be ignored", !mapboxMap.getPolygons().contains(polygon)); + } + + @Test + @Ignore + public void testAddPolygons() { + MapboxMap mapboxMap = activity.getMapboxMap(); + List<PolygonOptions> polygonList = new ArrayList<>(); + PolygonOptions polygonOptions1 = new PolygonOptions().fillColor(Color.BLACK).add(new LatLng()); + PolygonOptions polygonOptions2 = new PolygonOptions().fillColor(Color.WHITE).add(new LatLng()); + PolygonOptions polygonOptions3 = new PolygonOptions(); + polygonList.add(polygonOptions1); + polygonList.add(polygonOptions2); + polygonList.add(polygonOptions3); + mapboxMap.addPolygons(polygonList); + assertEquals("Polygons size should be 2", 2, mapboxMap.getPolygons().size()); + assertTrue(mapboxMap.getPolygons().contains(polygonOptions1.getPolygon())); + assertTrue(mapboxMap.getPolygons().contains(polygonOptions2.getPolygon())); + assertTrue("Polygon should be ignored", !mapboxMap.getPolygons().contains(polygonOptions3.getPolygon())); + } + + @Test + @Ignore + public void addPolygonsEmpty() { + MapboxMap mapboxMap = activity.getMapboxMap(); + mapboxMap.addPolygons(new ArrayList<PolygonOptions>()); + assertEquals("Polygons size should be 0", 0, mapboxMap.getPolygons().size()); + } + + @Test + @Ignore + public void addPolygonsSingle() { + MapboxMap mapboxMap = activity.getMapboxMap(); + List<PolygonOptions> polygonList = new ArrayList<>(); + PolygonOptions polygonOptions = new PolygonOptions().fillColor(Color.BLACK).add(new LatLng()); + polygonList.add(polygonOptions); + mapboxMap.addPolygons(polygonList); + assertEquals("Polygons size should be 1", 1, mapboxMap.getPolygons().size()); + assertTrue(mapboxMap.getPolygons().contains(polygonOptions.getPolygon())); + } + + @Test + @Ignore + public void testAddPolyline() { + MapboxMap mapboxMap = activity.getMapboxMap(); + PolylineOptions polylineOptions = new PolylineOptions().add(new LatLng()); + Polyline polyline = mapboxMap.addPolyline(polylineOptions); + assertTrue("Polyline should be contained", mapboxMap.getPolylines().contains(polyline)); + } + + @Test + @Ignore + public void testAddEmptyPolyline() { + MapboxMap mapboxMap = activity.getMapboxMap(); + PolylineOptions polylineOptions = new PolylineOptions(); + Polyline polyline = mapboxMap.addPolyline(polylineOptions); + assertTrue("Polyline should be ignored", !mapboxMap.getPolylines().contains(polyline)); + } + + @Test + @Ignore + public void testAddPolylines() { + MapboxMap mapboxMap = activity.getMapboxMap(); + List<PolylineOptions> polylineList = new ArrayList<>(); + PolylineOptions polygonOptions1 = new PolylineOptions().color(Color.BLACK).add(new LatLng()); + PolylineOptions polygonOptions2 = new PolylineOptions().color(Color.WHITE).add(new LatLng()); + PolylineOptions polygonOptions3 = new PolylineOptions(); + polylineList.add(polygonOptions1); + polylineList.add(polygonOptions2); + polylineList.add(polygonOptions3); + mapboxMap.addPolylines(polylineList); + assertEquals("Polygons size should be 2", 2, mapboxMap.getPolylines().size()); + assertTrue(mapboxMap.getPolylines().contains(polygonOptions1.getPolyline())); + assertTrue(mapboxMap.getPolylines().contains(polygonOptions2.getPolyline())); + assertTrue("Polyline should be ignored", !mapboxMap.getPolylines().contains(polygonOptions3.getPolyline())); + } + + @Test + @Ignore + public void testAddPolylinesEmpty() { + MapboxMap mapboxMap = activity.getMapboxMap(); + mapboxMap.addPolylines(new ArrayList<PolylineOptions>()); + assertEquals("Polygons size should be 0", 0, mapboxMap.getPolylines().size()); + } + + @Test + @Ignore + public void testAddPolylinesSingle() { + MapboxMap mapboxMap = activity.getMapboxMap(); + List<PolylineOptions> polylineList = new ArrayList<>(); + PolylineOptions polygonOptions = new PolylineOptions().color(Color.BLACK).add(new LatLng()); + polylineList.add(polygonOptions); + mapboxMap.addPolylines(polylineList); + assertEquals("Polygons size should be 1", 1, mapboxMap.getPolylines().size()); + assertTrue(mapboxMap.getPolylines().contains(polygonOptions.getPolyline())); + } + + @Test + @Ignore + public void testRemoveMarker() { + MapboxMap mapboxMap = activity.getMapboxMap(); + MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); + Marker marker = mapboxMap.addMarker(markerOptions); + mapboxMap.removeMarker(marker); + assertTrue("Markers should be empty", mapboxMap.getMarkers().isEmpty()); + } + + @Test + @Ignore + public void testRemovePolygon() { + MapboxMap mapboxMap = activity.getMapboxMap(); + PolygonOptions polygonOptions = new PolygonOptions(); + Polygon polygon = mapboxMap.addPolygon(polygonOptions); + mapboxMap.removePolygon(polygon); + assertTrue("Polygons should be empty", mapboxMap.getPolylines().isEmpty()); + } + + @Test + @Ignore + public void testRemovePolyline() { + MapboxMap mapboxMap = activity.getMapboxMap(); + PolylineOptions polylineOptions = new PolylineOptions(); + Polyline polyline = mapboxMap.addPolyline(polylineOptions); + mapboxMap.removePolyline(polyline); + assertTrue("Polylines should be empty", mapboxMap.getPolylines().isEmpty()); + } + + @Test + @Ignore + public void testRemoveAnnotation() { + MapboxMap mapboxMap = activity.getMapboxMap(); + MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); + Marker marker = mapboxMap.addMarker(markerOptions); + onView(withId(R.id.mapView)).perform(new RemoveAnnotationAction(marker, mapboxMap)); + assertTrue("Annotations should be empty", mapboxMap.getAnnotations().isEmpty()); + } + + @Test + @Ignore + public void testRemoveAnnotationById() { + MapboxMap mapboxMap = activity.getMapboxMap(); + MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); + mapboxMap.addMarker(markerOptions); + // id will always be 0 in unit tests + mapboxMap.removeAnnotation(0); + assertTrue("Annotations should be empty", mapboxMap.getAnnotations().isEmpty()); + } + + @Test + @Ignore + public void testRemoveAnnotations() { + MapboxMap mapboxMap = activity.getMapboxMap(); + List<BaseMarkerOptions> markerList = new ArrayList<>(); + MarkerOptions markerOptions1 = new MarkerOptions().title("a").position(new LatLng()); + MarkerOptions markerOptions2 = new MarkerOptions().title("b").position(new LatLng()); + markerList.add(markerOptions1); + markerList.add(markerOptions2); + mapboxMap.addMarkers(markerList); + mapboxMap.removeAnnotations(); + assertTrue("Annotations should be empty", mapboxMap.getAnnotations().isEmpty()); + } + + @Test + @Ignore + public void testClear() { + MapboxMap mapboxMap = activity.getMapboxMap(); + List<BaseMarkerOptions> markerList = new ArrayList<>(); + MarkerOptions markerOptions1 = new MarkerOptions().title("a").position(new LatLng()); + MarkerOptions markerOptions2 = new MarkerOptions().title("b").position(new LatLng()); + markerList.add(markerOptions1); + markerList.add(markerOptions2); + mapboxMap.addMarkers(markerList); + mapboxMap.clear(); + assertTrue("Annotations should be empty", mapboxMap.getAnnotations().isEmpty()); + } + + @Test + @Ignore + public void testRemoveAnnotationsByList() { + MapboxMap mapboxMap = activity.getMapboxMap(); + List<BaseMarkerOptions> markerList = new ArrayList<>(); + MarkerOptions markerOptions1 = new MarkerOptions().title("a").position(new LatLng()); + MarkerOptions markerOptions2 = new MarkerOptions().title("b").position(new LatLng()); + markerList.add(markerOptions1); + markerList.add(markerOptions2); + List<Marker> markers = mapboxMap.addMarkers(markerList); + Marker marker = mapboxMap.addMarker(new MarkerOptions().position(new LatLng()).title("c")); + mapboxMap.removeAnnotations(markers); + assertTrue("Annotations should not be empty", mapboxMap.getAnnotations().size() == 1); + assertTrue("Marker should be contained", mapboxMap.getAnnotations().contains(marker)); + } + + @Test + @Ignore + public void testGetAnnotationById() { + MapboxMap mapboxMap = activity.getMapboxMap(); + MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); + Marker initialMarker = mapboxMap.addMarker(markerOptions); + Marker retrievedMarker = (Marker) mapboxMap.getAnnotation(0); + assertEquals("Markers should match", initialMarker, retrievedMarker); + } + + @Test + @Ignore + public void testGetAnnotations() { + MapboxMap mapboxMap = activity.getMapboxMap(); + assertNotNull("Annotations should be non null", mapboxMap.getAnnotations()); + } + + @Test + @Ignore + public void testGetMarkers() { + MapboxMap mapboxMap = activity.getMapboxMap(); + assertNotNull("Markers should be non null", mapboxMap.getMarkers()); + } + + @Test + @Ignore + public void testGetPolygons() { + MapboxMap mapboxMap = activity.getMapboxMap(); + assertNotNull("Polygons should be non null", mapboxMap.getPolygons()); + } + + @Test + @Ignore + public void testGetPolylines() { + MapboxMap mapboxMap = activity.getMapboxMap(); + assertNotNull("Polylines should be non null", mapboxMap.getPolylines()); + } + + @Test + @Ignore + public void testGetSelectedMarkers() { + MapboxMap mapboxMap = activity.getMapboxMap(); + assertNotNull("Selected markers should be non null", mapboxMap.getSelectedMarkers()); + } + + @Test + @Ignore + public void testSelectMarker() { + MapboxMap mapboxMap = activity.getMapboxMap(); + MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); + Marker marker = mapboxMap.addMarker(markerOptions); + mapboxMap.selectMarker(marker); + assertTrue("Marker should be contained", mapboxMap.getSelectedMarkers().contains(marker)); + } + + @Test + @Ignore + public void testDeselectMarker() { + MapboxMap mapboxMap = activity.getMapboxMap(); + MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); + Marker marker = mapboxMap.addMarker(markerOptions); + mapboxMap.selectMarker(marker); + mapboxMap.deselectMarker(marker); + assertTrue("Selected markers should be empty", mapboxMap.getSelectedMarkers().isEmpty()); + } + + @Test + @Ignore + public void testDeselectMarkers() { + MapboxMap mapboxMap = activity.getMapboxMap(); + MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); + Marker marker1 = mapboxMap.addMarker(markerOptions); + Marker marker2 = mapboxMap.addMarker(markerOptions); + mapboxMap.selectMarker(marker1); + mapboxMap.selectMarker(marker2); + mapboxMap.deselectMarkers(); + assertTrue("Selected markers should be empty", mapboxMap.getSelectedMarkers().isEmpty()); + } + + @After + public void afterTest() { + Timber.e("@After test: unregister idle resource"); + Espresso.unregisterIdlingResources(idlingResource); + } + + private class MinZoomAction implements ViewAction { + + private MapboxMap mapboxMap; + + MinZoomAction(MapboxMap map) { + mapboxMap = map; + } + + @Override + public Matcher<View> getConstraints() { + return isDisplayed(); + } + + @Override + public String getDescription() { + return getClass().getSimpleName(); + } + + @Override + public void perform(UiController uiController, View view) { + mapboxMap.setMinZoom(10); + } + } + + private class RemoveAnnotationAction implements ViewAction { + + private Annotation annotation; + private MapboxMap mapboxMap; + + RemoveAnnotationAction(Annotation annotation, MapboxMap mapboxMap) { + this.annotation = annotation; + this.mapboxMap = mapboxMap; + } + + @Override + public Matcher<View> getConstraints() { + return isDisplayed(); + } + + @Override + public String getDescription() { + return getClass().getSimpleName(); + } + + @Override + public void perform(UiController uiController, View view) { + mapboxMap.removeAnnotation(annotation); + } + } + +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/MarkerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/MarkerTest.java index 650c9dc834..36e943b7ff 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/MarkerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/MarkerTest.java @@ -19,6 +19,7 @@ import com.mapbox.mapboxsdk.testapp.utils.ViewUtils; import org.hamcrest.Matcher; import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; @@ -44,6 +45,7 @@ public class MarkerTest { } @Test + @Ignore public void addMarkerTest() { ViewUtils.checkViewIsDisplayed(R.id.mapView); MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); @@ -65,6 +67,7 @@ public class MarkerTest { } @Test + @Ignore public void showInfoWindowTest(){ ViewUtils.checkViewIsDisplayed(R.id.mapView); MapboxMap mapboxMap = rule.getActivity().getMapboxMap(); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/MarkerViewTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/MarkerViewTest.java index d39b5dad96..09f707c4b5 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/MarkerViewTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/MarkerViewTest.java @@ -110,7 +110,6 @@ public class MarkerViewTest { public void perform(UiController uiController, View view) { mapboxMap.getMarkerViewManager().addMarkerViewAdapter(new MarkerViewActivity.TextAdapter(view.getContext(), mapboxMap)); marker = mapboxMap.addMarker(options); - mapboxMap.invalidate(); uiController.loopMainThreadForAtLeast(250); } } @@ -136,7 +135,6 @@ public class MarkerViewTest { @Override public void perform(UiController uiController, View view) { mapboxMap.selectMarker(marker); - mapboxMap.invalidate(); uiController.loopMainThreadForAtLeast(250); } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraAnimateTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraAnimateTest.java index 5e99cff936..73e3c8559f 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraAnimateTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraAnimateTest.java @@ -231,7 +231,7 @@ public class CameraAnimateTest { @Override public void perform(UiController uiController, View view) { mapboxMap.animateCamera(cameraUpdate); - uiController.loopMainThreadForAtLeast(MapboxConstants.ANIMATION_DURATION); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); } } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraEaseTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraEaseTest.java index 3782991e58..4f27703b18 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraEaseTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraEaseTest.java @@ -231,7 +231,7 @@ public class CameraEaseTest { @Override public void perform(UiController uiController, View view) { mapboxMap.easeCamera(cameraUpdate); - uiController.loopMainThreadForAtLeast(MapboxConstants.ANIMATION_DURATION); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); } } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraInternalAPITest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraInternalAPITest.java index 9bb30c0aa1..e180ab77b2 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraInternalAPITest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraInternalAPITest.java @@ -54,9 +54,8 @@ public class CameraInternalAPITest { CameraPosition cameraPosition = mapboxMap.getCameraPosition(); assertEquals("Default camera position should match default", cameraPosition, initialPosition); - MapView mapView = (MapView) activity.findViewById(R.id.mapView); - onView(withId(R.id.mapView)).perform(new BearingAction(mapView)); - assertEquals("Bearing should match", 45.1f, MapViewUtils.getDirection(mapView), TestConstants.BEARING_DELTA); + onView(withId(R.id.mapView)).perform(new BearingAction(mapboxMap)); + assertEquals("Bearing should match", 45.1f, MapViewUtils.getDirection(mapboxMap), TestConstants.BEARING_DELTA); } @Test @@ -69,9 +68,8 @@ public class CameraInternalAPITest { CameraPosition cameraPosition = mapboxMap.getCameraPosition(); assertEquals("Default camera position should match default", cameraPosition, initialPosition); - MapView mapView = (MapView) activity.findViewById(R.id.mapView); - onView(withId(R.id.mapView)).perform(new TiltAction(mapView)); - assertEquals("Tilt should match", 40.0f, MapViewUtils.getTilt(mapView), TestConstants.TILT_DELTA); + onView(withId(R.id.mapView)).perform(new TiltAction(mapboxMap)); + assertEquals("Tilt should match", 40.0f, MapViewUtils.getTilt(mapboxMap), TestConstants.TILT_DELTA); } @Test @@ -84,10 +82,8 @@ public class CameraInternalAPITest { CameraPosition cameraPosition = mapboxMap.getCameraPosition(); assertEquals("Default camera position should match default", cameraPosition, initialPosition); - MapView mapView = (MapView) activity.findViewById(R.id.mapView); - onView(withId(R.id.mapView)).perform(new LatLngAction(mapView)); - - LatLng centerCoordinate = MapViewUtils.getLatLng(mapView); + onView(withId(R.id.mapView)).perform(new LatLngAction(mapboxMap)); + LatLng centerCoordinate = MapViewUtils.getLatLng(mapboxMap); assertEquals("Latitude should match", 1.1f, centerCoordinate.getLatitude(), TestConstants.LAT_LNG_DELTA); assertEquals("Longitude should match", 2.2f, centerCoordinate.getLongitude(), TestConstants.LAT_LNG_DELTA); } @@ -99,10 +95,10 @@ public class CameraInternalAPITest { private class BearingAction implements ViewAction { - private MapView mapView; + private MapboxMap mapboxMap; - BearingAction(MapView mapView) { - this.mapView = mapView; + BearingAction(MapboxMap mapboxMap) { + this.mapboxMap = mapboxMap; } @Override @@ -117,16 +113,16 @@ public class CameraInternalAPITest { @Override public void perform(UiController uiController, View view) { - MapViewUtils.setDirection(mapView, -45.1f); + MapViewUtils.setDirection(mapboxMap, -45.1f); } } private class TiltAction implements ViewAction { - private MapView mapView; + private MapboxMap mapboxMap; - TiltAction(MapView mapView) { - this.mapView = mapView; + TiltAction(MapboxMap mapboxMap) { + this.mapboxMap = mapboxMap; } @Override @@ -141,16 +137,16 @@ public class CameraInternalAPITest { @Override public void perform(UiController uiController, View view) { - MapViewUtils.setTilt(mapView, 40.0f); + MapViewUtils.setTilt(mapboxMap, 40.0f); } } private class LatLngAction implements ViewAction { - private MapView mapView; + private MapboxMap mapboxMap; - LatLngAction(MapView mapView) { - this.mapView = mapView; + LatLngAction(MapboxMap mapboxMap) { + this.mapboxMap = mapboxMap; } @Override @@ -165,7 +161,7 @@ public class CameraInternalAPITest { @Override public void perform(UiController uiController, View view) { - MapViewUtils.setLatLng(mapView, new LatLng(1.1, 2.2)); + MapViewUtils.setLatLng(mapboxMap, new LatLng(1.1, 2.2)); } } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/TestConstants.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/TestConstants.java index 67556e49fb..fdbb92ac56 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/TestConstants.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/TestConstants.java @@ -1,7 +1,11 @@ package com.mapbox.mapboxsdk.testapp.utils; +import com.mapbox.mapboxsdk.constants.MapboxConstants; + public class TestConstants { + public static final long ANIMATION_TEST_TIME = MapboxConstants.ANIMATION_DURATION * 2; + public static final double LAT_LNG_DELTA_LARGE = 0.1; public static final double LAT_LNG_DELTA = 0.01; public static final double BEARING_DELTA = 0.1; @@ -11,5 +15,4 @@ public class TestConstants { public static final String TEXT_MARKER_TEXT = "Text"; public static final String TEXT_MARKER_TITLE = "Marker"; public static final String TEXT_MARKER_SNIPPET = "Snippet"; - } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/MarkerViewActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/MarkerViewActivity.java index 7099b5728a..2bb1a5b3d5 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/MarkerViewActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/MarkerViewActivity.java @@ -140,13 +140,15 @@ public class MarkerViewActivity extends AppCompatActivity { markerViewManager.addMarkerViewAdapter(new CountryAdapter(MarkerViewActivity.this, mapboxMap)); markerViewManager.addMarkerViewAdapter(new TextAdapter(MarkerViewActivity.this, mapboxMap)); + final ViewGroup markerViewContainer = markerViewManager.getMarkerViewContainer(); + // add a change listener to validate the size of amount of child views mapView.addOnMapChangedListener(new MapView.OnMapChangedListener() { @Override public void onMapChanged(@MapView.MapChange int change) { if (change == MapView.REGION_IS_CHANGING || change == MapView.REGION_DID_CHANGE) { if (!markerViewManager.getMarkerViewAdapters().isEmpty() && viewCountView != null) { - viewCountView.setText("ViewCache size " + mapView.getMarkerViewContainer().getChildCount()); + viewCountView.setText("ViewCache size " + markerViewContainer.getChildCount()); } } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/OfflineActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/OfflineActivity.java index 366377ca62..cc080eb5f0 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/OfflineActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/OfflineActivity.java @@ -42,6 +42,9 @@ public class OfflineActivity extends AppCompatActivity public static final String JSON_CHARSET = "UTF-8"; public static final String JSON_FIELD_REGION_NAME = "FIELD_REGION_NAME"; + // Style URL + public static final String STYLE_URL = Style.MAPBOX_STREETS; + /* * UI elements */ @@ -82,7 +85,7 @@ public class OfflineActivity extends AppCompatActivity // Set up map mapView = (MapView) findViewById(R.id.mapView); - mapView.setStyleUrl(Style.MAPBOX_STREETS); + mapView.setStyleUrl(STYLE_URL); mapView.onCreate(savedInstanceState); mapView.getMapAsync(new OnMapReadyCallback() { @Override @@ -242,13 +245,12 @@ public class OfflineActivity extends AppCompatActivity startProgress(); // Definition - String styleUrl = mapboxMap.getStyleUrl(); LatLngBounds bounds = mapboxMap.getProjection().getVisibleRegion().latLngBounds; double minZoom = mapboxMap.getCameraPosition().zoom; double maxZoom = mapboxMap.getMaxZoom(); float pixelRatio = this.getResources().getDisplayMetrics().density; OfflineTilePyramidRegionDefinition definition = new OfflineTilePyramidRegionDefinition( - styleUrl, bounds, minZoom, maxZoom, pixelRatio); + STYLE_URL, bounds, minZoom, maxZoom, pixelRatio); // Sample way of encoding metadata from a JSONObject byte[] metadata = OfflineUtils.convertRegionName(regionName); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java index dbde9a4420..1f69f7bcd7 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java @@ -179,13 +179,6 @@ public class MapboxMapOptionsTest { } @Test - public void testParceable() { - MapboxMapOptions options = new MapboxMapOptions().camera(new CameraPosition.Builder().build()).styleUrl("s").accessToken("a").debugActive(true).compassMargins(new int[]{0, 1, 2, 3}); - MapboxMapOptions parceled = (MapboxMapOptions) MockParcel.obtain(options); - assertEquals(options, parceled); - } - - @Test public void testAccessToken() { assertNull(new MapboxMapOptions().getAccessToken()); assertEquals("test", new MapboxMapOptions().accessToken("test").getAccessToken()); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java deleted file mode 100644 index 6371ddc2b8..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java +++ /dev/null @@ -1,542 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import android.graphics.Color; - -import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions; -import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.annotations.MarkerOptions; -import com.mapbox.mapboxsdk.annotations.Polygon; -import com.mapbox.mapboxsdk.annotations.PolygonOptions; -import com.mapbox.mapboxsdk.annotations.Polyline; -import com.mapbox.mapboxsdk.annotations.PolylineOptions; -import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException; -import com.mapbox.mapboxsdk.geometry.LatLng; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import java.util.ArrayList; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class MapboxMapTest { - - private MapboxMap mMapboxMap; - - @InjectMocks - MapView mMapView = mock(MapView.class); - - @Mock - MapboxMap.OnMarkerClickListener mOnMarkerClickListener; - - @Mock - MapboxMap.OnCameraChangeListener mOnCameraChangeListener; - - @Mock - MapboxMap.InfoWindowAdapter mInfoWindowAdapter; - - @Mock - MapboxMap.OnScrollListener mScrollListener; - - @Mock - MapboxMap.OnFlingListener mFlingListener; - - @Mock - MapboxMap.OnFpsChangedListener mFpsChangedListener; - - @Mock - MapboxMap.OnInfoWindowClickListener mWindowClickListener; - - @Mock - MapboxMap.OnInfoWindowCloseListener mWindowCloseListener; - - @Mock - MapboxMap.OnInfoWindowLongClickListener mWindowLongClickListener; - - @Mock - MapboxMap.OnMyLocationChangeListener mLocationChangeListener; - - @Mock - MapboxMap.OnMyLocationTrackingModeChangeListener mMyLocationTrackingModeChangeListener; - - @Mock - MapboxMap.OnMyBearingTrackingModeChangeListener mMyBearingTrackingModeChangeListener; - - @Mock - IconManager iconManager; - - @Before - public void beforeTest() { - MockitoAnnotations.initMocks(this); - mMapboxMap = new MapboxMap(mMapView, iconManager); - } - - @Test - public void testSanity() { - assertNotNull("mMapboxMap should not be null", mMapboxMap); - } - - @Test - public void testMock() { - assertNotNull("mMapView should be mocked", mMapView); - } - - @Test - public void testGetMapView() { - assertNotNull("MapView should be non null", mMapboxMap.getMapView()); - } - - // - // UiSettings - // - - @Test - public void testUiSettings() { - assertNotNull("UiSettings should not be null", mMapboxMap.getUiSettings()); - } - - // - // MinZoomLevel - // - - @Test - public void testMinZoom() { - double zoom = 10; - mMapboxMap.setMinZoom(zoom); - assertEquals("MinZoom should match", zoom, mMapboxMap.getMinZoom(), 0); - } - - @Test - public void testMaxZoom() { - double zoom = 10; - mMapboxMap.setMaxZoom(zoom); - assertEquals("MaxZoom should match", zoom, mMapboxMap.getMaxZoom(), 0); - } - - @Test - public void testInitialZoomLevels() { - assertEquals("MaxZoom should match", 0, mMapboxMap.getMaxZoom(), 0); - assertEquals("MinZoom should match", 0, mMapboxMap.getMinZoom(), 0); - } - - // - // TrackingSettings - // - - @Test - public void testTrackingSettings() { - assertNotNull("TrackingSettings should not be null", mMapboxMap.getTrackingSettings()); - } - - // - // Projection - // - - @Test - public void testProjection() { - assertNotNull("Projection should not be null", mMapboxMap.getProjection()); - } - - // - // InfoWindow - // - - @Test - public void testConcurrentInfoWindowEnabled() { - mMapboxMap.setAllowConcurrentMultipleOpenInfoWindows(true); - assertTrue("ConcurrentWindows should be true", mMapboxMap.isAllowConcurrentMultipleOpenInfoWindows()); - } - - @Test - public void testConcurrentInfoWindowDisabled() { - mMapboxMap.setAllowConcurrentMultipleOpenInfoWindows(false); - assertFalse("ConcurrentWindows should be false", mMapboxMap.isAllowConcurrentMultipleOpenInfoWindows()); - } - - @Test - public void testInfoWindowAdapter() { - mMapboxMap.setInfoWindowAdapter(mInfoWindowAdapter); - assertEquals("InfoWindowAdpter should be the same", mInfoWindowAdapter, mMapboxMap.getInfoWindowAdapter()); - } - - // - // Location - // - - @Test - public void testMyLocationEnabled() { - when(mMapView.isPermissionsAccepted()).thenReturn(true); - mMapboxMap.setMyLocationEnabled(true); - assertTrue("MyLocationEnabled should be true", mMapboxMap.isMyLocationEnabled()); - - } - - @Test - public void testMyLocationDisabled() { - when(mMapView.isPermissionsAccepted()).thenReturn(true); - mMapboxMap.setMyLocationEnabled(false); - assertFalse("MyLocationEnabled should be false", mMapboxMap.isMyLocationEnabled()); - } - - // - // setters/getters interfaces - // - - @Test - public void testScrollListener() { - mMapboxMap.setOnScrollListener(mScrollListener); - assertEquals("ScrollListener should match", mScrollListener, mMapboxMap.getOnScrollListener()); - } - - @Test - public void testFlingListener() { - mMapboxMap.setOnFlingListener(mFlingListener); - assertEquals("FlingListener should match", mFlingListener, mMapboxMap.getOnFlingListener()); - } - - @Test - public void testFpsListener() { - mMapboxMap.setOnFpsChangedListener(mFpsChangedListener); - assertEquals("FpsListener should match", mFpsChangedListener, mMapboxMap.getOnFpsChangedListener()); - } - - @Test - public void testInfoWindowClickListener() { - mMapboxMap.setOnInfoWindowClickListener(mWindowClickListener); - assertEquals("InfoWidowClickListener should match", mWindowClickListener, mMapboxMap.getOnInfoWindowClickListener()); - } - - @Test - public void testInfoWindowCloseListener() { - mMapboxMap.setOnInfoWindowCloseListener(mWindowCloseListener); - assertEquals("InfoWindowCloseListener should match", mWindowCloseListener, mMapboxMap.getOnInfoWindowCloseListener()); - } - - @Test - public void testInfoWindowLongClickListener() { - mMapboxMap.setOnInfoWindowLongClickListener(mWindowLongClickListener); - assertEquals("InfoWindowLongClickListener should match", mWindowLongClickListener, mMapboxMap.getOnInfoWindowLongClickListener()); - } - - @Test - public void testOnBearingTrackingModeChangeListener() { - mMapboxMap.setOnMyBearingTrackingModeChangeListener(mMyBearingTrackingModeChangeListener); - assertEquals("MyBearingTrackingChangeListerner should match", mMyBearingTrackingModeChangeListener, mMapboxMap.getOnMyBearingTrackingModeChangeListener()); - } - - @Test - public void testOnLocationTrackingModeChangeListener() { - mMapboxMap.setOnMyLocationTrackingModeChangeListener(mMyLocationTrackingModeChangeListener); - assertEquals("MyLocationTrackigChangeListener should match", mMyLocationTrackingModeChangeListener, mMapboxMap.getOnMyLocationTrackingModeChangeListener()); - } - - // - // Annotations - // - - @Test - public void testAddMarker() { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - Marker marker = mMapboxMap.addMarker(markerOptions); - assertTrue("Marker should be contained", mMapboxMap.getMarkers().contains(marker)); - } - - @Test(expected = InvalidMarkerPositionException.class) - public void testAddMarkerInvalidPosition() { - new MarkerOptions().getMarker(); - } - - @Test - public void testAddMarkers() { - List<BaseMarkerOptions> markerList = new ArrayList<>(); - MarkerOptions markerOptions1 = new MarkerOptions().position(new LatLng()).title("a"); - MarkerOptions markerOptions2 = new MarkerOptions().position(new LatLng()).title("b"); - markerList.add(markerOptions1); - markerList.add(markerOptions2); - List<Marker> markers = mMapboxMap.addMarkers(markerList); - assertEquals("Markers size should be 2", 2, mMapboxMap.getMarkers().size()); - assertTrue(mMapboxMap.getMarkers().contains(markers.get(0))); - assertTrue(mMapboxMap.getMarkers().contains(markers.get(1))); - } - - @Test - public void testAddMarkersEmpty() { - List<BaseMarkerOptions> markerList = new ArrayList<>(); - mMapboxMap.addMarkers(markerList); - assertEquals("Markers size should be 0", 0, mMapboxMap.getMarkers().size()); - } - - @Test - public void testAddMarkersSingleMarker() { - List<BaseMarkerOptions> markerList = new ArrayList<>(); - MarkerOptions markerOptions = new MarkerOptions().title("a").position(new LatLng()); - markerList.add(markerOptions); - List<Marker> markers = mMapboxMap.addMarkers(markerList); - assertEquals("Markers size should be 1", 1, mMapboxMap.getMarkers().size()); - assertTrue(mMapboxMap.getMarkers().contains(markers.get(0))); - } - - @Test - public void testAddPolygon() { - PolygonOptions polygonOptions = new PolygonOptions().add(new LatLng()); - Polygon polygon = mMapboxMap.addPolygon(polygonOptions); - assertTrue("Polygon should be contained", mMapboxMap.getPolygons().contains(polygon)); - } - - @Test - public void testAddEmptyPolygon() { - PolygonOptions polygonOptions = new PolygonOptions(); - Polygon polygon = mMapboxMap.addPolygon(polygonOptions); - assertTrue("Polygon should be ignored", !mMapboxMap.getPolygons().contains(polygon)); - } - - @Test - public void testAddPolygons() { - List<PolygonOptions> polygonList = new ArrayList<>(); - PolygonOptions polygonOptions1 = new PolygonOptions().fillColor(Color.BLACK).add(new LatLng()); - PolygonOptions polygonOptions2 = new PolygonOptions().fillColor(Color.WHITE).add(new LatLng()); - PolygonOptions polygonOptions3 = new PolygonOptions(); - polygonList.add(polygonOptions1); - polygonList.add(polygonOptions2); - polygonList.add(polygonOptions3); - mMapboxMap.addPolygons(polygonList); - assertEquals("Polygons size should be 2", 2, mMapboxMap.getPolygons().size()); - assertTrue(mMapboxMap.getPolygons().contains(polygonOptions1.getPolygon())); - assertTrue(mMapboxMap.getPolygons().contains(polygonOptions2.getPolygon())); - assertTrue("Polygon should be ignored", !mMapboxMap.getPolygons().contains(polygonOptions3.getPolygon())); - } - - @Test - public void addPolygonsEmpty() { - mMapboxMap.addPolygons(new ArrayList<PolygonOptions>()); - assertEquals("Polygons size should be 0", 0, mMapboxMap.getPolygons().size()); - } - - @Test - public void addPolygonsSingle() { - List<PolygonOptions> polygonList = new ArrayList<>(); - PolygonOptions polygonOptions = new PolygonOptions().fillColor(Color.BLACK).add(new LatLng()); - polygonList.add(polygonOptions); - mMapboxMap.addPolygons(polygonList); - assertEquals("Polygons size should be 1", 1, mMapboxMap.getPolygons().size()); - assertTrue(mMapboxMap.getPolygons().contains(polygonOptions.getPolygon())); - } - - @Test - public void testAddPolyline() { - PolylineOptions polylineOptions = new PolylineOptions().add(new LatLng()); - Polyline polyline = mMapboxMap.addPolyline(polylineOptions); - assertTrue("Polyline should be contained", mMapboxMap.getPolylines().contains(polyline)); - } - - @Test - public void testAddEmptyPolyline() { - PolylineOptions polylineOptions = new PolylineOptions(); - Polyline polyline = mMapboxMap.addPolyline(polylineOptions); - assertTrue("Polyline should be ignored", !mMapboxMap.getPolylines().contains(polyline)); - } - - @Test - public void testAddPolylines() { - List<PolylineOptions> polylineList = new ArrayList<>(); - PolylineOptions polygonOptions1 = new PolylineOptions().color(Color.BLACK).add(new LatLng()); - PolylineOptions polygonOptions2 = new PolylineOptions().color(Color.WHITE).add(new LatLng()); - PolylineOptions polygonOptions3 = new PolylineOptions(); - polylineList.add(polygonOptions1); - polylineList.add(polygonOptions2); - polylineList.add(polygonOptions3); - mMapboxMap.addPolylines(polylineList); - assertEquals("Polygons size should be 2", 2, mMapboxMap.getPolylines().size()); - assertTrue(mMapboxMap.getPolylines().contains(polygonOptions1.getPolyline())); - assertTrue(mMapboxMap.getPolylines().contains(polygonOptions2.getPolyline())); - assertTrue("Polyline should be ignored", !mMapboxMap.getPolylines().contains(polygonOptions3.getPolyline())); - } - - @Test - public void testAddPolylinesEmpty() { - mMapboxMap.addPolylines(new ArrayList<PolylineOptions>()); - assertEquals("Polygons size should be 0", 0, mMapboxMap.getPolylines().size()); - } - - @Test - public void testAddPolylinesSingle() { - List<PolylineOptions> polylineList = new ArrayList<>(); - PolylineOptions polygonOptions = new PolylineOptions().color(Color.BLACK).add(new LatLng()); - polylineList.add(polygonOptions); - mMapboxMap.addPolylines(polylineList); - assertEquals("Polygons size should be 1", 1, mMapboxMap.getPolylines().size()); - assertTrue(mMapboxMap.getPolylines().contains(polygonOptions.getPolyline())); - } - - @Test - public void testRemoveMarker() { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - Marker marker = mMapboxMap.addMarker(markerOptions); - mMapboxMap.removeMarker(marker); - assertTrue("Markers should be empty", mMapboxMap.getMarkers().isEmpty()); - } - - @Test - public void testRemovePolygon() { - PolygonOptions polygonOptions = new PolygonOptions(); - Polygon polygon = mMapboxMap.addPolygon(polygonOptions); - mMapboxMap.removePolygon(polygon); - assertTrue("Polygons should be empty", mMapboxMap.getPolylines().isEmpty()); - } - - @Test - public void testRemovePolyline() { - PolylineOptions polylineOptions = new PolylineOptions(); - Polyline polyline = mMapboxMap.addPolyline(polylineOptions); - mMapboxMap.removePolyline(polyline); - assertTrue("Polylines should be empty", mMapboxMap.getPolylines().isEmpty()); - } - - @Test - public void testRemoveAnnotation() { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - Marker marker = mMapboxMap.addMarker(markerOptions); - mMapboxMap.removeAnnotation(marker); - assertTrue("Annotations should be empty", mMapboxMap.getAnnotations().isEmpty()); - } - - @Test - public void testRemoveAnnotationById() { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - mMapboxMap.addMarker(markerOptions); - // id will always be 0 in unit tests - mMapboxMap.removeAnnotation(0); - assertTrue("Annotations should be empty", mMapboxMap.getAnnotations().isEmpty()); - } - - @Test - public void testRemoveAnnotations() { - List<BaseMarkerOptions> markerList = new ArrayList<>(); - MarkerOptions markerOptions1 = new MarkerOptions().title("a").position(new LatLng()); - MarkerOptions markerOptions2 = new MarkerOptions().title("b").position(new LatLng()); - markerList.add(markerOptions1); - markerList.add(markerOptions2); - mMapboxMap.addMarkers(markerList); - mMapboxMap.removeAnnotations(); - assertTrue("Annotations should be empty", mMapboxMap.getAnnotations().isEmpty()); - } - - @Test - public void testClear() { - List<BaseMarkerOptions> markerList = new ArrayList<>(); - MarkerOptions markerOptions1 = new MarkerOptions().title("a").position(new LatLng()); - MarkerOptions markerOptions2 = new MarkerOptions().title("b").position(new LatLng()); - markerList.add(markerOptions1); - markerList.add(markerOptions2); - mMapboxMap.addMarkers(markerList); - mMapboxMap.clear(); - assertTrue("Annotations should be empty", mMapboxMap.getAnnotations().isEmpty()); - } - - @Test - public void testRemoveAnnotationsByList() { - List<BaseMarkerOptions> markerList = new ArrayList<>(); - MarkerOptions markerOptions1 = new MarkerOptions().title("a").position(new LatLng()); - MarkerOptions markerOptions2 = new MarkerOptions().title("b").position(new LatLng()); - markerList.add(markerOptions1); - markerList.add(markerOptions2); - List<Marker> markers = mMapboxMap.addMarkers(markerList); - Marker marker = mMapboxMap.addMarker(new MarkerOptions().position(new LatLng()).title("c")); - mMapboxMap.removeAnnotations(markers); - assertTrue("Annotations should not be empty", mMapboxMap.getAnnotations().size() == 1); - assertTrue("Marker should be contained", mMapboxMap.getAnnotations().contains(marker)); - } - - @Test - public void testGetAnnotationById() { - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - Marker initialMarker = mMapboxMap.addMarker(markerOptions); - Marker retrievedMarker = (Marker) mMapboxMap.getAnnotation(0); - assertEquals("Markers should match", initialMarker, retrievedMarker); - } - - @Test - public void testGetAnnotations() { - assertNotNull("Annotations should be non null", mMapboxMap.getAnnotations()); - } - - @Test - public void testGetMarkers() { - assertNotNull("Markers should be non null", mMapboxMap.getMarkers()); - } - - @Test - public void testGetPolygons() { - assertNotNull("Polygons should be non null", mMapboxMap.getPolygons()); - } - - @Test - public void testGetPolylines() { - assertNotNull("Polylines should be non null", mMapboxMap.getPolylines()); - } - - @Test - public void testGetSelectedMarkers() { - assertNotNull("Selected markers should be non null", mMapboxMap.getSelectedMarkers()); - } - - @Test - public void testSelectMarker() { - mMapboxMap.setOnMarkerClickListener(mOnMarkerClickListener); - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - Marker marker = mMapboxMap.addMarker(markerOptions); - when(mOnMarkerClickListener.onMarkerClick(marker)).thenReturn(true); - mMapboxMap.selectMarker(marker); - assertTrue("Marker should be contained", mMapboxMap.getSelectedMarkers().contains(marker)); - } - - @Test - public void testDeselectMarker() { - mMapboxMap.setOnMarkerClickListener(mOnMarkerClickListener); - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - Marker marker = mMapboxMap.addMarker(markerOptions); - when(mOnMarkerClickListener.onMarkerClick(marker)).thenReturn(true); - mMapboxMap.selectMarker(marker); - mMapboxMap.deselectMarker(marker); - assertTrue("Selected markers should be empty", mMapboxMap.getSelectedMarkers().isEmpty()); - } - - @Test - public void testDeselectMarkers() { - mMapboxMap.setOnMarkerClickListener(mOnMarkerClickListener); - MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); - Marker marker1 = mMapboxMap.addMarker(markerOptions); - Marker marker2 = mMapboxMap.addMarker(markerOptions); - when(mOnMarkerClickListener.onMarkerClick(marker1)).thenReturn(true); - when(mOnMarkerClickListener.onMarkerClick(marker2)).thenReturn(true); - mMapboxMap.selectMarker(marker1); - mMapboxMap.selectMarker(marker2); - mMapboxMap.deselectMarkers(); - assertTrue("Selected markers should be empty", mMapboxMap.getSelectedMarkers().isEmpty()); - } - - // - // OnMarkerClick interface - // - - @Test - public void testOnMarkerClick() { - mMapboxMap.setOnMarkerClickListener(mOnMarkerClickListener); - Marker marker = new MarkerOptions().position(new LatLng()).getMarker(); - when(mOnMarkerClickListener.onMarkerClick(marker)).thenReturn(true); - mMapboxMap.selectMarker(marker); - verify(mOnMarkerClickListener, times(1)).onMarkerClick(marker); - } - -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/ProjectionTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/ProjectionTest.java deleted file mode 100644 index fac06de16b..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/ProjectionTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.MockitoAnnotations; - -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.mock; - -public class ProjectionTest { - - @InjectMocks - MapView mMapView = mock(MapView.class); - - @Before - public void beforeTest() { - MockitoAnnotations.initMocks(this); - } - - @Test - public void testSanity() { - Projection projection = new Projection(mMapView); - assertNotNull("projection should not be null", projection); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/TrackingSettingsTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/TrackingSettingsTest.java index 266bbadd95..21a05d2201 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/TrackingSettingsTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/TrackingSettingsTest.java @@ -2,7 +2,9 @@ package com.mapbox.mapboxsdk.maps; import com.mapbox.mapboxsdk.constants.MyBearingTracking; import com.mapbox.mapboxsdk.constants.MyLocationTracking; +import com.mapbox.mapboxsdk.maps.widgets.MyLocationView; +import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; @@ -14,38 +16,46 @@ import static org.mockito.Mockito.mock; public class TrackingSettingsTest { @InjectMocks - MapView mMapView = mock(MapView.class); + MyLocationView myLocationView = mock(MyLocationView.class); + + @InjectMocks + UiSettings uiSettings = mock(UiSettings.class); + + @InjectMocks + FocalPointChangeListener focalPointChangeListener = mock(FocalPointChangeListener.class); + + private TrackingSettings trackingSettings; + + @Before + public void beforeTest(){ + trackingSettings = new TrackingSettings(myLocationView, uiSettings, focalPointChangeListener); + } @Test public void testSanity() { - TrackingSettings trackingSettings = new TrackingSettings(mMapView, new UiSettings(mMapView)); assertNotNull("trackingsettings should not be null", trackingSettings); } @Test public void testMyLocationTrackingMode() { - TrackingSettings trackingSettings = new TrackingSettings(mMapView, new UiSettings(mMapView)); trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW); assertEquals("MyLocationTrackingMode should match", MyLocationTracking.TRACKING_FOLLOW, trackingSettings.getMyLocationTrackingMode()); } @Test public void testMyBearingTrackingMode() { - TrackingSettings trackingSettings = new TrackingSettings(mMapView, new UiSettings(mMapView)); trackingSettings.setMyBearingTrackingMode(MyBearingTracking.COMPASS); assertEquals("MyLocationTrackingMode should match", MyBearingTracking.COMPASS, trackingSettings.getMyBearingTrackingMode()); } @Test public void testDismissTrackingModesOnGesture() { - TrackingSettings trackingSettings = new TrackingSettings(mMapView, new UiSettings(mMapView)); trackingSettings.setDismissTrackingOnGesture(false); assertFalse("DismissTrackingOnGesture should be false", trackingSettings.isDismissTrackingOnGesture()); } @Test - public void testValidateGesturesForTrackingModes(){ - TrackingSettings trackingSettings = new TrackingSettings(mMapView, new UiSettings(mMapView)); + public void testValidateGesturesForTrackingModes() { trackingSettings.setDismissTrackingOnGesture(false); trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW); assertFalse("DismissTrackingOnGesture should be false", trackingSettings.isDismissTrackingOnGesture()); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java index 14fc84723d..741929b814 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java @@ -1,6 +1,11 @@ package com.mapbox.mapboxsdk.maps; import android.view.Gravity; +import android.view.View; +import android.widget.FrameLayout; +import android.widget.ImageView; + +import com.mapbox.mapboxsdk.maps.widgets.CompassView; import org.junit.Before; import org.junit.Test; @@ -16,13 +21,28 @@ import static org.mockito.Mockito.when; public class UiSettingsTest { @InjectMocks - MapView mMapView = mock(MapView.class); + Projection projection = mock(Projection.class); + + @InjectMocks + FocalPointChangeListener focalPointChangeListener = mock(FocalPointChangeListener.class); + + @InjectMocks + CompassView compassView = mock(CompassView.class); + + @InjectMocks + ImageView imageView = mock(ImageView.class); + + @InjectMocks + ImageView logoView = mock(ImageView.class); + + @InjectMocks + FrameLayout.LayoutParams layoutParams = mock(FrameLayout.LayoutParams.class); - UiSettings uiSettings; + private UiSettings uiSettings; @Before public void beforeTest() { - uiSettings = new UiSettings(mMapView); + uiSettings = new UiSettings(projection, focalPointChangeListener, compassView, imageView, logoView); } @Test @@ -32,6 +52,7 @@ public class UiSettingsTest { @Test public void testCompassEnabled() { + when(compassView.isEnabled()).thenReturn(true); uiSettings.setCompassEnabled(true); assertEquals("Compass should be enabled", true, uiSettings.isCompassEnabled()); } @@ -44,12 +65,20 @@ public class UiSettingsTest { @Test public void testCompassGravity() { - uiSettings.setCompassGravity(Gravity.LEFT); - assertEquals("Compass gravity should be same", Gravity.LEFT, uiSettings.getCompassGravity()); + when(compassView.getLayoutParams()).thenReturn(layoutParams); + layoutParams.gravity = Gravity.START; + uiSettings.setCompassGravity(Gravity.START); + assertEquals("Compass gravity should be same", Gravity.START, uiSettings.getCompassGravity()); } @Test public void testCompassMargins() { + when(projection.getContentPadding()).thenReturn(new int[]{0, 0, 0, 0}); + when(compassView.getLayoutParams()).thenReturn(layoutParams); + layoutParams.leftMargin = 1; + layoutParams.topMargin = 2; + layoutParams.rightMargin = 3; + layoutParams.bottomMargin = 4; uiSettings.setCompassMargins(1, 2, 3, 4); assertTrue("Compass margin left should be same", uiSettings.getCompassMarginLeft() == 1); assertTrue("Compass margin top should be same", uiSettings.getCompassMarginTop() == 2); @@ -58,9 +87,11 @@ public class UiSettingsTest { } @Test - public void testCompassFadeWhenFacingNorth(){ + public void testCompassFadeWhenFacingNorth() { + when(compassView.isFadeCompassViewFacingNorth()).thenReturn(true); assertTrue("Compass should fade when facing north by default.", uiSettings.isCompassFadeWhenFacingNorth()); uiSettings.setCompassFadeFacingNorth(false); + when(compassView.isFadeCompassViewFacingNorth()).thenReturn(false); assertFalse("Compass fading should be disabled", uiSettings.isCompassFadeWhenFacingNorth()); } @@ -72,18 +103,27 @@ public class UiSettingsTest { @Test public void testLogoDisabled() { + when(logoView.getVisibility()).thenReturn(View.GONE); uiSettings.setLogoEnabled(false); assertEquals("Logo should be disabled", false, uiSettings.isLogoEnabled()); } @Test public void testLogoGravity() { - uiSettings.setLogoGravity(Gravity.RIGHT); - assertEquals("Logo gravity should be same", Gravity.RIGHT, uiSettings.getLogoGravity()); + layoutParams.gravity = Gravity.END; + when(logoView.getLayoutParams()).thenReturn(layoutParams); + uiSettings.setLogoGravity(Gravity.END); + assertEquals("Logo gravity should be same", Gravity.END, uiSettings.getLogoGravity()); } @Test public void testLogoMargins() { + when(projection.getContentPadding()).thenReturn(new int[]{0, 0, 0, 0}); + when(logoView.getLayoutParams()).thenReturn(layoutParams); + layoutParams.leftMargin = 1; + layoutParams.topMargin = 2; + layoutParams.rightMargin = 3; + layoutParams.bottomMargin = 4; uiSettings.setLogoMargins(1, 2, 3, 4); assertTrue("Compass margin left should be same", uiSettings.getLogoMarginLeft() == 1); assertTrue("Compass margin top should be same", uiSettings.getLogoMarginTop() == 2); @@ -93,24 +133,34 @@ public class UiSettingsTest { @Test public void testAttributionEnabled() { + when(imageView.getVisibility()).thenReturn(View.VISIBLE); uiSettings.setAttributionEnabled(true); assertEquals("Attribution should be enabled", true, uiSettings.isAttributionEnabled()); } @Test public void testAttributionDisabled() { + when(imageView.getVisibility()).thenReturn(View.GONE); uiSettings.setAttributionEnabled(false); - assertEquals("Attribution should be disabled", false, uiSettings.isLogoEnabled()); + assertEquals("Attribution should be disabled", false, uiSettings.isAttributionEnabled()); } @Test public void testAttributionGravity() { - uiSettings.setAttributionGravity(Gravity.RIGHT); - assertEquals("Attribution gravity should be same", Gravity.RIGHT, uiSettings.getAttributionGravity()); + when(imageView.getLayoutParams()).thenReturn(layoutParams); + layoutParams.gravity = Gravity.END; + uiSettings.setAttributionGravity(Gravity.END); + assertEquals("Attribution gravity should be same", Gravity.END, uiSettings.getAttributionGravity()); } @Test public void testAttributionMargins() { + when(imageView.getLayoutParams()).thenReturn(layoutParams); + when(projection.getContentPadding()).thenReturn(new int[]{0, 0, 0, 0}); + layoutParams.leftMargin = 1; + layoutParams.topMargin = 2; + layoutParams.rightMargin = 3; + layoutParams.bottomMargin = 4; uiSettings.setAttributionMargins(1, 2, 3, 4); assertTrue("Attribution margin left should be same", uiSettings.getAttributionMarginLeft() == 1); assertTrue("Attribution margin top should be same", uiSettings.getAttributionMarginTop() == 2); @@ -287,21 +337,4 @@ public class UiSettingsTest { assertEquals("Zoom gesture should be disabled", false, uiSettings.isZoomGesturesEnabled()); assertEquals("Scroll gesture should be disabled", false, uiSettings.isScrollGesturesEnabled()); } - - @Test - public void testInvalidate() { - uiSettings.invalidate(); - } - - @Test - public void testHeight() { - when(mMapView.getMeasuredHeight()).thenReturn(1); - assertEquals("height should be same as mocked instance", 1, uiSettings.getHeight(), 0); - } - - @Test - public void testWidth() { - when(mMapView.getMeasuredWidth()).thenReturn(1); - assertEquals("width should be same as mocked instance", 1, uiSettings.getWidth(), 0); - } }
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettingsTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettingsTest.java index fd70308931..550040338f 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettingsTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettingsTest.java @@ -3,7 +3,8 @@ package com.mapbox.mapboxsdk.maps.widgets; import android.graphics.Color; import android.graphics.drawable.Drawable; -import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.Projection; +import com.mapbox.mapboxsdk.maps.TrackingSettings; import org.junit.Before; import org.junit.Test; @@ -21,16 +22,19 @@ import static org.mockito.Mockito.when; public class MyLocationViewSettingsTest { @InjectMocks - MapView mMapView = mock(MapView.class); + Projection projection = mock(Projection.class); @InjectMocks MyLocationView myLocationView = mock(MyLocationView.class); - MyLocationViewSettings locationViewSettings; + @InjectMocks + TrackingSettings trackingSettings = mock(TrackingSettings.class); + + private MyLocationViewSettings locationViewSettings; @Before public void beforeTest() { - locationViewSettings = new MyLocationViewSettings(mMapView, myLocationView); + locationViewSettings = new MyLocationViewSettings(projection, myLocationView, trackingSettings); } @Test @@ -81,3 +85,4 @@ public class MyLocationViewSettingsTest { } } + diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/platform/android/MapboxGLAndroidSDKTestApp/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 0000000000..ca6ee9cea8 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline
\ No newline at end of file |