diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps')
11 files changed, 0 insertions, 2700 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/AnnotationManagerTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/AnnotationManagerTest.java deleted file mode 100644 index fd59f52a55..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/AnnotationManagerTest.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import android.support.v4.util.LongSparseArray; - -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.geometry.LatLng; - -import org.junit.Test; -import org.mockito.ArgumentMatchers; - -import java.util.ArrayList; -import java.util.List; - -import static junit.framework.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class AnnotationManagerTest { - - @Test - public void checksAddAMarker() throws Exception { - NativeMap aNativeMapView = mock(NativeMapView.class); - MapView aMapView = mock(MapView.class); - LongSparseArray<Annotation> annotationsArray = new LongSparseArray<>(); - IconManager aIconManager = mock(IconManager.class); - Annotations annotations = new AnnotationContainer(aNativeMapView, annotationsArray); - Markers markers = new MarkerContainer(aNativeMapView, annotationsArray, aIconManager); - Polygons polygons = new PolygonContainer(aNativeMapView, annotationsArray); - Polylines polylines = new PolylineContainer(aNativeMapView, annotationsArray); - ShapeAnnotations shapeAnnotations = new ShapeAnnotationContainer(aNativeMapView, annotationsArray); - AnnotationManager annotationManager = new AnnotationManager(aMapView, annotationsArray, - aIconManager, annotations, markers, polygons, polylines, shapeAnnotations); - Marker aMarker = mock(Marker.class); - long aId = 5L; - when(aNativeMapView.addMarker(aMarker)).thenReturn(aId); - BaseMarkerOptions aMarkerOptions = mock(BaseMarkerOptions.class); - MapboxMap aMapboxMap = mock(MapboxMap.class); - when(aMarkerOptions.getMarker()).thenReturn(aMarker); - - annotationManager.addMarker(aMarkerOptions, aMapboxMap); - - assertEquals(aMarker, annotationManager.getAnnotations().get(0)); - assertEquals(aMarker, annotationManager.getAnnotation(aId)); - } - - @Test - public void checksAddMarkers() throws Exception { - NativeMapView aNativeMapView = mock(NativeMapView.class); - MapView aMapView = mock(MapView.class); - LongSparseArray<Annotation> annotationsArray = new LongSparseArray<>(); - IconManager aIconManager = mock(IconManager.class); - Annotations annotations = new AnnotationContainer(aNativeMapView, annotationsArray); - Markers markers = new MarkerContainer(aNativeMapView, annotationsArray, aIconManager); - Polygons polygons = new PolygonContainer(aNativeMapView, annotationsArray); - Polylines polylines = new PolylineContainer(aNativeMapView, annotationsArray); - ShapeAnnotations shapeAnnotations = new ShapeAnnotationContainer(aNativeMapView, annotationsArray); - AnnotationManager annotationManager = new AnnotationManager(aMapView, annotationsArray, - aIconManager, annotations, markers, polygons, polylines, shapeAnnotations); - - long firstId = 1L; - long secondId = 2L; - List<BaseMarkerOptions> markerList = new ArrayList<>(); - MarkerOptions firstMarkerOption = new MarkerOptions().position(new LatLng()).title("first"); - MarkerOptions secondMarkerOption = new MarkerOptions().position(new LatLng()).title("second"); - - markerList.add(firstMarkerOption); - markerList.add(secondMarkerOption); - MapboxMap aMapboxMap = mock(MapboxMap.class); - when(aNativeMapView.addMarker(any(Marker.class))).thenReturn(firstId, secondId); - - when(aNativeMapView.addMarkers(ArgumentMatchers.<Marker>anyList())) - .thenReturn(new long[] {firstId, secondId}); - - annotationManager.addMarkers(markerList, aMapboxMap); - - assertEquals(2, annotationManager.getAnnotations().size()); - assertEquals("first", ((Marker) annotationManager.getAnnotations().get(0)).getTitle()); - assertEquals("second", ((Marker) annotationManager.getAnnotations().get(1)).getTitle()); - assertEquals("first", ((Marker) annotationManager.getAnnotation(firstId)).getTitle()); - assertEquals("second", ((Marker) annotationManager.getAnnotation(secondId)).getTitle()); - } -}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/AttributionDialogManagerTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/AttributionDialogManagerTest.java deleted file mode 100644 index 9b4eeb27aa..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/AttributionDialogManagerTest.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import android.content.Context; - -import com.mapbox.mapboxsdk.camera.CameraPosition; -import com.mapbox.mapboxsdk.geometry.LatLng; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.robolectric.RobolectricTestRunner; - -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -@RunWith(RobolectricTestRunner.class) -public class AttributionDialogManagerTest { - @InjectMocks - Context context = mock(Context.class); - - @InjectMocks - MapboxMap mapboxMap = mock(MapboxMap.class); - - @InjectMocks - Style style = mock(Style.class); - - private AttributionDialogManager attributionDialogManager; - private CameraPosition cameraPosition; - - private static final String ASSERT_MAPBOX_TOKEN = "TestAccessToken"; - - private static final String ASSERT_MAPBOX_STYLE_URI = "mapbox://styles/mapbox/streets-v11"; - private static final String ASSERT_MAPBOX_LOCAL_STYLE_URI = "asset://style.json"; - - private static final String ASSERT_MAPBOX_PACKAGE_NAME = "com.mapbox.attributionmanagertest"; - - private static final String ASSERT_MAPBOX_FEEDBACK_FINAL_URL = - "https://apps.mapbox.com/feedback?referrer=com.mapbox.attributionmanagertest&" - + "access_token=TestAccessToken&owner=mapbox&id=streets-v11" - + "#/22.200001/11.100000/12.000000/24.000000/5"; - private static final String ASSERT_MAPBOX_FEEDHACK_FINAL_URL_LOCAL_STYLE = - "https://apps.mapbox.com/feedback?referrer=com.mapbox.attributionmanagertest&" - + "access_token=TestAccessToken#/22.200001/11.100000/12.000000/24.000000/5"; - private static final String ASSERT_MAPBOX_FEEDBACL_FINAL_URL_NULL_CAMERA_POSITION = - "https://apps.mapbox.com/feedback?referrer=com.mapbox.attributionmanagertest&access_token=TestAccessToken"; - - @Before - public void beforeTest() { - attributionDialogManager = new AttributionDialogManager(context, mapboxMap); - cameraPosition = new CameraPosition.Builder(CameraPosition.DEFAULT) - .tilt(5.0f).zoom(12).bearing(24.0f).target(new LatLng(11.1f, 22.2f)).build(); - } - - @Test - public void testSanity() { - assertNotNull("AttributionDialogManager should not be null", attributionDialogManager); - } - - @Test - public void testBuildMapFeedbackMapUrl() { - when(context.getApplicationContext()).thenReturn(context); - when(context.getPackageName()).thenReturn(ASSERT_MAPBOX_PACKAGE_NAME); - when(style.getUri()).thenReturn(ASSERT_MAPBOX_STYLE_URI); - when(mapboxMap.getCameraPosition()).thenReturn(cameraPosition); - when(mapboxMap.getStyle()).thenReturn(style); - - Assert.assertEquals(ASSERT_MAPBOX_FEEDBACK_FINAL_URL, - attributionDialogManager.buildMapFeedbackMapUrl(ASSERT_MAPBOX_TOKEN)); - } - - @Test - public void testBuildMapFeedbackMapUrlWithLocalStyleJson() { - when(context.getApplicationContext()).thenReturn(context); - when(context.getPackageName()).thenReturn(ASSERT_MAPBOX_PACKAGE_NAME); - when(style.getUri()).thenReturn(ASSERT_MAPBOX_LOCAL_STYLE_URI); - when(mapboxMap.getCameraPosition()).thenReturn(cameraPosition); - when(mapboxMap.getStyle()).thenReturn(style); - - Assert.assertEquals(ASSERT_MAPBOX_FEEDHACK_FINAL_URL_LOCAL_STYLE, - attributionDialogManager.buildMapFeedbackMapUrl(ASSERT_MAPBOX_TOKEN)); - } - - @Test - public void testBuildMapFeedbackMapUrlWithNullCameraPosition() { - when(context.getApplicationContext()).thenReturn(context); - when(context.getPackageName()).thenReturn(ASSERT_MAPBOX_PACKAGE_NAME); - when(style.getUri()).thenReturn(ASSERT_MAPBOX_LOCAL_STYLE_URI); - when(mapboxMap.getCameraPosition()).thenReturn(null); - when(mapboxMap.getStyle()).thenReturn(style); - - Assert.assertEquals(ASSERT_MAPBOX_FEEDBACL_FINAL_URL_NULL_CAMERA_POSITION, - attributionDialogManager.buildMapFeedbackMapUrl(ASSERT_MAPBOX_TOKEN)); - } - - -} diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapChangeReceiverTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapChangeReceiverTest.java deleted file mode 100644 index 025f06752c..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapChangeReceiverTest.java +++ /dev/null @@ -1,586 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import com.google.common.util.concurrent.ExecutionError; -import com.mapbox.mapboxsdk.log.Logger; -import com.mapbox.mapboxsdk.log.LoggerDefinition; - -import junit.framework.Assert; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.verify; - -/** - * Tests integration of MapChangeDispatcher and see if events are correctly forwarded. - */ -public class MapChangeReceiverTest { - - private static final String TEST_STRING = "mapChangeRandom"; - - private MapChangeReceiver mapChangeEventManager; - - @Mock - private MapView.OnCameraWillChangeListener onCameraWillChangeListener; - - @Mock - private MapView.OnCameraDidChangeListener onCameraDidChangeListener; - - @Mock - private MapView.OnCameraIsChangingListener onCameraIsChangingListener; - - @Mock - private MapView.OnWillStartLoadingMapListener onWillStartLoadingMapListener; - - @Mock - private MapView.OnDidFinishLoadingMapListener onDidFinishLoadingMapListener; - - @Mock - private MapView.OnDidFailLoadingMapListener onDidFailLoadingMapListener; - - @Mock - private MapView.OnWillStartRenderingFrameListener onWillStartRenderingFrameListener; - - @Mock - private MapView.OnDidFinishRenderingFrameListener onDidFinishRenderingFrameListener; - - @Mock - private MapView.OnWillStartRenderingMapListener onWillStartRenderingMapListener; - - @Mock - private MapView.OnDidFinishRenderingMapListener onDidFinishRenderingMapListener; - - @Mock - private MapView.OnDidBecomeIdleListener onDidBecomeIdleListener; - - @Mock - private MapView.OnDidFinishLoadingStyleListener onDidFinishLoadingStyleListener; - - @Mock - private MapView.OnSourceChangedListener onSourceChangedListener; - - @Mock - private LoggerDefinition loggerDefinition; - - @Before - public void beforeTest() { - MockitoAnnotations.initMocks(this); - mapChangeEventManager = new MapChangeReceiver(); - } - - @Test - public void testOnCameraRegionWillChangeListener() { - mapChangeEventManager.addOnCameraWillChangeListener(onCameraWillChangeListener); - mapChangeEventManager.onCameraWillChange(false); - verify(onCameraWillChangeListener).onCameraWillChange(false); - - mapChangeEventManager.removeOnCameraWillChangeListener(onCameraWillChangeListener); - mapChangeEventManager.onCameraWillChange(false); - verify(onCameraWillChangeListener).onCameraWillChange(false); - - mapChangeEventManager.addOnCameraWillChangeListener(onCameraWillChangeListener); - Logger.setLoggerDefinition(loggerDefinition); - Exception exc = new RuntimeException(); - doThrow(exc).when(onCameraWillChangeListener).onCameraWillChange(false); - try { - mapChangeEventManager.onCameraWillChange(false); - Assert.fail("The exception should've been re-thrown."); - } catch (RuntimeException throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(exc)); - } - - Error err = new ExecutionError("", new Error()); - doThrow(err).when(onCameraWillChangeListener).onCameraWillChange(false); - try { - mapChangeEventManager.onCameraWillChange(false); - Assert.fail("The exception should've been re-thrown."); - } catch (ExecutionError throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(err)); - } - } - - @Test - public void testOnCameraRegionWillChangeAnimatedListener() { - mapChangeEventManager.addOnCameraWillChangeListener(onCameraWillChangeListener); - mapChangeEventManager.onCameraWillChange(true); - verify(onCameraWillChangeListener).onCameraWillChange(true); - mapChangeEventManager.removeOnCameraWillChangeListener(onCameraWillChangeListener); - mapChangeEventManager.onCameraWillChange(true); - verify(onCameraWillChangeListener).onCameraWillChange(true); - - mapChangeEventManager.addOnCameraWillChangeListener(onCameraWillChangeListener); - Logger.setLoggerDefinition(loggerDefinition); - Exception exc = new RuntimeException(); - doThrow(exc).when(onCameraWillChangeListener).onCameraWillChange(true); - try { - mapChangeEventManager.onCameraWillChange(true); - Assert.fail("The exception should've been re-thrown."); - } catch (RuntimeException throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(exc)); - } - - Error err = new ExecutionError("", new Error()); - doThrow(err).when(onCameraWillChangeListener).onCameraWillChange(true); - try { - mapChangeEventManager.onCameraWillChange(true); - Assert.fail("The exception should've been re-thrown."); - } catch (ExecutionError throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(err)); - } - } - - @Test - public void testOnCameraIsChangingListener() { - mapChangeEventManager.addOnCameraIsChangingListener(onCameraIsChangingListener); - mapChangeEventManager.onCameraIsChanging(); - verify(onCameraIsChangingListener).onCameraIsChanging(); - mapChangeEventManager.removeOnCameraIsChangingListener(onCameraIsChangingListener); - mapChangeEventManager.onCameraIsChanging(); - verify(onCameraIsChangingListener).onCameraIsChanging(); - - mapChangeEventManager.addOnCameraIsChangingListener(onCameraIsChangingListener); - Logger.setLoggerDefinition(loggerDefinition); - Exception exc = new RuntimeException(); - doThrow(exc).when(onCameraIsChangingListener).onCameraIsChanging(); - try { - mapChangeEventManager.onCameraIsChanging(); - Assert.fail("The exception should've been re-thrown."); - } catch (RuntimeException throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(exc)); - } - - Error err = new ExecutionError("", new Error()); - doThrow(err).when(onCameraIsChangingListener).onCameraIsChanging(); - try { - mapChangeEventManager.onCameraIsChanging(); - Assert.fail("The exception should've been re-thrown."); - } catch (ExecutionError throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(err)); - } - } - - @Test - public void testOnCameraRegionDidChangeListener() { - mapChangeEventManager.addOnCameraDidChangeListener(onCameraDidChangeListener); - mapChangeEventManager.onCameraDidChange(false); - verify(onCameraDidChangeListener).onCameraDidChange(false); - mapChangeEventManager.removeOnCameraDidChangeListener(onCameraDidChangeListener); - mapChangeEventManager.onCameraDidChange(false); - verify(onCameraDidChangeListener).onCameraDidChange(false); - - mapChangeEventManager.addOnCameraDidChangeListener(onCameraDidChangeListener); - Logger.setLoggerDefinition(loggerDefinition); - Exception exc = new RuntimeException(); - doThrow(exc).when(onCameraDidChangeListener).onCameraDidChange(false); - try { - mapChangeEventManager.onCameraDidChange(false); - Assert.fail("The exception should've been re-thrown."); - } catch (RuntimeException throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(exc)); - } - - Error err = new ExecutionError("", new Error()); - doThrow(err).when(onCameraDidChangeListener).onCameraDidChange(false); - try { - mapChangeEventManager.onCameraDidChange(false); - Assert.fail("The exception should've been re-thrown."); - } catch (ExecutionError throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(err)); - } - } - - @Test - public void testOnCameraRegionDidChangeAnimatedListener() { - mapChangeEventManager.addOnCameraDidChangeListener(onCameraDidChangeListener); - mapChangeEventManager.onCameraDidChange(true); - verify(onCameraDidChangeListener).onCameraDidChange(true); - mapChangeEventManager.removeOnCameraDidChangeListener(onCameraDidChangeListener); - mapChangeEventManager.onCameraDidChange(true); - verify(onCameraDidChangeListener).onCameraDidChange(true); - - mapChangeEventManager.addOnCameraDidChangeListener(onCameraDidChangeListener); - Logger.setLoggerDefinition(loggerDefinition); - Exception exc = new RuntimeException(); - doThrow(exc).when(onCameraDidChangeListener).onCameraDidChange(true); - try { - mapChangeEventManager.onCameraDidChange(true); - Assert.fail("The exception should've been re-thrown."); - } catch (RuntimeException throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(exc)); - } - - Error err = new ExecutionError("", new Error()); - doThrow(err).when(onCameraDidChangeListener).onCameraDidChange(true); - try { - mapChangeEventManager.onCameraDidChange(true); - Assert.fail("The exception should've been re-thrown."); - } catch (ExecutionError throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(err)); - } - } - - @Test - public void testOnWillStartLoadingMapListener() { - mapChangeEventManager.addOnWillStartLoadingMapListener(onWillStartLoadingMapListener); - mapChangeEventManager.onWillStartLoadingMap(); - verify(onWillStartLoadingMapListener).onWillStartLoadingMap(); - mapChangeEventManager.removeOnWillStartLoadingMapListener(onWillStartLoadingMapListener); - mapChangeEventManager.onWillStartLoadingMap(); - verify(onWillStartLoadingMapListener).onWillStartLoadingMap(); - - mapChangeEventManager.addOnWillStartLoadingMapListener(onWillStartLoadingMapListener); - Logger.setLoggerDefinition(loggerDefinition); - Exception exc = new RuntimeException(); - doThrow(exc).when(onWillStartLoadingMapListener).onWillStartLoadingMap(); - try { - mapChangeEventManager.onWillStartLoadingMap(); - Assert.fail("The exception should've been re-thrown."); - } catch (RuntimeException throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(exc)); - } - - Error err = new ExecutionError("", new Error()); - doThrow(err).when(onWillStartLoadingMapListener).onWillStartLoadingMap(); - try { - mapChangeEventManager.onWillStartLoadingMap(); - Assert.fail("The exception should've been re-thrown."); - } catch (ExecutionError throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(err)); - } - } - - @Test - public void testOnDidFinishLoadingMapListener() { - mapChangeEventManager.addOnDidFinishLoadingMapListener(onDidFinishLoadingMapListener); - mapChangeEventManager.onDidFinishLoadingMap(); - verify(onDidFinishLoadingMapListener).onDidFinishLoadingMap(); - mapChangeEventManager.removeOnDidFinishLoadingMapListener(onDidFinishLoadingMapListener); - mapChangeEventManager.onDidFinishLoadingMap(); - verify(onDidFinishLoadingMapListener).onDidFinishLoadingMap(); - - mapChangeEventManager.addOnDidFinishLoadingMapListener(onDidFinishLoadingMapListener); - Logger.setLoggerDefinition(loggerDefinition); - Exception exc = new RuntimeException(); - doThrow(exc).when(onDidFinishLoadingMapListener).onDidFinishLoadingMap(); - try { - mapChangeEventManager.onDidFinishLoadingMap(); - Assert.fail("The exception should've been re-thrown."); - } catch (RuntimeException throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(exc)); - } - - Error err = new ExecutionError("", new Error()); - doThrow(err).when(onDidFinishLoadingMapListener).onDidFinishLoadingMap(); - try { - mapChangeEventManager.onDidFinishLoadingMap(); - Assert.fail("The exception should've been re-thrown."); - } catch (ExecutionError throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(err)); - } - } - - @Test - public void testOnDidFailLoadingMapListener() { - mapChangeEventManager.addOnDidFailLoadingMapListener(onDidFailLoadingMapListener); - mapChangeEventManager.onDidFailLoadingMap(TEST_STRING); - verify(onDidFailLoadingMapListener).onDidFailLoadingMap(TEST_STRING); - mapChangeEventManager.removeOnDidFailLoadingMapListener(onDidFailLoadingMapListener); - mapChangeEventManager.onDidFailLoadingMap(TEST_STRING); - verify(onDidFailLoadingMapListener).onDidFailLoadingMap(TEST_STRING); - - mapChangeEventManager.addOnDidFailLoadingMapListener(onDidFailLoadingMapListener); - Logger.setLoggerDefinition(loggerDefinition); - Exception exc = new RuntimeException(); - doThrow(exc).when(onDidFailLoadingMapListener).onDidFailLoadingMap(TEST_STRING); - try { - mapChangeEventManager.onDidFailLoadingMap(TEST_STRING); - Assert.fail("The exception should've been re-thrown."); - } catch (RuntimeException throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(exc)); - } - - Error err = new ExecutionError("", new Error()); - doThrow(err).when(onDidFailLoadingMapListener).onDidFailLoadingMap(TEST_STRING); - try { - mapChangeEventManager.onDidFailLoadingMap(TEST_STRING); - Assert.fail("The exception should've been re-thrown."); - } catch (ExecutionError throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(err)); - } - } - - @Test - public void testOnWillStartRenderingFrameListener() { - mapChangeEventManager.addOnWillStartRenderingFrameListener(onWillStartRenderingFrameListener); - mapChangeEventManager.onWillStartRenderingFrame(); - verify(onWillStartRenderingFrameListener).onWillStartRenderingFrame(); - mapChangeEventManager.removeOnWillStartRenderingFrameListener(onWillStartRenderingFrameListener); - mapChangeEventManager.onWillStartRenderingFrame(); - verify(onWillStartRenderingFrameListener).onWillStartRenderingFrame(); - - mapChangeEventManager.addOnWillStartRenderingFrameListener(onWillStartRenderingFrameListener); - Logger.setLoggerDefinition(loggerDefinition); - Exception exc = new RuntimeException(); - doThrow(exc).when(onWillStartRenderingFrameListener).onWillStartRenderingFrame(); - try { - mapChangeEventManager.onWillStartRenderingFrame(); - Assert.fail("The exception should've been re-thrown."); - } catch (RuntimeException throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(exc)); - } - - Error err = new ExecutionError("", new Error()); - doThrow(err).when(onWillStartRenderingFrameListener).onWillStartRenderingFrame(); - try { - mapChangeEventManager.onWillStartRenderingFrame(); - Assert.fail("The exception should've been re-thrown."); - } catch (ExecutionError throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(err)); - } - } - - @Test - public void testOnDidFinishRenderingFrameListener() { - mapChangeEventManager.addOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener); - mapChangeEventManager.onDidFinishRenderingFrame(true); - verify(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(true); - mapChangeEventManager.removeOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener); - mapChangeEventManager.onDidFinishRenderingFrame(true); - verify(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(true); - - mapChangeEventManager.addOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener); - Logger.setLoggerDefinition(loggerDefinition); - Exception exc = new RuntimeException(); - doThrow(exc).when(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(true); - try { - mapChangeEventManager.onDidFinishRenderingFrame(true); - Assert.fail("The exception should've been re-thrown."); - } catch (RuntimeException throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(exc)); - } - - Error err = new ExecutionError("", new Error()); - doThrow(err).when(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(true); - try { - mapChangeEventManager.onDidFinishRenderingFrame(true); - Assert.fail("The exception should've been re-thrown."); - } catch (ExecutionError throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(err)); - } - } - - @Test - public void testOnDidFinishRenderingFrameFullyRenderedListener() { - mapChangeEventManager.addOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener); - mapChangeEventManager.onDidFinishRenderingFrame(false); - verify(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(false); - mapChangeEventManager.removeOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener); - mapChangeEventManager.onDidFinishRenderingFrame(false); - verify(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(false); - - mapChangeEventManager.addOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener); - Logger.setLoggerDefinition(loggerDefinition); - Exception exc = new RuntimeException(); - doThrow(exc).when(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(false); - try { - mapChangeEventManager.onDidFinishRenderingFrame(false); - Assert.fail("The exception should've been re-thrown."); - } catch (RuntimeException throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(exc)); - } - - Error err = new ExecutionError("", new Error()); - doThrow(err).when(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(false); - try { - mapChangeEventManager.onDidFinishRenderingFrame(false); - Assert.fail("The exception should've been re-thrown."); - } catch (ExecutionError throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(err)); - } - } - - @Test - public void testOnWillStartRenderingMapListener() { - mapChangeEventManager.addOnWillStartRenderingMapListener(onWillStartRenderingMapListener); - mapChangeEventManager.onWillStartRenderingMap(); - verify(onWillStartRenderingMapListener).onWillStartRenderingMap(); - mapChangeEventManager.removeOnWillStartRenderingMapListener(onWillStartRenderingMapListener); - mapChangeEventManager.onWillStartRenderingMap(); - verify(onWillStartRenderingMapListener).onWillStartRenderingMap(); - - mapChangeEventManager.addOnWillStartRenderingMapListener(onWillStartRenderingMapListener); - Logger.setLoggerDefinition(loggerDefinition); - Exception exc = new RuntimeException(); - doThrow(exc).when(onWillStartRenderingMapListener).onWillStartRenderingMap(); - try { - mapChangeEventManager.onWillStartRenderingMap(); - Assert.fail("The exception should've been re-thrown."); - } catch (RuntimeException throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(exc)); - } - - Error err = new ExecutionError("", new Error()); - doThrow(err).when(onWillStartRenderingMapListener).onWillStartRenderingMap(); - try { - mapChangeEventManager.onWillStartRenderingMap(); - Assert.fail("The exception should've been re-thrown."); - } catch (ExecutionError throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(err)); - } - } - - @Test - public void testOnDidFinishRenderingMapListener() { - mapChangeEventManager.addOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener); - mapChangeEventManager.onDidFinishRenderingMap(true); - verify(onDidFinishRenderingMapListener).onDidFinishRenderingMap(true); - mapChangeEventManager.removeOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener); - mapChangeEventManager.onDidFinishRenderingMap(true); - verify(onDidFinishRenderingMapListener).onDidFinishRenderingMap(true); - - mapChangeEventManager.addOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener); - Logger.setLoggerDefinition(loggerDefinition); - Exception exc = new RuntimeException(); - doThrow(exc).when(onDidFinishRenderingMapListener).onDidFinishRenderingMap(true); - try { - mapChangeEventManager.onDidFinishRenderingMap(true); - Assert.fail("The exception should've been re-thrown."); - } catch (RuntimeException throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(exc)); - } - - Error err = new ExecutionError("", new Error()); - doThrow(err).when(onDidFinishRenderingMapListener).onDidFinishRenderingMap(true); - try { - mapChangeEventManager.onDidFinishRenderingMap(true); - Assert.fail("The exception should've been re-thrown."); - } catch (ExecutionError throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(err)); - } - } - - @Test - public void testOnDidFinishRenderingMapFullyRenderedListener() { - mapChangeEventManager.addOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener); - mapChangeEventManager.onDidFinishRenderingMap(false); - verify(onDidFinishRenderingMapListener).onDidFinishRenderingMap(false); - mapChangeEventManager.removeOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener); - mapChangeEventManager.onDidFinishRenderingMap(false); - verify(onDidFinishRenderingMapListener).onDidFinishRenderingMap(false); - - mapChangeEventManager.addOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener); - Logger.setLoggerDefinition(loggerDefinition); - Exception exc = new RuntimeException(); - doThrow(exc).when(onDidFinishRenderingMapListener).onDidFinishRenderingMap(false); - try { - mapChangeEventManager.onDidFinishRenderingMap(false); - Assert.fail("The exception should've been re-thrown."); - } catch (RuntimeException throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(exc)); - } - - Error err = new ExecutionError("", new Error()); - doThrow(err).when(onDidFinishRenderingMapListener).onDidFinishRenderingMap(false); - try { - mapChangeEventManager.onDidFinishRenderingMap(false); - Assert.fail("The exception should've been re-thrown."); - } catch (ExecutionError throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(err)); - } - } - - @Test - public void testOnDidBecomeIdleListener() { - mapChangeEventManager.addOnDidBecomeIdleListener(onDidBecomeIdleListener); - mapChangeEventManager.onDidBecomeIdle(); - verify(onDidBecomeIdleListener).onDidBecomeIdle(); - mapChangeEventManager.removeOnDidBecomeIdleListener(onDidBecomeIdleListener); - mapChangeEventManager.onDidBecomeIdle(); - verify(onDidBecomeIdleListener).onDidBecomeIdle(); - - mapChangeEventManager.addOnDidBecomeIdleListener(onDidBecomeIdleListener); - Logger.setLoggerDefinition(loggerDefinition); - Exception exc = new RuntimeException(); - doThrow(exc).when(onDidBecomeIdleListener).onDidBecomeIdle(); - try { - mapChangeEventManager.onDidBecomeIdle(); - Assert.fail("The exception should've been re-thrown."); - } catch (RuntimeException throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(exc)); - } - - Error err = new ExecutionError("", new Error()); - doThrow(err).when(onDidBecomeIdleListener).onDidBecomeIdle(); - try { - mapChangeEventManager.onDidBecomeIdle(); - Assert.fail("The exception should've been re-thrown."); - } catch (ExecutionError throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(err)); - } - } - - @Test - public void testOnDidFinishLoadingStyleListener() { - mapChangeEventManager.addOnDidFinishLoadingStyleListener(onDidFinishLoadingStyleListener); - mapChangeEventManager.onDidFinishLoadingStyle(); - verify(onDidFinishLoadingStyleListener).onDidFinishLoadingStyle(); - mapChangeEventManager.removeOnDidFinishLoadingStyleListener(onDidFinishLoadingStyleListener); - mapChangeEventManager.onDidFinishLoadingStyle(); - verify(onDidFinishLoadingStyleListener).onDidFinishLoadingStyle(); - - mapChangeEventManager.addOnDidFinishLoadingStyleListener(onDidFinishLoadingStyleListener); - Logger.setLoggerDefinition(loggerDefinition); - Exception exc = new RuntimeException(); - doThrow(exc).when(onDidFinishLoadingStyleListener).onDidFinishLoadingStyle(); - try { - mapChangeEventManager.onDidFinishLoadingStyle(); - Assert.fail("The exception should've been re-thrown."); - } catch (RuntimeException throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(exc)); - } - - Error err = new ExecutionError("", new Error()); - doThrow(err).when(onDidFinishLoadingStyleListener).onDidFinishLoadingStyle(); - try { - mapChangeEventManager.onDidFinishLoadingStyle(); - Assert.fail("The exception should've been re-thrown."); - } catch (ExecutionError throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(err)); - } - } - - @Test - public void testOnSourceChangedListener() { - mapChangeEventManager.addOnSourceChangedListener(onSourceChangedListener); - mapChangeEventManager.onSourceChanged(TEST_STRING); - verify(onSourceChangedListener).onSourceChangedListener(TEST_STRING); - mapChangeEventManager.removeOnSourceChangedListener(onSourceChangedListener); - mapChangeEventManager.onSourceChanged(TEST_STRING); - verify(onSourceChangedListener).onSourceChangedListener(TEST_STRING); - - mapChangeEventManager.addOnSourceChangedListener(onSourceChangedListener); - Logger.setLoggerDefinition(loggerDefinition); - Exception exc = new RuntimeException(); - doThrow(exc).when(onSourceChangedListener).onSourceChangedListener(TEST_STRING); - try { - mapChangeEventManager.onSourceChanged(TEST_STRING); - Assert.fail("The exception should've been re-thrown."); - } catch (RuntimeException throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(exc)); - } - - Error err = new ExecutionError("", new Error()); - doThrow(err).when(onSourceChangedListener).onSourceChangedListener(TEST_STRING); - try { - mapChangeEventManager.onSourceChanged(TEST_STRING); - Assert.fail("The exception should've been re-thrown."); - } catch (ExecutionError throwable) { - verify(loggerDefinition).e(anyString(), anyString(), eq(err)); - } - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapTouchListenersTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapTouchListenersTest.java deleted file mode 100644 index cb097c283d..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapTouchListenersTest.java +++ /dev/null @@ -1,157 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import android.graphics.PointF; - -import android.support.annotation.Nullable; -import com.mapbox.android.gestures.MoveGestureDetector; -import com.mapbox.android.gestures.RotateGestureDetector; -import com.mapbox.android.gestures.ShoveGestureDetector; -import com.mapbox.android.gestures.StandardScaleGestureDetector; -import com.mapbox.mapboxsdk.geometry.LatLng; - -import org.junit.Before; -import org.junit.Test; - -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 MapTouchListenersTest { - - @Nullable - private MapGestureDetector mapGestureDetector; - private LatLng latLng; - private PointF pointF; - - @Before - public void setUp() throws Exception { - latLng = new LatLng(); - pointF = new PointF(); - - Projection projection = mock(Projection.class); - when(projection.fromScreenLocation(pointF)).thenReturn(latLng); - mapGestureDetector = new MapGestureDetector(null, - null, projection, null, null, null); - } - - @Test - public void onMapClickListenerTest() throws Exception { - MapboxMap.OnMapClickListener listener = mock(MapboxMap.OnMapClickListener.class); - mapGestureDetector.addOnMapClickListener(listener); - mapGestureDetector.notifyOnMapClickListeners(pointF); - verify(listener, times(1)).onMapClick(latLng); - - mapGestureDetector.removeOnMapClickListener(listener); - mapGestureDetector.notifyOnMapClickListeners(pointF); - verify(listener, times(1)).onMapClick(latLng); - } - - @Test - public void onMapLongClickListenerTest() throws Exception { - MapboxMap.OnMapLongClickListener listener = mock(MapboxMap.OnMapLongClickListener.class); - mapGestureDetector.addOnMapLongClickListener(listener); - mapGestureDetector.notifyOnMapLongClickListeners(pointF); - verify(listener, times(1)).onMapLongClick(latLng); - - mapGestureDetector.removeOnMapLongClickListener(listener); - mapGestureDetector.notifyOnMapLongClickListeners(pointF); - verify(listener, times(1)).onMapLongClick(latLng); - } - - @Test - public void onFlingListenerTest() throws Exception { - MapboxMap.OnFlingListener listener = mock(MapboxMap.OnFlingListener.class); - mapGestureDetector.addOnFlingListener(listener); - mapGestureDetector.notifyOnFlingListeners(); - verify(listener, times(1)).onFling(); - - mapGestureDetector.removeOnFlingListener(listener); - mapGestureDetector.notifyOnFlingListeners(); - verify(listener, times(1)).onFling(); - } - - @Test - public void onMoveListenerTest() throws Exception { - MapboxMap.OnMoveListener listener = mock(MapboxMap.OnMoveListener.class); - MoveGestureDetector detector = mock(MoveGestureDetector.class); - mapGestureDetector.addOnMoveListener(listener); - mapGestureDetector.notifyOnMoveBeginListeners(detector); - mapGestureDetector.notifyOnMoveListeners(detector); - mapGestureDetector.notifyOnMoveEndListeners(detector); - verify(listener, times(1)).onMoveBegin(detector); - verify(listener, times(1)).onMove(detector); - verify(listener, times(1)).onMoveEnd(detector); - - mapGestureDetector.removeOnMoveListener(listener); - mapGestureDetector.notifyOnMoveBeginListeners(detector); - mapGestureDetector.notifyOnMoveListeners(detector); - mapGestureDetector.notifyOnMoveEndListeners(detector); - verify(listener, times(1)).onMoveBegin(detector); - verify(listener, times(1)).onMove(detector); - verify(listener, times(1)).onMoveEnd(detector); - } - - @Test - public void onRotateListenerTest() throws Exception { - MapboxMap.OnRotateListener listener = mock(MapboxMap.OnRotateListener.class); - RotateGestureDetector detector = mock(RotateGestureDetector.class); - mapGestureDetector.addOnRotateListener(listener); - mapGestureDetector.notifyOnRotateBeginListeners(detector); - mapGestureDetector.notifyOnRotateListeners(detector); - mapGestureDetector.notifyOnRotateEndListeners(detector); - verify(listener, times(1)).onRotateBegin(detector); - verify(listener, times(1)).onRotate(detector); - verify(listener, times(1)).onRotateEnd(detector); - - mapGestureDetector.removeOnRotateListener(listener); - mapGestureDetector.notifyOnRotateBeginListeners(detector); - mapGestureDetector.notifyOnRotateListeners(detector); - mapGestureDetector.notifyOnRotateEndListeners(detector); - verify(listener, times(1)).onRotateBegin(detector); - verify(listener, times(1)).onRotate(detector); - verify(listener, times(1)).onRotateEnd(detector); - } - - @Test - public void onScaleListenerTest() throws Exception { - MapboxMap.OnScaleListener listener = mock(MapboxMap.OnScaleListener.class); - StandardScaleGestureDetector detector = mock(StandardScaleGestureDetector.class); - mapGestureDetector.addOnScaleListener(listener); - mapGestureDetector.notifyOnScaleBeginListeners(detector); - mapGestureDetector.notifyOnScaleListeners(detector); - mapGestureDetector.notifyOnScaleEndListeners(detector); - verify(listener, times(1)).onScaleBegin(detector); - verify(listener, times(1)).onScale(detector); - verify(listener, times(1)).onScaleEnd(detector); - - mapGestureDetector.removeOnScaleListener(listener); - mapGestureDetector.notifyOnScaleBeginListeners(detector); - mapGestureDetector.notifyOnScaleListeners(detector); - mapGestureDetector.notifyOnScaleEndListeners(detector); - verify(listener, times(1)).onScaleBegin(detector); - verify(listener, times(1)).onScale(detector); - verify(listener, times(1)).onScaleEnd(detector); - } - - @Test - public void onShoveListenerTest() throws Exception { - MapboxMap.OnShoveListener listener = mock(MapboxMap.OnShoveListener.class); - ShoveGestureDetector detector = mock(ShoveGestureDetector.class); - mapGestureDetector.addShoveListener(listener); - mapGestureDetector.notifyOnShoveBeginListeners(detector); - mapGestureDetector.notifyOnShoveListeners(detector); - mapGestureDetector.notifyOnShoveEndListeners(detector); - verify(listener, times(1)).onShoveBegin(detector); - verify(listener, times(1)).onShove(detector); - verify(listener, times(1)).onShoveEnd(detector); - - mapGestureDetector.removeShoveListener(listener); - mapGestureDetector.notifyOnShoveBeginListeners(detector); - mapGestureDetector.notifyOnShoveListeners(detector); - mapGestureDetector.notifyOnShoveEndListeners(detector); - verify(listener, times(1)).onShoveBegin(detector); - verify(listener, times(1)).onShove(detector); - verify(listener, times(1)).onShoveEnd(detector); - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsAttrsTest.kt b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsAttrsTest.kt deleted file mode 100644 index ee8024257f..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsAttrsTest.kt +++ /dev/null @@ -1,101 +0,0 @@ -package com.mapbox.mapboxsdk.maps - -import android.content.Context -import android.content.res.Resources -import android.content.res.TypedArray -import com.mapbox.mapboxsdk.R -import io.mockk.MockKAnnotations -import io.mockk.every -import io.mockk.impl.annotations.RelaxedMockK -import io.mockk.verify -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.robolectric.RobolectricTestRunner - -@RunWith(RobolectricTestRunner::class) -class MapboxMapOptionsAttrsTest { - - @RelaxedMockK - private lateinit var options: MapboxMapOptions - - @RelaxedMockK - private lateinit var typedArray: TypedArray - - @RelaxedMockK - private lateinit var context: Context - - @RelaxedMockK - private lateinit var resources: Resources - - @Before - fun setUp() { - MockKAnnotations.init(this) - every { - context.resources - }.returns(resources) - } - - @Test - fun enabledLocalIdeographFontFamily() { - mockEnableLocalIdeograph(enabled = true) - - val options = MapboxMapOptions.createFromAttributes(options, context, typedArray) - - verify(exactly = 1) { - options.localIdeographFontFamily(any()) - } - } - - @Test - fun localIdeographFontFamily() { - mockEnableLocalIdeograph(enabled = true) - - val font = "foo" - mockLocalIdeographString(font) - - val options = MapboxMapOptions.createFromAttributes(options, context, typedArray) - - verify(exactly = 1) { - options.localIdeographFontFamily(font) - } - } - - @Test - fun localIdeographFontFamilies() { - mockEnableLocalIdeograph(enabled = true) - - val fonts = arrayOf("foo", "bar") - mockLocalIdeographStringArray(fonts) - - val options = MapboxMapOptions.createFromAttributes(options, context, typedArray) - - verify(exactly = 1) { - options.localIdeographFontFamily(*fonts) - } - } - - private fun mockEnableLocalIdeograph(enabled: Boolean) { - every { - typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_localIdeographEnabled, true) - }.returns(enabled) - } - - private fun mockLocalIdeographString(font: String) { - every { - typedArray.getString(R.styleable.mapbox_MapView_mapbox_localIdeographFontFamily) - }.returns(font) - } - - private fun mockLocalIdeographStringArray(fonts: Array<String>) { - val resId = 9000 - - every { - typedArray.getResourceId(R.styleable.mapbox_MapView_mapbox_localIdeographFontFamilies, 0) - }.returns(resId) - - every { - resources.getStringArray(resId) - }.returns(fonts) - } -}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java deleted file mode 100644 index c46e6e3190..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java +++ /dev/null @@ -1,196 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import android.graphics.Color; -import android.view.Gravity; - -import com.mapbox.mapboxsdk.camera.CameraPosition; -import com.mapbox.mapboxsdk.constants.MapboxConstants; -import com.mapbox.mapboxsdk.geometry.LatLng; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.RuntimeEnvironment; - -import java.util.Arrays; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertNull; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -@RunWith(RobolectricTestRunner.class) -public class MapboxMapOptionsTest { - - private static final double DELTA = 1e-15; - - @Test - public void testSanity() { - assertNotNull("should not be null", new MapboxMapOptions()); - } - - @Test - public void testDebugEnabled() { - assertFalse(new MapboxMapOptions().getDebugActive()); - assertTrue(new MapboxMapOptions().debugActive(true).getDebugActive()); - assertFalse(new MapboxMapOptions().debugActive(false).getDebugActive()); - } - - @Test - public void testCompassEnabled() { - assertTrue(new MapboxMapOptions().compassEnabled(true).getCompassEnabled()); - assertFalse(new MapboxMapOptions().compassEnabled(false).getCompassEnabled()); - } - - @Test - public void testCompassGravity() { - assertEquals(Gravity.TOP | Gravity.END, new MapboxMapOptions().getCompassGravity()); - assertEquals(Gravity.BOTTOM, new MapboxMapOptions().compassGravity(Gravity.BOTTOM).getCompassGravity()); - assertNotEquals(Gravity.START, new MapboxMapOptions().compassGravity(Gravity.BOTTOM).getCompassGravity()); - } - - @Test - public void testCompassMargins() { - assertTrue(Arrays.equals(new int[] {0, 1, 2, 3}, new MapboxMapOptions().compassMargins( - new int[] {0, 1, 2, 3}).getCompassMargins())); - assertFalse(Arrays.equals(new int[] {0, 1, 2, 3}, new MapboxMapOptions().compassMargins( - new int[] {0, 0, 0, 0}).getCompassMargins())); - } - - @Test - public void testLogoEnabled() { - assertTrue(new MapboxMapOptions().logoEnabled(true).getLogoEnabled()); - assertFalse(new MapboxMapOptions().logoEnabled(false).getLogoEnabled()); - } - - @Test - public void testLogoGravity() { - assertEquals(Gravity.BOTTOM | Gravity.START, new MapboxMapOptions().getLogoGravity()); - assertEquals(Gravity.BOTTOM, new MapboxMapOptions().logoGravity(Gravity.BOTTOM).getLogoGravity()); - assertNotEquals(Gravity.START, new MapboxMapOptions().logoGravity(Gravity.BOTTOM).getLogoGravity()); - } - - @Test - public void testLogoMargins() { - assertTrue(Arrays.equals(new int[] {0, 1, 2, 3}, new MapboxMapOptions().logoMargins( - new int[] {0, 1, 2, 3}).getLogoMargins())); - assertFalse(Arrays.equals(new int[] {0, 1, 2, 3}, new MapboxMapOptions().logoMargins( - new int[] {0, 0, 0, 0}).getLogoMargins())); - } - - @Test - public void testAttributionTintColor() { - assertEquals(-1, new MapboxMapOptions().getAttributionTintColor()); - assertEquals(Color.RED, new MapboxMapOptions().attributionTintColor(Color.RED).getAttributionTintColor()); - } - - @Test - public void testAttributionEnabled() { - assertTrue(new MapboxMapOptions().attributionEnabled(true).getAttributionEnabled()); - assertFalse(new MapboxMapOptions().attributionEnabled(false).getAttributionEnabled()); - } - - @Test - public void testAttributionGravity() { - assertEquals(Gravity.BOTTOM | Gravity.START, new MapboxMapOptions().getAttributionGravity()); - assertEquals(Gravity.BOTTOM, new MapboxMapOptions().attributionGravity(Gravity.BOTTOM).getAttributionGravity()); - assertNotEquals(Gravity.START, new MapboxMapOptions().attributionGravity(Gravity.BOTTOM).getAttributionGravity()); - } - - @Test - public void testAttributionMargins() { - assertTrue(Arrays.equals(new int[] {0, 1, 2, 3}, new MapboxMapOptions().attributionMargins( - new int[] {0, 1, 2, 3}).getAttributionMargins())); - assertFalse(Arrays.equals(new int[] {0, 1, 2, 3}, new MapboxMapOptions().attributionMargins( - new int[] {0, 0, 0, 0}).getAttributionMargins())); - } - - @Test - public void testMinZoom() { - assertEquals(MapboxConstants.MINIMUM_ZOOM, new MapboxMapOptions().getMinZoomPreference(), DELTA); - assertEquals(5.0f, new MapboxMapOptions().minZoomPreference(5.0f).getMinZoomPreference(), DELTA); - assertNotEquals(2.0f, new MapboxMapOptions().minZoomPreference(5.0f).getMinZoomPreference(), DELTA); - } - - @Test - public void testMaxZoom() { - assertEquals(MapboxConstants.MAXIMUM_ZOOM, new MapboxMapOptions().getMaxZoomPreference(), DELTA); - assertEquals(5.0f, new MapboxMapOptions().maxZoomPreference(5.0f).getMaxZoomPreference(), DELTA); - assertNotEquals(2.0f, new MapboxMapOptions().maxZoomPreference(5.0f).getMaxZoomPreference(), DELTA); - } - - @Test - public void testTiltGesturesEnabled() { - assertTrue(new MapboxMapOptions().getTiltGesturesEnabled()); - assertTrue(new MapboxMapOptions().tiltGesturesEnabled(true).getTiltGesturesEnabled()); - assertFalse(new MapboxMapOptions().tiltGesturesEnabled(false).getTiltGesturesEnabled()); - } - - @Test - public void testScrollGesturesEnabled() { - assertTrue(new MapboxMapOptions().getScrollGesturesEnabled()); - assertTrue(new MapboxMapOptions().scrollGesturesEnabled(true).getScrollGesturesEnabled()); - assertFalse(new MapboxMapOptions().scrollGesturesEnabled(false).getScrollGesturesEnabled()); - } - - @Test - public void testZoomGesturesEnabled() { - assertTrue(new MapboxMapOptions().getZoomGesturesEnabled()); - assertTrue(new MapboxMapOptions().zoomGesturesEnabled(true).getZoomGesturesEnabled()); - assertFalse(new MapboxMapOptions().zoomGesturesEnabled(false).getZoomGesturesEnabled()); - } - - @Test - public void testRotateGesturesEnabled() { - assertTrue(new MapboxMapOptions().getRotateGesturesEnabled()); - assertTrue(new MapboxMapOptions().rotateGesturesEnabled(true).getRotateGesturesEnabled()); - assertFalse(new MapboxMapOptions().rotateGesturesEnabled(false).getRotateGesturesEnabled()); - } - - @Test - public void testCamera() { - CameraPosition position = new CameraPosition.Builder().build(); - assertEquals(new CameraPosition.Builder(position).build(), new MapboxMapOptions().camera(position).getCamera()); - assertNotEquals(new CameraPosition.Builder().target(new LatLng(1, 1)), new MapboxMapOptions().camera(position)); - assertNull(new MapboxMapOptions().getCamera()); - } - - @Test - public void testPrefetchesTiles() { - // Default value - assertTrue(new MapboxMapOptions().getPrefetchesTiles()); - - // Check mutations - assertTrue(new MapboxMapOptions().setPrefetchesTiles(true).getPrefetchesTiles()); - assertFalse(new MapboxMapOptions().setPrefetchesTiles(false).getPrefetchesTiles()); - } - - @Test - public void testPrefetchZoomDelta() { - // Default value - assertEquals(4, new MapboxMapOptions().getPrefetchZoomDelta()); - - // Check mutations - assertEquals(5, new MapboxMapOptions().setPrefetchZoomDelta(5).getPrefetchZoomDelta()); - } - - - @Test - public void testCrossSourceCollisions() { - // Default value - assertTrue(new MapboxMapOptions().getCrossSourceCollisions()); - - // check mutations - assertTrue(new MapboxMapOptions().crossSourceCollisions(true).getCrossSourceCollisions()); - assertFalse(new MapboxMapOptions().crossSourceCollisions(false).getCrossSourceCollisions()); - } - - @Test - public void testLocalIdeographFontFamily_enabledByDefault() { - MapboxMapOptions options = MapboxMapOptions.createFromAttributes(RuntimeEnvironment.application, null); - assertEquals(MapboxConstants.DEFAULT_FONT, options.getLocalIdeographFontFamily()); - } -} - diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.kt b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.kt deleted file mode 100644 index 6647fe5595..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.kt +++ /dev/null @@ -1,214 +0,0 @@ -package com.mapbox.mapboxsdk.maps - -import com.mapbox.mapboxsdk.camera.CameraPosition -import com.mapbox.mapboxsdk.camera.CameraUpdateFactory -import com.mapbox.mapboxsdk.constants.MapboxConstants -import com.mapbox.mapboxsdk.geometry.LatLng -import com.mapbox.mapboxsdk.geometry.LatLngBounds -import com.mapbox.mapboxsdk.style.layers.TransitionOptions -import io.mockk.* -import junit.framework.Assert.assertEquals -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.robolectric.RobolectricTestRunner - -@RunWith(RobolectricTestRunner::class) -class MapboxMapTest { - - private lateinit var mapboxMap: MapboxMap - - private lateinit var nativeMapView: NativeMap - - private lateinit var transform: Transform - - private lateinit var cameraChangeDispatcher: CameraChangeDispatcher - - private lateinit var developerAnimationListener: MapboxMap.OnDeveloperAnimationListener - - @Before - fun setup() { - cameraChangeDispatcher = spyk() - developerAnimationListener = mockk(relaxed = true) - nativeMapView = mockk(relaxed = true) - transform = mockk(relaxed = true) - mapboxMap = MapboxMap(nativeMapView, transform, mockk(relaxed = true), null, null, cameraChangeDispatcher, listOf(developerAnimationListener)) - every { nativeMapView.isDestroyed } returns false - every { nativeMapView.nativePtr } returns 5 - mapboxMap.injectLocationComponent(spyk()) - mapboxMap.setStyle(Style.MAPBOX_STREETS) - mapboxMap.onFinishLoadingStyle() - } - - @Test - fun testTransitionOptions() { - val expected = TransitionOptions(100, 200) - mapboxMap.style?.transition = expected - verify { nativeMapView.transitionOptions = expected } - } - - @Test - fun testMoveCamera() { - val callback = mockk<MapboxMap.CancelableCallback>() - val target = LatLng(1.0, 2.0) - val expected = CameraPosition.Builder().target(target).build() - val update = CameraUpdateFactory.newCameraPosition(expected) - mapboxMap.moveCamera(update, callback) - verify { transform.moveCamera(mapboxMap, update, callback) } - verify { developerAnimationListener.onDeveloperAnimationStarted() } - } - - @Test - fun testEaseCamera() { - val callback = mockk<MapboxMap.CancelableCallback>() - val target = LatLng(1.0, 2.0) - val expected = CameraPosition.Builder().target(target).build() - val update = CameraUpdateFactory.newCameraPosition(expected) - mapboxMap.easeCamera(update, callback) - verify { transform.easeCamera(mapboxMap, update, MapboxConstants.ANIMATION_DURATION, true, callback) } - verify { developerAnimationListener.onDeveloperAnimationStarted() } - } - - @Test - fun testAnimateCamera() { - val callback = mockk<MapboxMap.CancelableCallback>() - val target = LatLng(1.0, 2.0) - val expected = CameraPosition.Builder().target(target).build() - val update = CameraUpdateFactory.newCameraPosition(expected) - mapboxMap.animateCamera(update, callback) - verify { transform.animateCamera(mapboxMap, update, MapboxConstants.ANIMATION_DURATION, callback) } - verify { developerAnimationListener.onDeveloperAnimationStarted() } - } - - @Test - fun testScrollBy() { - mapboxMap.scrollBy(100f, 200f) - verify { nativeMapView.moveBy(100.0, 200.0, 0) } - verify { developerAnimationListener.onDeveloperAnimationStarted() } - } - - @Test - fun testResetNorth() { - mapboxMap.resetNorth() - verify { transform.resetNorth() } - verify { developerAnimationListener.onDeveloperAnimationStarted() } - } - - @Test - fun testFocalBearing() { - mapboxMap.setFocalBearing(35.0, 100f, 200f, 1000) - verify { transform.setBearing(35.0, 100f, 200f, 1000) } - verify { developerAnimationListener.onDeveloperAnimationStarted() } - } - - @Test - fun testMinZoom() { - mapboxMap.setMinZoomPreference(10.0) - verify { transform.minZoom = 10.0 } - } - - @Test - fun testMaxZoom() { - mapboxMap.setMaxZoomPreference(10.0) - verify { transform.maxZoom = 10.0 } - } - - @Test - fun testFpsListener() { - val fpsChangedListener = mockk<MapboxMap.OnFpsChangedListener>() - mapboxMap.onFpsChangedListener = fpsChangedListener - assertEquals("Listener should match", fpsChangedListener, mapboxMap.onFpsChangedListener) - } - - @Test - fun testTilePrefetch() { - mapboxMap.prefetchesTiles = true - verify { nativeMapView.prefetchTiles = true } - } - - @Test - fun testGetPrefetchZoomDelta() { - every { nativeMapView.prefetchZoomDelta } answers { 3 } - assertEquals(3, mapboxMap.prefetchZoomDelta) - } - - @Test - fun testSetPrefetchZoomDelta() { - mapboxMap.prefetchZoomDelta = 2 - verify { nativeMapView.prefetchZoomDelta = 2 } - } - - @Test - fun testCameraForLatLngBounds() { - val bounds = LatLngBounds.Builder().include(LatLng()).include(LatLng(1.0, 1.0)).build() - mapboxMap.setLatLngBoundsForCameraTarget(bounds) - verify { nativeMapView.setLatLngBounds(bounds) } - } - - @Test(expected = IllegalArgumentException::class) - fun testAnimateCameraChecksDurationPositive() { - mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(LatLng(30.0, 30.0)), 0, null) - } - - @Test(expected = IllegalArgumentException::class) - fun testEaseCameraChecksDurationPositive() { - mapboxMap.easeCamera(CameraUpdateFactory.newLatLng(LatLng(30.0, 30.0)), 0, null) - } - - @Test - fun testGetNativeMapPtr() { - assertEquals(5, mapboxMap.nativeMapPtr) - } - - @Test - fun testNativeMapIsNotCalledOnStateSave() { - clearMocks(nativeMapView) - mapboxMap.onSaveInstanceState(mockk(relaxed = true)) - verify { nativeMapView wasNot Called } - } - - @Test - fun testCameraChangeDispatcherCleared() { - mapboxMap.onDestroy() - verify { cameraChangeDispatcher.onDestroy() } - } - - @Test - fun testStyleClearedOnDestroy() { - val style = mockk<Style>(relaxed = true) - val builder = mockk<Style.Builder>(relaxed = true) - every { builder.build(nativeMapView) } returns style - mapboxMap.setStyle(builder) - - mapboxMap.onDestroy() - verify(exactly = 1) { style.clear() } - } - - @Test - fun testStyleCallbackNotCalledWhenPreviousFailed() { - val style = mockk<Style>(relaxed = true) - val builder = mockk<Style.Builder>(relaxed = true) - every { builder.build(nativeMapView) } returns style - val onStyleLoadedListener = mockk<Style.OnStyleLoaded>(relaxed = true) - - mapboxMap.setStyle(builder, onStyleLoadedListener) - mapboxMap.onFailLoadingStyle() - mapboxMap.setStyle(builder, onStyleLoadedListener) - mapboxMap.onFinishLoadingStyle() - verify(exactly = 1) { onStyleLoadedListener.onStyleLoaded(style) } - } - - @Test - fun testStyleCallbackNotCalledWhenPreviousNotFinished() { - // regression test for #14337 - val style = mockk<Style>(relaxed = true) - val builder = mockk<Style.Builder>(relaxed = true) - every { builder.build(nativeMapView) } returns style - val onStyleLoadedListener = mockk<Style.OnStyleLoaded>(relaxed = true) - - mapboxMap.setStyle(builder, onStyleLoadedListener) - mapboxMap.setStyle(builder, onStyleLoadedListener) - mapboxMap.onFinishLoadingStyle() - verify(exactly = 1) { onStyleLoadedListener.onStyleLoaded(style) } - } -}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleBuilderTest.kt b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleBuilderTest.kt deleted file mode 100644 index 4c153414de..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleBuilderTest.kt +++ /dev/null @@ -1,237 +0,0 @@ -package com.mapbox.mapboxsdk.maps - -import android.graphics.Bitmap -import android.graphics.drawable.Drawable -import android.graphics.drawable.ShapeDrawable -import android.util.Pair -import com.mapbox.mapboxsdk.style.layers.SymbolLayer -import com.mapbox.mapboxsdk.style.layers.TransitionOptions -import com.mapbox.mapboxsdk.style.sources.GeoJsonSource -import com.mapbox.mapboxsdk.utils.BitmapUtils -import io.mockk.mockk -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue -import org.junit.Test -import org.junit.runner.RunWith -import org.robolectric.RobolectricTestRunner - -@RunWith(RobolectricTestRunner::class) -class StyleBuilderTest { - - @Test - fun testFromUrl() { - val expected = Style.MAPBOX_STREETS - val builder = Style.Builder() - builder.fromUrl(expected) - assertEquals(expected, builder.uri) - } - - @Test - fun testFromJson() { - val expected = "{}" - val builder = Style.Builder() - builder.fromJson(expected) - assertEquals(expected, builder.json) - } - - @Test - fun testWithLayer() { - val layer = mockk<SymbolLayer>() - val builder = Style.Builder() - builder.withLayer(layer) - assertEquals(layer, builder.layers[0].layer) - } - - @Test - fun testWithLayers() { - val layer1 = mockk<SymbolLayer>() - val layer2 = mockk<SymbolLayer>() - val builder = Style.Builder() - builder.withLayers(layer1, layer2) - assertEquals(layer1, builder.layers[0].layer) - assertEquals(layer2, builder.layers[1].layer) - } - - @Test - fun testWithLayerAt() { - val expectedIndex = 5 - val layer = mockk<SymbolLayer>() - val builder = Style.Builder() - builder.withLayerAt(layer, expectedIndex) - assertEquals(layer, builder.layers[0].layer) - assertEquals(expectedIndex, (builder.layers[0] as Style.Builder.LayerAtWrapper).index) - } - - @Test - fun testWithLayerAbove() { - val expectedAbove = "above" - val layer = mockk<SymbolLayer>() - val builder = Style.Builder() - builder.withLayerAbove(layer, expectedAbove) - assertEquals(layer, builder.layers[0].layer) - assertEquals(expectedAbove, (builder.layers[0] as Style.Builder.LayerAboveWrapper).aboveLayer) - } - - @Test - fun testWithLayerBelow() { - val expectedBelow = "above" - val layer = mockk<SymbolLayer>() - val builder = Style.Builder() - builder.withLayerBelow(layer, expectedBelow) - assertEquals(layer, builder.layers[0].layer) - assertEquals(expectedBelow, (builder.layers[0] as Style.Builder.LayerBelowWrapper).belowLayer) - } - - @Test - fun testWithSource() { - val source = mockk<GeoJsonSource>() - val builder = Style.Builder() - builder.withSource(source) - assertEquals(source, builder.sources[0]) - } - - @Test - fun testWithSources() { - val source1 = mockk<GeoJsonSource>() - val source2 = mockk<GeoJsonSource>() - val builder = Style.Builder() - builder.withSources(source1, source2) - assertEquals(source1, builder.sources[0]) - assertEquals(source2, builder.sources[1]) - } - - @Test - fun testWithImage() { - val bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8) - val builder = Style.Builder() - builder.withImage("id", bitmap) - assertEquals(bitmap, builder.images[0].bitmap) - assertEquals("id", builder.images[0].id) - assertEquals(false, builder.images[0].sdf) - } - - @Test - fun testWithImages() { - val bitmap1 = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8) - val bitmap2 = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8) - val builder = Style.Builder() - builder.withBitmapImages(Pair("id1", bitmap1), Pair("id2", bitmap2)) - assertEquals(bitmap1, builder.images[0].bitmap) - assertEquals("id1", builder.images[0].id) - assertEquals(false, builder.images[0].sdf) - assertEquals(bitmap2, builder.images[1].bitmap) - assertEquals("id2", builder.images[1].id) - assertEquals(false, builder.images[1].sdf) - } - - @Test - fun testWithImageSdf() { - val bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8) - val builder = Style.Builder() - builder.withImage("id", bitmap, true) - assertEquals(bitmap, builder.images[0].bitmap) - assertEquals("id", builder.images[0].id) - assertEquals(true, builder.images[0].sdf) - } - - @Test - fun testWithImageSdfs() { - val bitmap1 = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8) - val bitmap2 = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8) - val builder = Style.Builder() - builder.withBitmapImages(true, Pair("id1", bitmap1), Pair("id2", bitmap2)) - assertEquals(bitmap1, builder.images[0].bitmap) - assertEquals("id1", builder.images[0].id) - assertEquals(true, builder.images[0].sdf) - assertEquals(bitmap2, builder.images[1].bitmap) - assertEquals("id2", builder.images[1].id) - assertEquals(true, builder.images[1].sdf) - } - - @Test - fun testWithImageDrawable() { - val drawable = ShapeDrawable() - drawable.intrinsicWidth = 1 - drawable.intrinsicHeight = 1 - val builder = Style.Builder() - builder.withImage("id", drawable) - assertTrue(BitmapUtils.equals( - BitmapUtils.getBitmapFromDrawable(drawable)!!, - builder.images[0].bitmap) - ) - assertEquals("id", builder.images[0].id) - assertEquals(false, builder.images[0].sdf) - } - - @Test - fun testWithImageDrawableSdf() { - val drawable = ShapeDrawable() - drawable.intrinsicWidth = 1 - drawable.intrinsicHeight = 1 - val builder = Style.Builder() - builder.withImage("id", drawable, true) - assertTrue(BitmapUtils.equals( - BitmapUtils.getBitmapFromDrawable(drawable)!!, - builder.images[0].bitmap) - ) - assertEquals("id", builder.images[0].id) - assertEquals(true, builder.images[0].sdf) - } - - @Test - fun testWithImageDrawables() { - val drawable1 = ShapeDrawable() - drawable1.intrinsicWidth = 1 - drawable1.intrinsicHeight = 1 - val drawable2 = ShapeDrawable() - drawable2.intrinsicWidth = 1 - drawable2.intrinsicHeight = 1 - val builder = Style.Builder() - builder.withDrawableImages(Pair<String, Drawable>("id1", drawable1), Pair<String, Drawable>("id2", drawable2)) - assertTrue(BitmapUtils.equals( - BitmapUtils.getBitmapFromDrawable(drawable1)!!, - builder.images[0].bitmap) - ) - assertEquals("id1", builder.images[0].id) - assertEquals(false, builder.images[0].sdf) - assertTrue(BitmapUtils.equals( - BitmapUtils.getBitmapFromDrawable(drawable2)!!, - builder.images[1].bitmap) - ) - assertEquals("id2", builder.images[1].id) - assertEquals(false, builder.images[1].sdf) - } - - @Test - fun testWithImageSdfDrawables() { - val drawable1 = ShapeDrawable() - drawable1.intrinsicWidth = 1 - drawable1.intrinsicHeight = 1 - val drawable2 = ShapeDrawable() - drawable2.intrinsicWidth = 1 - drawable2.intrinsicHeight = 1 - val builder = Style.Builder() - builder.withDrawableImages(true, Pair<String, Drawable>("id1", drawable1), Pair<String, Drawable>("id2", drawable2)) - assertTrue(BitmapUtils.equals( - BitmapUtils.getBitmapFromDrawable(drawable1)!!, - builder.images[0].bitmap) - ) - assertEquals("id1", builder.images[0].id) - assertEquals(true, builder.images[0].sdf) - assertTrue(BitmapUtils.equals( - BitmapUtils.getBitmapFromDrawable(drawable2)!!, - builder.images[1].bitmap) - ) - assertEquals("id2", builder.images[1].id) - assertEquals(true, builder.images[1].sdf) - } - - @Test - fun testWithTransitionOptions() { - val transitionOptions = TransitionOptions(100, 200) - val builder = Style.Builder() - builder.withTransition(transitionOptions) - assertEquals(100, builder.transitionOptions.duration) - assertEquals(200, builder.transitionOptions.delay) - } -}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt deleted file mode 100644 index a5070ae5c0..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt +++ /dev/null @@ -1,408 +0,0 @@ -package com.mapbox.mapboxsdk.maps - -import android.graphics.Bitmap -import android.graphics.drawable.ShapeDrawable -import com.mapbox.mapboxsdk.constants.MapboxConstants -import com.mapbox.mapboxsdk.style.layers.CannotAddLayerException -import com.mapbox.mapboxsdk.style.layers.SymbolLayer -import com.mapbox.mapboxsdk.style.layers.TransitionOptions -import com.mapbox.mapboxsdk.style.sources.CannotAddSourceException -import com.mapbox.mapboxsdk.style.sources.GeoJsonSource -import io.mockk.* -import org.junit.Assert -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.robolectric.RobolectricTestRunner - -@RunWith(RobolectricTestRunner::class) -class StyleTest { - - private lateinit var mapboxMap: MapboxMap - - private lateinit var nativeMapView: NativeMap - - @Before - fun setup() { - nativeMapView = mockk(relaxed = true) - mapboxMap = MapboxMap(nativeMapView, null, null, null, null, null, null) - every { nativeMapView.isDestroyed } returns false - mapboxMap.injectLocationComponent(spyk()) - } - - @Test - fun testFromUrl() { - val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS) - mapboxMap.setStyle(builder) - verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS } - } - - @Test - fun testFromJson() { - val builder = Style.Builder().fromJson("{}") - mapboxMap.setStyle(builder) - verify(exactly = 1) { nativeMapView.styleJson = "{}" } - } - - @Test - fun testEmptyBuilder() { - val builder = Style.Builder() - mapboxMap.setStyle(builder) - verify(exactly = 1) { nativeMapView.styleJson = Style.EMPTY_JSON } - } - - @Test - fun testWithLayer() { - val layer = mockk<SymbolLayer>() - every { layer.id } returns "1" - val builder = Style.Builder().withLayer(layer) - mapboxMap.setStyle(builder) - mapboxMap.onFinishLoadingStyle() - verify(exactly = 1) { nativeMapView.addLayerBelow(layer, MapboxConstants.LAYER_ID_ANNOTATIONS) } - } - - @Test - fun testWithLayerAbove() { - val layer = mockk<SymbolLayer>() - every { layer.id } returns "1" - val builder = Style.Builder().withLayerAbove(layer, "id") - mapboxMap.setStyle(builder) - mapboxMap.onFinishLoadingStyle() - verify(exactly = 1) { nativeMapView.addLayerAbove(layer, "id") } - } - - @Test - fun testWithLayerBelow() { - val layer = mockk<SymbolLayer>() - every { layer.id } returns "1" - val builder = Style.Builder().withLayerBelow(layer, "id") - mapboxMap.setStyle(builder) - mapboxMap.onFinishLoadingStyle() - verify(exactly = 1) { nativeMapView.addLayerBelow(layer, "id") } - } - - @Test - fun testWithLayerAt() { - val layer = mockk<SymbolLayer>() - every { layer.id } returns "1" - val builder = Style.Builder().withLayerAt(layer, 1) - mapboxMap.setStyle(builder) - mapboxMap.onFinishLoadingStyle() - verify(exactly = 1) { nativeMapView.addLayerAt(layer, 1) } - } - - @Test - fun testWithSource() { - val source = mockk<GeoJsonSource>() - every { source.id } returns "1" - val builder = Style.Builder().withSource(source) - mapboxMap.setStyle(builder) - mapboxMap.onFinishLoadingStyle() - verify(exactly = 1) { nativeMapView.addSource(source) } - } - - @Test - fun testWithTransitionOptions() { - val transitionOptions = TransitionOptions(100, 200) - val builder = Style.Builder().withTransition(transitionOptions) - mapboxMap.setStyle(builder) - mapboxMap.onFinishLoadingStyle() - verify(exactly = 1) { nativeMapView.transitionOptions = transitionOptions } - } - - @Test - fun testWithFromLoadingSource() { - val source = mockk<GeoJsonSource>() - every { source.id } returns "1" - val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withSource(source) - mapboxMap.setStyle(builder) - verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS } - mapboxMap.notifyStyleLoaded() - verify(exactly = 1) { nativeMapView.addSource(source) } - } - - @Test - fun testWithFromLoadingLayer() { - val layer = mockk<SymbolLayer>() - every { layer.id } returns "1" - val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withLayer(layer) - mapboxMap.setStyle(builder) - verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS } - mapboxMap.notifyStyleLoaded() - verify(exactly = 1) { nativeMapView.addLayerBelow(layer, MapboxConstants.LAYER_ID_ANNOTATIONS) } - } - - @Test - fun testWithFromLoadingLayerAt() { - val layer = mockk<SymbolLayer>() - every { layer.id } returns "1" - val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withLayerAt(layer, 1) - mapboxMap.setStyle(builder) - verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS } - mapboxMap.notifyStyleLoaded() - verify(exactly = 1) { nativeMapView.addLayerAt(layer, 1) } - } - - @Test - fun testWithFromLoadingLayerBelow() { - val layer = mockk<SymbolLayer>() - every { layer.id } returns "1" - val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withLayerBelow(layer, "below") - mapboxMap.setStyle(builder) - verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS } - mapboxMap.notifyStyleLoaded() - verify(exactly = 1) { nativeMapView.addLayerBelow(layer, "below") } - } - - @Test - fun testWithFromLoadingLayerAbove() { - val layer = mockk<SymbolLayer>() - every { layer.id } returns "1" - val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withLayerBelow(layer, "below") - mapboxMap.setStyle(builder) - verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS } - mapboxMap.notifyStyleLoaded() - verify(exactly = 1) { nativeMapView.addLayerBelow(layer, "below") } - } - - @Test - fun testWithFromLoadingTransitionOptions() { - val transitionOptions = TransitionOptions(100, 200) - val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withTransition(transitionOptions) - mapboxMap.setStyle(builder) - verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS } - mapboxMap.notifyStyleLoaded() - verify(exactly = 1) { nativeMapView.transitionOptions = transitionOptions } - } - - @Test - fun testFromCallback() { - val callback = mockk<Style.OnStyleLoaded>() - every { callback.onStyleLoaded(any()) } answers {} - val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS) - mapboxMap.setStyle(builder, callback) - verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS } - mapboxMap.notifyStyleLoaded() - verify(exactly = 1) { callback.onStyleLoaded(any()) } - } - - @Test - fun testWithCallback() { - val callback = mockk<Style.OnStyleLoaded>() - every { callback.onStyleLoaded(any()) } answers {} - val source = mockk<GeoJsonSource>() - every { source.id } returns "1" - val builder = Style.Builder().withSource(source) - mapboxMap.setStyle(builder, callback) - mapboxMap.onFinishLoadingStyle() - verify(exactly = 1) { nativeMapView.addSource(source) } - verify(exactly = 1) { callback.onStyleLoaded(any()) } - } - - @Test - fun testGetAsyncWith() { - val callback = mockk<Style.OnStyleLoaded>() - every { callback.onStyleLoaded(any()) } answers {} - mapboxMap.getStyle(callback) - val source = mockk<GeoJsonSource>() - every { source.id } returns "1" - val builder = Style.Builder().withSource(source) - mapboxMap.setStyle(builder) - mapboxMap.onFinishLoadingStyle() - verify(exactly = 1) { nativeMapView.addSource(source) } - verify(exactly = 1) { callback.onStyleLoaded(any()) } - } - - @Test - fun testGetAsyncFrom() { - val callback = mockk<Style.OnStyleLoaded>() - every { callback.onStyleLoaded(any()) } answers {} - mapboxMap.getStyle(callback) - val source = mockk<GeoJsonSource>() - every { source.id } returns "1" - val builder = Style.Builder().fromJson("{}") - mapboxMap.setStyle(builder) - verify(exactly = 1) { nativeMapView.styleJson = "{}" } - mapboxMap.notifyStyleLoaded() - verify(exactly = 1) { callback.onStyleLoaded(any()) } - } - - @Test - fun testGetAsyncWithFrom() { - val callback = mockk<Style.OnStyleLoaded>() - every { callback.onStyleLoaded(any()) } answers {} - mapboxMap.getStyle(callback) - val source = mockk<GeoJsonSource>() - every { source.id } returns "1" - val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withSource(source) - mapboxMap.setStyle(builder) - verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS } - mapboxMap.notifyStyleLoaded() - verify(exactly = 1) { nativeMapView.addSource(source) } - verify(exactly = 1) { callback.onStyleLoaded(any()) } - } - - @Test - fun testGetNullStyle() { - Assert.assertNull(mapboxMap.style) - } - - @Test - fun testGetNullWhileLoading() { - val transitionOptions = TransitionOptions(100, 200) - val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withTransition(transitionOptions) - mapboxMap.setStyle(builder) - Assert.assertNull(mapboxMap.style) - mapboxMap.notifyStyleLoaded() - Assert.assertNotNull(mapboxMap.style) - } - - @Test - fun testNotReinvokeSameListener() { - val callback = mockk<Style.OnStyleLoaded>() - every { callback.onStyleLoaded(any()) } answers {} - mapboxMap.getStyle(callback) - val source = mockk<GeoJsonSource>() - every { source.id } returns "1" - val builder = Style.Builder().fromJson("{}") - mapboxMap.setStyle(builder) - verify(exactly = 1) { nativeMapView.styleJson = "{}" } - mapboxMap.notifyStyleLoaded() - mapboxMap.setStyle(Style.MAPBOX_STREETS) - verify(exactly = 1) { callback.onStyleLoaded(any()) } - } - - @Test(expected = IllegalStateException::class) - fun testIllegalStateExceptionWithStyleReload() { - val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS) - mapboxMap.setStyle(builder) - mapboxMap.notifyStyleLoaded() - val style = mapboxMap.style - mapboxMap.setStyle(Style.Builder().fromUrl(Style.DARK)) - style!!.addLayer(mockk<SymbolLayer>()) - } - - @Test - fun testAddImage() { - val bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888) - val builder = Style.Builder().fromUrl(Style.SATELLITE).withImage("id", bitmap) - mapboxMap.setStyle(builder) - verify(exactly = 1) { nativeMapView.styleUri = Style.SATELLITE } - verify(exactly = 0) { nativeMapView.addImages(any()) } - mapboxMap.notifyStyleLoaded() - verify(exactly = 1) { nativeMapView.addImages(any()) } - } - - @Test - fun testAddDrawable() { - val drawable = ShapeDrawable() - drawable.intrinsicHeight = 10 - drawable.intrinsicWidth = 10 - val builder = Style.Builder().fromUrl(Style.SATELLITE).withImage("id", drawable) - mapboxMap.setStyle(builder) - verify(exactly = 1) { nativeMapView.styleUri = Style.SATELLITE } - verify(exactly = 0) { nativeMapView.addImages(any()) } - mapboxMap.notifyStyleLoaded() - verify(exactly = 1) { nativeMapView.addImages(any()) } - } - - @Test - fun testSourceSkippedIfAdditionFails() { - val source1 = mockk<GeoJsonSource>(relaxed = true) - every { source1.id } returns "source1" - val source2 = mockk<GeoJsonSource>(relaxed = true) - every { source2.id } returns "source1" // same ID - - val builder = Style.Builder().withSource(source1) - mapboxMap.setStyle(builder) - mapboxMap.notifyStyleLoaded() - - every { nativeMapView.addSource(any()) } throws CannotAddSourceException("Duplicate ID") - - try { - mapboxMap.style!!.addSource(source2) - } catch (ex: Exception) { - Assert.assertEquals("Source that failed to be added shouldn't be cached", source1, mapboxMap.style!!.getSource("source1")) - } - } - - @Test - fun testLayerSkippedIfAdditionFails() { - val layer1 = mockk<SymbolLayer>(relaxed = true) - every { layer1.id } returns "layer1" - val layer2 = mockk<SymbolLayer>(relaxed = true) - every { layer2.id } returns "layer1" // same ID - - val builder = Style.Builder().withLayer(layer1) - mapboxMap.setStyle(builder) - mapboxMap.notifyStyleLoaded() - - every { nativeMapView.addLayer(any()) } throws CannotAddLayerException("Duplicate ID") - - try { - mapboxMap.style!!.addLayer(layer2) - } catch (ex: Exception) { - Assert.assertEquals("Layer that failed to be added shouldn't be cached", layer1, mapboxMap.style!!.getLayer("layer1")) - } - } - - @Test - fun testLayerSkippedIfAdditionBelowFails() { - val layer1 = mockk<SymbolLayer>(relaxed = true) - every { layer1.id } returns "layer1" - val layer2 = mockk<SymbolLayer>(relaxed = true) - every { layer2.id } returns "layer1" // same ID - - val builder = Style.Builder().withLayer(layer1) - mapboxMap.setStyle(builder) - mapboxMap.notifyStyleLoaded() - - every { nativeMapView.addLayerBelow(any(), "") } throws CannotAddLayerException("Duplicate ID") - - try { - mapboxMap.style!!.addLayerBelow(layer2, "") - } catch (ex: Exception) { - Assert.assertEquals("Layer that failed to be added shouldn't be cached", layer1, mapboxMap.style!!.getLayer("layer1")) - } - } - - @Test - fun testLayerSkippedIfAdditionAboveFails() { - val layer1 = mockk<SymbolLayer>(relaxed = true) - every { layer1.id } returns "layer1" - val layer2 = mockk<SymbolLayer>(relaxed = true) - every { layer2.id } returns "layer1" // same ID - - val builder = Style.Builder().withLayer(layer1) - mapboxMap.setStyle(builder) - mapboxMap.notifyStyleLoaded() - - every { nativeMapView.addLayerAbove(any(), "") } throws CannotAddLayerException("Duplicate ID") - - try { - mapboxMap.style!!.addLayerAbove(layer2, "") - } catch (ex: Exception) { - Assert.assertEquals("Layer that failed to be added shouldn't be cached", layer1, mapboxMap.style!!.getLayer("layer1")) - } - } - - @Test - fun testLayerSkippedIfAdditionAtFails() { - val layer1 = mockk<SymbolLayer>(relaxed = true) - every { layer1.id } returns "layer1" - val layer2 = mockk<SymbolLayer>(relaxed = true) - every { layer2.id } returns "layer1" // same ID - - val builder = Style.Builder().withLayer(layer1) - mapboxMap.setStyle(builder) - mapboxMap.notifyStyleLoaded() - - every { nativeMapView.addLayerAt(any(), 5) } throws CannotAddLayerException("Duplicate ID") - - try { - mapboxMap.style!!.addLayerAt(layer2, 5) - } catch (ex: Exception) { - Assert.assertEquals("Layer that failed to be added shouldn't be cached", layer1, mapboxMap.style!!.getLayer("layer1")) - } - } -}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/TransformTest.kt b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/TransformTest.kt deleted file mode 100644 index fddf7eeaff..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/TransformTest.kt +++ /dev/null @@ -1,183 +0,0 @@ -package com.mapbox.mapboxsdk.maps - -import com.mapbox.mapboxsdk.camera.CameraPosition -import com.mapbox.mapboxsdk.camera.CameraUpdateFactory -import com.mapbox.mapboxsdk.geometry.LatLng -import io.mockk.* -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.robolectric.RobolectricTestRunner - -@RunWith(RobolectricTestRunner::class) -class TransformTest { - - private lateinit var mapView: MapView - private lateinit var nativeMapView: NativeMap - private lateinit var transform: Transform - - @Before - fun setup() { - val cameraChangeDispatcher = spyk<CameraChangeDispatcher>() - mapView = mockk() - nativeMapView = mockk() - transform = Transform(mapView, nativeMapView, cameraChangeDispatcher) - every { nativeMapView.isDestroyed } returns false - every { nativeMapView.cameraPosition } returns CameraPosition.DEFAULT - every { nativeMapView.cancelTransitions() } answers {} - every { nativeMapView.jumpTo(any(), any(), any(), any(), any()) } answers {} - every { nativeMapView.easeTo(any(), any(), any(), any(), any(), any(), any()) } answers {} - every { nativeMapView.flyTo(any(), any(), any(), any(), any(), any()) } answers {} - every { nativeMapView.minZoom = any() } answers {} - every { nativeMapView.maxZoom = any() } answers {} - } - - @Test - fun testMoveCamera() { - val mapboxMap = mockk<MapboxMap>() - every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT } - - val callback = mockk<MapboxMap.CancelableCallback>() - every { callback.onFinish() } answers {} - - val target = LatLng(1.0, 2.0) - val expected = CameraPosition.Builder().target(target).build() - val update = CameraUpdateFactory.newCameraPosition(expected) - transform.moveCamera(mapboxMap, update, callback) - - verify { nativeMapView.jumpTo(target, -1.0, -1.0, -1.0, null) } - verify { callback.onFinish() } - } - - @Test - fun testMoveCameraToSamePosition() { - val mapboxMap = mockk<MapboxMap>() - every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT } - - val callback = mockk<MapboxMap.CancelableCallback>() - every { callback.onFinish() } answers {} - - val expected = CameraPosition.DEFAULT - val update = CameraUpdateFactory.newCameraPosition(expected) - - transform.moveCamera(mapboxMap, update, null) // Initialize camera position - transform.moveCamera(mapboxMap, update, callback) - - verify(exactly = 1, verifyBlock = { nativeMapView.jumpTo(any(), any(), any(), any(), any()) }) - verify { callback.onFinish() } - } - - @Test - fun testEaseCamera() { - val mapboxMap = mockk<MapboxMap>() - every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT } - - every { mapView.addOnCameraDidChangeListener(any()) } answers { transform.onCameraDidChange(true) } - every { mapView.removeOnCameraDidChangeListener(any()) } answers {} - - val callback = mockk<MapboxMap.CancelableCallback>() - every { callback.onFinish() } answers {} - - val target = LatLng(1.0, 2.0) - val expected = CameraPosition.Builder().target(target).build() - val update = CameraUpdateFactory.newCameraPosition(expected) - - transform.easeCamera(mapboxMap, update, 100, false, callback) - - verify { nativeMapView.easeTo(target, -1.0, -1.0, -1.0, null, 100, false) } - verify { callback.onFinish() } - } - - @Test - fun testEaseCameraToSamePosition() { - val mapboxMap = mockk<MapboxMap>() - every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT } - - val callback = mockk<MapboxMap.CancelableCallback>() - every { callback.onFinish() } answers {} - - val expected = CameraPosition.DEFAULT - val update = CameraUpdateFactory.newCameraPosition(expected) - transform.moveCamera(mapboxMap, update, null) - - transform.easeCamera(mapboxMap, update, 100, false, callback) - - verify(exactly = 0, verifyBlock = { nativeMapView.easeTo(any(), any(), any(), any(), any(), any(), any()) }) - verify { callback.onFinish() } - } - - @Test - fun testAnimateCamera() { - val mapboxMap = mockk<MapboxMap>() - every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT } - - every { mapView.addOnCameraDidChangeListener(any()) } answers { transform.onCameraDidChange(true) } - every { mapView.removeOnCameraDidChangeListener(any()) } answers {} - - val callback = mockk<MapboxMap.CancelableCallback>() - every { callback.onFinish() } answers {} - - val target = LatLng(1.0, 2.0) - val expected = CameraPosition.Builder().target(target).build() - val update = CameraUpdateFactory.newCameraPosition(expected) - - transform.animateCamera(mapboxMap, update, 100, callback) - - verify { nativeMapView.flyTo(target, -1.0, -1.0, -1.0, null, 100) } - verify { callback.onFinish() } - } - - @Test - fun testAnimateCameraToSamePosition() { - val mapboxMap = mockk<MapboxMap>() - every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT } - - val callback = mockk<MapboxMap.CancelableCallback>() - every { callback.onFinish() } answers {} - - val expected = CameraPosition.DEFAULT - val update = CameraUpdateFactory.newCameraPosition(expected) - transform.moveCamera(mapboxMap, update, null) - - transform.animateCamera(mapboxMap, update, 100, callback) - - verify(exactly = 0, verifyBlock = { nativeMapView.flyTo(any(), any(), any(), any(), any(), any()) }) - verify { callback.onFinish() } - } - - @Test - fun testMinZoom() { - transform.minZoom = 10.0 - verify { nativeMapView.minZoom = 10.0 } - } - - @Test - fun testMaxZoom() { - transform.maxZoom = 10.0 - verify { nativeMapView.maxZoom = 10.0 } - } - - @Test - fun testCancelNotInvokedFromOnFinish() { - val slot = slot<MapView.OnCameraDidChangeListener>() - every { mapView.addOnCameraDidChangeListener(capture(slot)) } answers { slot.captured.onCameraDidChange(true) } - every { mapView.removeOnCameraDidChangeListener(any()) } answers {} - // regression test for https://github.com/mapbox/mapbox-gl-native/issues/13735 - val mapboxMap = mockk<MapboxMap>() - every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT } - - val target = LatLng(1.0, 2.0) - val expected = CameraPosition.Builder().target(target).build() - - val callback = object : MapboxMap.CancelableCallback { - override fun onCancel() { - throw IllegalStateException("onCancel shouldn't be called from onFinish") - } - - override fun onFinish() { - transform.animateCamera(mapboxMap, CameraUpdateFactory.newCameraPosition(expected), 500, null) - } - } - transform.animateCamera(mapboxMap, CameraUpdateFactory.newCameraPosition(expected), 500, callback) - } -}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java deleted file mode 100644 index a84e93cd75..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java +++ /dev/null @@ -1,433 +0,0 @@ -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.camera.CameraPosition; -import com.mapbox.mapboxsdk.maps.widgets.CompassView; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; - -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; -import static org.mockito.Mockito.verify; - -public class UiSettingsTest { - - @InjectMocks - 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); - - private UiSettings uiSettings; - - @Before - public void beforeTest() { - uiSettings = new UiSettings(projection, focalPointChangeListener, compassView, imageView, logoView, 1); - } - - @Test - public void testSanity() { - assertNotNull("uiSettings should not be null", uiSettings); - } - - @Test - public void testCompassEnabled() { - when(compassView.isEnabled()).thenReturn(true); - uiSettings.setCompassEnabled(true); - assertEquals("Compass should be enabled", true, uiSettings.isCompassEnabled()); - } - - @Test - public void testCompassDisabled() { - uiSettings.setCompassEnabled(false); - assertEquals("Compass should be disabled", false, uiSettings.isCompassEnabled()); - } - - @Test - public void testCompassGravity() { - 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); - assertTrue("Compass margin right should be same", uiSettings.getCompassMarginRight() == 3); - assertTrue("Compass margin bottom should be same", uiSettings.getCompassMarginBottom() == 4); - } - - @Test - 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()); - } - - @Test - public void testLogoEnabled() { - uiSettings.setLogoEnabled(true); - assertEquals("Logo should be enabled", true, uiSettings.isLogoEnabled()); - } - - @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() { - 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); - assertTrue("Compass margin right should be same", uiSettings.getLogoMarginRight() == 3); - assertTrue("Compass margin bottom should be same", uiSettings.getLogoMarginBottom() == 4); - } - - @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.isAttributionEnabled()); - } - - @Test - public void testAttributionGravity() { - 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); - assertTrue("Attribution margin right should be same", uiSettings.getAttributionMarginRight() == 3); - assertTrue("Attribution margin bottom should be same", uiSettings.getAttributionMarginBottom() == 4); - } - - @Test - public void testRotateGesturesEnabled() { - uiSettings.setRotateGesturesEnabled(true); - assertEquals("Rotate gesture should be enabled", true, uiSettings.isRotateGesturesEnabled()); - } - - @Test - public void testRotateGesturesDisabled() { - uiSettings.setRotateGesturesEnabled(false); - assertEquals("Rotate gesture should be disabled", false, uiSettings.isRotateGesturesEnabled()); - } - - @Test - public void testRotateGestureChangeAllowed() { - uiSettings.setRotateGesturesEnabled(false); - assertEquals("Rotate gesture should be false", false, uiSettings.isRotateGesturesEnabled()); - uiSettings.setRotateGesturesEnabled(true); - assertEquals("Rotate gesture should be true", true, uiSettings.isRotateGesturesEnabled()); - } - - @Test - public void testTiltGesturesEnabled() { - uiSettings.setTiltGesturesEnabled(true); - assertEquals("Tilt gesture should be enabled", true, uiSettings.isTiltGesturesEnabled()); - } - - @Test - public void testTiltGesturesDisabled() { - uiSettings.setTiltGesturesEnabled(false); - assertEquals("Tilt gesture should be disabled", false, uiSettings.isTiltGesturesEnabled()); - } - - @Test - public void testTiltGestureChangeAllowed() { - uiSettings.setTiltGesturesEnabled(false); - assertEquals("Tilt gesture should be false", false, uiSettings.isTiltGesturesEnabled()); - uiSettings.setTiltGesturesEnabled(true); - assertEquals("Tilt gesture should be true", true, uiSettings.isTiltGesturesEnabled()); - } - - @Test - public void testZoomGesturesEnabled() { - uiSettings.setZoomGesturesEnabled(true); - assertEquals("Zoom gesture should be enabled", true, uiSettings.isZoomGesturesEnabled()); - } - - @Test - public void testZoomGesturesDisabled() { - uiSettings.setZoomGesturesEnabled(false); - assertEquals("Zoom gesture should be disabled", false, uiSettings.isZoomGesturesEnabled()); - } - - @Test - public void testZoomGestureChangeAllowed() { - uiSettings.setZoomGesturesEnabled(false); - assertEquals("Zoom gesture should be false", false, uiSettings.isZoomGesturesEnabled()); - uiSettings.setZoomGesturesEnabled(true); - assertEquals("Zoom gesture should be true", true, uiSettings.isZoomGesturesEnabled()); - } - - @Test - public void testDoubleTapGesturesEnabled() { - uiSettings.setDoubleTapGesturesEnabled(true); - assertEquals("DoubleTap gesture should be enabled", true, uiSettings.isDoubleTapGesturesEnabled()); - } - - @Test - public void testDoubleTapGesturesDisabled() { - uiSettings.setDoubleTapGesturesEnabled(false); - assertEquals("DoubleTap gesture should be disabled", false, uiSettings.isDoubleTapGesturesEnabled()); - } - - @Test - public void testDoubleTapGestureChangeAllowed() { - uiSettings.setDoubleTapGesturesEnabled(false); - assertEquals("DoubleTap gesture should be false", false, uiSettings.isDoubleTapGesturesEnabled()); - uiSettings.setDoubleTapGesturesEnabled(true); - assertEquals("DoubleTap gesture should be true", true, uiSettings.isDoubleTapGesturesEnabled()); - } - - @Test - public void testQuickZoomGesturesEnabled() { - uiSettings.setQuickZoomGesturesEnabled(true); - assertEquals("QuickZoom gesture should be enabled", true, uiSettings.isQuickZoomGesturesEnabled()); - } - - @Test - public void testQuickZoomGesturesDisabled() { - uiSettings.setQuickZoomGesturesEnabled(false); - assertEquals("QuickZoom gesture should be disabled", false, uiSettings.isQuickZoomGesturesEnabled()); - } - - @Test - public void testQuickZoomGestureChangeAllowed() { - uiSettings.setQuickZoomGesturesEnabled(false); - assertEquals("QuickZoom gesture should be false", false, uiSettings.isQuickZoomGesturesEnabled()); - uiSettings.setQuickZoomGesturesEnabled(true); - assertEquals("QuickZoom gesture should be true", true, uiSettings.isQuickZoomGesturesEnabled()); - } - - @Test - public void testScrollGesturesEnabled() { - uiSettings.setScrollGesturesEnabled(true); - assertEquals("Scroll gesture should be enabled", true, uiSettings.isScrollGesturesEnabled()); - } - - @Test - public void testScrollGesturesDisabled() { - uiSettings.setScrollGesturesEnabled(false); - assertEquals("Scroll gesture should be disabled", false, uiSettings.isScrollGesturesEnabled()); - } - - @Test - public void testScrollGestureChangeAllowed() { - uiSettings.setScrollGesturesEnabled(false); - assertEquals("Scroll gesture should be false", false, uiSettings.isScrollGesturesEnabled()); - uiSettings.setScrollGesturesEnabled(true); - assertEquals("Scroll gesture should be true", true, uiSettings.isScrollGesturesEnabled()); - } - - @Test - public void testScaleVelocityAnimationEnabled() { - uiSettings.setScaleVelocityAnimationEnabled(true); - assertEquals("Scale velocity animation should be enabled", true, uiSettings.isScaleVelocityAnimationEnabled()); - } - - @Test - public void testScaleVelocityAnimationDisabled() { - uiSettings.setScaleVelocityAnimationEnabled(false); - assertEquals("Scale velocity animation should be disabled", false, uiSettings.isScaleVelocityAnimationEnabled()); - } - - @Test - public void testRotateVelocityAnimationEnabled() { - uiSettings.setRotateVelocityAnimationEnabled(true); - assertEquals("Rotate velocity animation should be enabled", true, uiSettings.isRotateVelocityAnimationEnabled()); - } - - @Test - public void testRotateVelocityAnimationDisabled() { - uiSettings.setRotateVelocityAnimationEnabled(false); - assertEquals("Rotate velocity animation should be disabled", false, uiSettings.isRotateVelocityAnimationEnabled()); - } - - @Test - public void testFlingVelocityAnimationEnabled() { - uiSettings.setFlingVelocityAnimationEnabled(true); - assertEquals("Fling velocity animation should be enabled", true, uiSettings.isFlingVelocityAnimationEnabled()); - } - - @Test - public void testFlingVelocityAnimationDisabled() { - uiSettings.setFlingVelocityAnimationEnabled(false); - assertEquals("Fling velocity animation should be disabled", false, uiSettings.isFlingVelocityAnimationEnabled()); - } - - @Test - public void testAllVelocityAnimationsEnabled() { - uiSettings.setAllVelocityAnimationsEnabled(true); - assertEquals("Scale velocity animation should be enabled", true, uiSettings.isScaleVelocityAnimationEnabled()); - assertEquals("Rotate velocity animation should be enabled", true, uiSettings.isRotateVelocityAnimationEnabled()); - assertEquals("Fling velocity animation should be enabled", true, uiSettings.isFlingVelocityAnimationEnabled()); - } - - @Test - public void testAllVelocityAnimationsDisabled() { - uiSettings.setAllVelocityAnimationsEnabled(false); - assertEquals("Scale velocity animation should be disabled", false, uiSettings.isScaleVelocityAnimationEnabled()); - assertEquals("Rotate velocity animation should be disabled", false, uiSettings.isRotateVelocityAnimationEnabled()); - assertEquals("Fling velocity animation should be disabled", false, uiSettings.isFlingVelocityAnimationEnabled()); - } - - @Test - public void testDisableRotateWhenScalingEnabled() { - uiSettings.setDisableRotateWhenScaling(true); - assertEquals("Rotate disabling should be enabled", true, - uiSettings.isDisableRotateWhenScaling()); - } - - @Test - public void testDisableRotateWhenScalingDisabled() { - uiSettings.setDisableRotateWhenScaling(false); - assertEquals("Rotate disabling should be disabled", false, - uiSettings.isDisableRotateWhenScaling()); - } - - @Test - public void testIncreaseScaleThresholdWhenRotatingEnabled() { - uiSettings.setIncreaseScaleThresholdWhenRotating(true); - assertEquals("Scale threshold increase should be enabled", true, uiSettings.isIncreaseScaleThresholdWhenRotating()); - } - - @Test - public void testIncreaseScaleThresholdWhenRotatingDisabled() { - uiSettings.setIncreaseScaleThresholdWhenRotating(false); - assertEquals("Scale threshold increase should be disabled", false, - uiSettings.isIncreaseScaleThresholdWhenRotating()); - } - - @Test - public void testAllGesturesEnabled() { - uiSettings.setAllGesturesEnabled(true); - assertEquals("Rotate gesture should be enabled", true, uiSettings.isRotateGesturesEnabled()); - assertEquals("Tilt gesture should be enabled", true, uiSettings.isTiltGesturesEnabled()); - assertEquals("Zoom gesture should be enabled", true, uiSettings.isZoomGesturesEnabled()); - assertEquals("Scroll gesture should be enabled", true, uiSettings.isScrollGesturesEnabled()); - } - - @Test - public void testAllGesturesDisabled() { - uiSettings.setAllGesturesEnabled(false); - assertEquals("Rotate gesture should be enabled", false, uiSettings.isRotateGesturesEnabled()); - assertEquals("Tilt gesture should be disabled", false, uiSettings.isTiltGesturesEnabled()); - assertEquals("Zoom gesture should be disabled", false, uiSettings.isZoomGesturesEnabled()); - assertEquals("Scroll gesture should be disabled", false, uiSettings.isScrollGesturesEnabled()); - } - - @Test - public void testAreAllGesturesEnabled() { - uiSettings.setAllGesturesEnabled(true); - assertEquals("All gestures check should return true", true, - uiSettings.areAllGesturesEnabled()); - } - - @Test - public void testAreAllGesturesEnabledWithOneGestureDisabled() { - uiSettings.setAllGesturesEnabled(true); - uiSettings.setScrollGesturesEnabled(false); - assertEquals("All gestures check should return false", false, - uiSettings.areAllGesturesEnabled()); - } - - @Test - public void testZoomRateDefaultValue() { - assertEquals("Default zoom rate should be 1.0f", 1.0f, - uiSettings.getZoomRate(), 0); - } - - @Test - public void testZoomRate() { - uiSettings.setZoomRate(0.83f); - assertEquals("Zoom rate should be 0.83f", 0.83f, - uiSettings.getZoomRate(), 0); - } - - @Test - public void testUpdateWhenCompassViewNotHidden() { - CameraPosition cameraPosition = new CameraPosition.Builder(CameraPosition.DEFAULT).bearing(24.0f).build(); - when(compassView.isHidden()).thenReturn(false); - uiSettings.update(cameraPosition); - verify(compassView).update(-24.0f); - } - - @Test - public void testUpdateWhenCompassViewHidden() { - CameraPosition cameraPosition = new CameraPosition.Builder(CameraPosition.DEFAULT).bearing(24.0f).build(); - when(compassView.isHidden()).thenReturn(true); - uiSettings.update(cameraPosition); - verify(compassView).update(-24.0f); - } -} |