diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps')
3 files changed, 29 insertions, 94 deletions
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 index b69ba4e3f8..33fd77521d 100644 --- 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 @@ -13,6 +13,7 @@ import com.mapbox.mapboxsdk.annotations.Polyline; import com.mapbox.mapboxsdk.annotations.PolylineOptions; import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; +import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLngBounds; @@ -572,16 +573,21 @@ public class MapboxMapTest { @Test public void testAddMarker() { - MarkerOptions markerOptions = new MarkerOptions(); + 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().title("a"); - MarkerOptions markerOptions2 = new MarkerOptions().title("b"); + MarkerOptions markerOptions1 = new MarkerOptions().position(new LatLng()).title("a"); + MarkerOptions markerOptions2 = new MarkerOptions().position(new LatLng()).title("b"); markerList.add(markerOptions1); markerList.add(markerOptions2); mMapboxMap.addMarkers(markerList); @@ -600,7 +606,7 @@ public class MapboxMapTest { @Test public void testAddMarkersSingleMarker() { List<BaseMarkerOptions> markerList = new ArrayList<>(); - MarkerOptions markerOptions = new MarkerOptions().title("a"); + MarkerOptions markerOptions = new MarkerOptions().title("a").position(new LatLng()); markerList.add(markerOptions); mMapboxMap.addMarkers(markerList); assertEquals("Markers size should be 1", 1, mMapboxMap.getMarkers().size()); @@ -701,7 +707,7 @@ public class MapboxMapTest { @Test public void testRemoveMarker() { - MarkerOptions markerOptions = new MarkerOptions(); + MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); Marker marker = mMapboxMap.addMarker(markerOptions); mMapboxMap.removeMarker(marker); assertTrue("Markers should be empty", mMapboxMap.getMarkers().isEmpty()); @@ -725,7 +731,7 @@ public class MapboxMapTest { @Test public void testRemoveAnnotation() { - MarkerOptions markerOptions = new MarkerOptions(); + MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); Marker marker = mMapboxMap.addMarker(markerOptions); mMapboxMap.removeAnnotation(marker); assertTrue("Annotations should be empty", mMapboxMap.getAnnotations().isEmpty()); @@ -733,7 +739,7 @@ public class MapboxMapTest { @Test public void testRemoveAnnotationById() { - MarkerOptions markerOptions = new MarkerOptions(); + MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); mMapboxMap.addMarker(markerOptions); // id will always be 0 in unit tests mMapboxMap.removeAnnotation(0); @@ -743,8 +749,8 @@ public class MapboxMapTest { @Test public void testRemoveAnnotations() { List<BaseMarkerOptions> markerList = new ArrayList<>(); - MarkerOptions markerOptions1 = new MarkerOptions().title("a"); - MarkerOptions markerOptions2 = new MarkerOptions().title("b"); + 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); @@ -755,8 +761,8 @@ public class MapboxMapTest { @Test public void testClear() { List<BaseMarkerOptions> markerList = new ArrayList<>(); - MarkerOptions markerOptions1 = new MarkerOptions().title("a"); - MarkerOptions markerOptions2 = new MarkerOptions().title("b"); + 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); @@ -767,12 +773,12 @@ public class MapboxMapTest { @Test public void testRemoveAnnotationsByList() { List<BaseMarkerOptions> markerList = new ArrayList<>(); - MarkerOptions markerOptions1 = new MarkerOptions().title("a"); - MarkerOptions markerOptions2 = new MarkerOptions().title("b"); + 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().title("c")); + 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)); @@ -780,7 +786,7 @@ public class MapboxMapTest { @Test public void testGetAnnotationById() { - MarkerOptions markerOptions = new MarkerOptions(); + MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); Marker initialMarker = mMapboxMap.addMarker(markerOptions); Marker retrievedMarker = (Marker) mMapboxMap.getAnnotation(0); assertEquals("Markers should match", initialMarker, retrievedMarker); @@ -814,7 +820,7 @@ public class MapboxMapTest { @Test public void testSelectMarker() { mMapboxMap.setOnMarkerClickListener(mOnMarkerClickListener); - MarkerOptions markerOptions = new MarkerOptions(); + MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); Marker marker = mMapboxMap.addMarker(markerOptions); when(mOnMarkerClickListener.onMarkerClick(marker)).thenReturn(true); mMapboxMap.selectMarker(marker); @@ -824,7 +830,7 @@ public class MapboxMapTest { @Test public void testDeselectMarker() { mMapboxMap.setOnMarkerClickListener(mOnMarkerClickListener); - MarkerOptions markerOptions = new MarkerOptions(); + MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); Marker marker = mMapboxMap.addMarker(markerOptions); when(mOnMarkerClickListener.onMarkerClick(marker)).thenReturn(true); mMapboxMap.selectMarker(marker); @@ -835,7 +841,7 @@ public class MapboxMapTest { @Test public void testDeselectMarkers() { mMapboxMap.setOnMarkerClickListener(mOnMarkerClickListener); - MarkerOptions markerOptions = new MarkerOptions(); + MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()); Marker marker1 = mMapboxMap.addMarker(markerOptions); Marker marker2 = mMapboxMap.addMarker(markerOptions); when(mOnMarkerClickListener.onMarkerClick(marker1)).thenReturn(true); @@ -853,7 +859,7 @@ public class MapboxMapTest { @Test public void testOnMarkerClick() { mMapboxMap.setOnMarkerClickListener(mOnMarkerClickListener); - Marker marker = new MarkerOptions().getMarker(); + 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/StyleInitializerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/StyleInitializerTest.java deleted file mode 100644 index 71d61a3d4b..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/StyleInitializerTest.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import android.content.Context; -import android.content.res.Resources; - -import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.model.constants.AppConstant; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.MockitoAnnotations; - -import java.util.Locale; - -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.when; - -public class StyleInitializerTest { - - @InjectMocks - Context context = mock(Context.class); - - @InjectMocks - Resources resources = mock(Resources.class); - - MapView.StyleInitializer initializer; - - @Before - public void beforeTest() { - MockitoAnnotations.initMocks(this); - when(context.getResources()).thenReturn(resources); - when(resources.getInteger(R.integer.style_version)).thenReturn(AppConstant.STYLE_VERSION); - initializer = new MapView.StyleInitializer(context); - } - - @Test - public void testSanity() { - assertNotNull("initializer should not be null", initializer); - } - - @Test - public void testDefaultStyle() { - assertTrue(initializer.isDefaultStyle()); - assertEquals(String.format(Locale.US, "mapbox://styles/mapbox/streets-v%d", AppConstant.STYLE_VERSION), "mapbox://styles/mapbox/streets-v9"); - } - - @Test - public void testUpdateStyle() { - String customStyle = "test"; - initializer.setStyle(customStyle); - assertFalse(initializer.isDefaultStyle()); - assertEquals(customStyle, initializer.getStyle()); - } - - @Test - public void testUpdateStyleNull() { - String customStyle = null; - initializer.setStyle(customStyle); - assertTrue(initializer.isDefaultStyle()); - assertEquals(String.format(Locale.US, "mapbox://styles/mapbox/streets-v%d", AppConstant.STYLE_VERSION), "mapbox://styles/mapbox/streets-v9"); - } - - @Test - public void testOverrideDefaultStyle() { - String customStyle = "test"; - initializer.setStyle(customStyle, true); - assertTrue(initializer.isDefaultStyle()); - assertEquals(customStyle, initializer.getStyle()); - } -} 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 a03eb6acae..fd70308931 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 @@ -16,6 +16,7 @@ import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertTrue; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class MyLocationViewSettingsTest { @@ -41,6 +42,9 @@ public class MyLocationViewSettingsTest { public void testForegroundDrawables() { Drawable foregroundDrawable = mock(Drawable.class); Drawable foregroundBearingDrawable = mock(Drawable.class); + Drawable.ConstantState constantState = mock(Drawable.ConstantState.class); + when(foregroundDrawable.getConstantState()).thenReturn(constantState); + when(constantState.newDrawable()).thenReturn(foregroundDrawable); locationViewSettings.setForegroundDrawable(foregroundDrawable, foregroundBearingDrawable); assertEquals("foreground should match", foregroundDrawable, locationViewSettings.getForegroundDrawable()); assertEquals("foreground bearing should match", foregroundBearingDrawable, locationViewSettings.getForegroundBearingDrawable()); |