diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index c417b3fc26a..f25e05429ed 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -834,6 +834,10 @@ public final void easeCamera(final CameraUpdate update, final int durationMs, fi */ public final void easeCamera(final CameraUpdate update, final int durationMs, final boolean easingInterpolator, final MapboxMap.CancelableCallback callback, final boolean isDismissable) { + + if (durationMs <= 0) { + throw new IllegalArgumentException("Null duration passed into easeCamera"); + } new Handler().post(new Runnable() { @Override public void run() { @@ -906,6 +910,9 @@ public final void animateCamera(CameraUpdate update, int durationMs) { */ public final void animateCamera(final CameraUpdate update, final int durationMs, final MapboxMap.CancelableCallback callback) { + if (durationMs <= 0) { + throw new IllegalArgumentException("Null duration passed into animageCamera"); + } new Handler().post(new Runnable() { @Override public void run() { diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java new file mode 100644 index 00000000000..5e9f94db28d --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java @@ -0,0 +1,47 @@ +package com.mapbox.mapboxsdk.maps; + +import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.mockito.Mockito.mock; + +public class MapboxMapTest { + + private MapboxMap mapboxMap; + + @Before + public void beforeTest() { + + mapboxMap = new MapboxMap(mock(NativeMapView.class), + mock(Transform.class), + mock(UiSettings.class), + mock(TrackingSettings.class), + mock(MyLocationViewSettings.class), + mock(Projection.class), + mock(MapboxMap.OnRegisterTouchListener.class), + mock(AnnotationManager.class), + mock(CameraChangeDispatcher.class)); + } + + @Test(expected = IllegalArgumentException.class) + public void testAnimateCameraChecksDurationPositive() { + mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(30.0, 30.0)), + 0, null); + } + + @Test(expected = IllegalArgumentException.class) + public void testEaseCameraChecksDurationPositive() { + mapboxMap.easeCamera(CameraUpdateFactory.newLatLng(new LatLng(30.0, 30.0)), + 0, null); + } + + @After + public void afterTest() { + mapboxMap = null; + } +}