[android] updated location tracking gestures management tests
This commit is contained in:
committed by
Łukasz Paczos
parent
d625993da2
commit
b2d4b82cdf
@@ -54,13 +54,14 @@ final class LocationCameraController implements MapboxAnimator.OnCameraAnimation
|
||||
MoveGestureDetector moveGestureDetector,
|
||||
OnCameraTrackingChangedListener internalCameraTrackingChangedListener,
|
||||
OnCameraMoveInvalidateListener onCameraMoveInvalidateListener,
|
||||
AndroidGesturesManager androidGesturesManager) {
|
||||
AndroidGesturesManager initialGesturesManager,
|
||||
AndroidGesturesManager internalGesturesManager) {
|
||||
this.mapboxMap = mapboxMap;
|
||||
this.moveGestureDetector = moveGestureDetector;
|
||||
this.internalCameraTrackingChangedListener = internalCameraTrackingChangedListener;
|
||||
this.onCameraMoveInvalidateListener = onCameraMoveInvalidateListener;
|
||||
this.internalGesturesManager = androidGesturesManager;
|
||||
this.initialGesturesManager = androidGesturesManager;
|
||||
this.internalGesturesManager = internalGesturesManager;
|
||||
this.initialGesturesManager = initialGesturesManager;
|
||||
}
|
||||
|
||||
void initializeOptions(LocationComponentOptions options) {
|
||||
|
||||
@@ -40,6 +40,7 @@ public class LocationCameraControllerTest {
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
float moveThreshold = 5f;
|
||||
when(options.trackingInitialMoveThreshold()).thenReturn(moveThreshold);
|
||||
when(options.trackingGesturesManagement()).thenReturn(true);
|
||||
camera.initializeOptions(options);
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING_GPS);
|
||||
@@ -47,15 +48,33 @@ public class LocationCameraControllerTest {
|
||||
verify(moveGestureDetector).setMoveThreshold(moveThreshold);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCameraMode_gestureThresholdNotAdjustedWhenDisabled() {
|
||||
MoveGestureDetector moveGestureDetector = mock(MoveGestureDetector.class);
|
||||
LocationCameraController camera = buildCamera(moveGestureDetector);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
float moveThreshold = 5f;
|
||||
when(options.trackingInitialMoveThreshold()).thenReturn(moveThreshold);
|
||||
when(options.trackingGesturesManagement()).thenReturn(false);
|
||||
camera.initializeOptions(options);
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING_GPS);
|
||||
|
||||
verify(moveGestureDetector, times(0)).setMoveThreshold(moveThreshold);
|
||||
verify(moveGestureDetector, times(0)).setMoveThreshold(0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCameraMode_gestureThresholdIsResetWhenNotTracking() {
|
||||
MoveGestureDetector moveGestureDetector = mock(MoveGestureDetector.class);
|
||||
LocationCameraController camera = buildCamera(moveGestureDetector);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
when(options.trackingGesturesManagement()).thenReturn(true);
|
||||
camera.initializeOptions(options);
|
||||
|
||||
camera.setCameraMode(CameraMode.NONE);
|
||||
|
||||
verify(moveGestureDetector).setMoveThreshold(0f);
|
||||
verify(moveGestureDetector, times(2)).setMoveThreshold(0f); // one for initialization
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -180,7 +199,9 @@ public class LocationCameraControllerTest {
|
||||
when(projection.toScreenLocation(any(LatLng.class))).thenReturn(pointF);
|
||||
when(mapboxMap.getProjection()).thenReturn(projection);
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
when(options.trackingGesturesManagement()).thenReturn(true);
|
||||
camera.initializeOptions(options);
|
||||
camera.setCameraMode(CameraMode.TRACKING);
|
||||
LatLng latLng = mock(LatLng.class);
|
||||
|
||||
@@ -310,14 +331,41 @@ public class LocationCameraControllerTest {
|
||||
verify(mapboxMap).moveCamera(any(CameraUpdate.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gesturesManagement_enabled() {
|
||||
MapboxMap mapboxMap = mock(MapboxMap.class);
|
||||
AndroidGesturesManager initialGesturesManager = mock(AndroidGesturesManager.class);
|
||||
AndroidGesturesManager internalGesturesManager = mock(AndroidGesturesManager.class);
|
||||
LocationCameraController camera = buildCamera(mapboxMap, initialGesturesManager, internalGesturesManager);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
when(options.trackingGesturesManagement()).thenReturn(true);
|
||||
camera.initializeOptions(options);
|
||||
|
||||
verify(mapboxMap).setGesturesManager(internalGesturesManager, true, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gesturesManagement_disabled() {
|
||||
MapboxMap mapboxMap = mock(MapboxMap.class);
|
||||
AndroidGesturesManager initialGesturesManager = mock(AndroidGesturesManager.class);
|
||||
AndroidGesturesManager internalGesturesManager = mock(AndroidGesturesManager.class);
|
||||
LocationCameraController camera = buildCamera(mapboxMap, initialGesturesManager, internalGesturesManager);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
when(options.trackingGesturesManagement()).thenReturn(false);
|
||||
camera.initializeOptions(options);
|
||||
|
||||
verify(mapboxMap).setGesturesManager(initialGesturesManager, true, true);
|
||||
}
|
||||
|
||||
private LocationCameraController buildCamera(OnCameraTrackingChangedListener onCameraTrackingChangedListener) {
|
||||
MapboxMap mapboxMap = mock(MapboxMap.class);
|
||||
when(mapboxMap.getUiSettings()).thenReturn(mock(UiSettings.class));
|
||||
MoveGestureDetector moveGestureDetector = mock(MoveGestureDetector.class);
|
||||
OnCameraMoveInvalidateListener onCameraMoveInvalidateListener = mock(OnCameraMoveInvalidateListener.class);
|
||||
AndroidGesturesManager androidGesturesManager = mock(AndroidGesturesManager.class);
|
||||
AndroidGesturesManager initialGesturesManager = mock(AndroidGesturesManager.class);
|
||||
AndroidGesturesManager internalGesturesManager = mock(AndroidGesturesManager.class);
|
||||
return new LocationCameraController(mapboxMap, moveGestureDetector,
|
||||
onCameraTrackingChangedListener, onCameraMoveInvalidateListener, androidGesturesManager);
|
||||
onCameraTrackingChangedListener, onCameraMoveInvalidateListener, initialGesturesManager, internalGesturesManager);
|
||||
}
|
||||
|
||||
private LocationCameraController buildCamera(MoveGestureDetector moveGestureDetector) {
|
||||
@@ -325,17 +373,28 @@ public class LocationCameraControllerTest {
|
||||
when(mapboxMap.getUiSettings()).thenReturn(mock(UiSettings.class));
|
||||
OnCameraTrackingChangedListener onCameraTrackingChangedListener = mock(OnCameraTrackingChangedListener.class);
|
||||
OnCameraMoveInvalidateListener onCameraMoveInvalidateListener = mock(OnCameraMoveInvalidateListener.class);
|
||||
AndroidGesturesManager androidGesturesManager = mock(AndroidGesturesManager.class);
|
||||
AndroidGesturesManager initialGesturesManager = mock(AndroidGesturesManager.class);
|
||||
AndroidGesturesManager internalGesturesManager = mock(AndroidGesturesManager.class);
|
||||
return new LocationCameraController(mapboxMap, moveGestureDetector,
|
||||
onCameraTrackingChangedListener, onCameraMoveInvalidateListener, androidGesturesManager);
|
||||
onCameraTrackingChangedListener, onCameraMoveInvalidateListener, initialGesturesManager, internalGesturesManager);
|
||||
}
|
||||
|
||||
private LocationCameraController buildCamera(MapboxMap mapboxMap) {
|
||||
MoveGestureDetector moveGestureDetector = mock(MoveGestureDetector.class);
|
||||
OnCameraTrackingChangedListener onCameraTrackingChangedListener = mock(OnCameraTrackingChangedListener.class);
|
||||
OnCameraMoveInvalidateListener onCameraMoveInvalidateListener = mock(OnCameraMoveInvalidateListener.class);
|
||||
AndroidGesturesManager androidGesturesManager = mock(AndroidGesturesManager.class);
|
||||
AndroidGesturesManager initialGesturesManager = mock(AndroidGesturesManager.class);
|
||||
AndroidGesturesManager internalGesturesManager = mock(AndroidGesturesManager.class);
|
||||
return new LocationCameraController(mapboxMap, moveGestureDetector,
|
||||
onCameraTrackingChangedListener, onCameraMoveInvalidateListener, androidGesturesManager);
|
||||
onCameraTrackingChangedListener, onCameraMoveInvalidateListener, initialGesturesManager, internalGesturesManager);
|
||||
}
|
||||
|
||||
private LocationCameraController buildCamera(MapboxMap mapboxMap, AndroidGesturesManager initialGesturesManager,
|
||||
AndroidGesturesManager internalGesturesManager) {
|
||||
MoveGestureDetector moveGestureDetector = mock(MoveGestureDetector.class);
|
||||
OnCameraTrackingChangedListener onCameraTrackingChangedListener = mock(OnCameraTrackingChangedListener.class);
|
||||
OnCameraMoveInvalidateListener onCameraMoveInvalidateListener = mock(OnCameraMoveInvalidateListener.class);
|
||||
return new LocationCameraController(mapboxMap, moveGestureDetector,
|
||||
onCameraTrackingChangedListener, onCameraMoveInvalidateListener, initialGesturesManager, internalGesturesManager);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,6 +210,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.staleStateTimeout(200)
|
||||
.enableStaleState(false)
|
||||
@@ -238,6 +239,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.foregroundName("custom-foreground-bitmap")
|
||||
.backgroundName("custom-background-bitmap")
|
||||
@@ -278,6 +280,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.foregroundName("custom-foreground-bitmap")
|
||||
.gpsName("custom-gps-bitmap")
|
||||
@@ -307,6 +310,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.foregroundName("custom-foreground-bitmap")
|
||||
.gpsName("custom-gps-bitmap")
|
||||
@@ -338,6 +342,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
uiController: UiController, context: Context) {
|
||||
|
||||
component.activateLocationComponent(context,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.gpsName("custom-gps-bitmap")
|
||||
.build())
|
||||
@@ -367,6 +372,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.staleStateTimeout(200)
|
||||
.build())
|
||||
@@ -421,6 +427,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.accuracyColor(color)
|
||||
.build())
|
||||
|
||||
@@ -36,5 +36,6 @@
|
||||
"TextureViewTransparentBackgroundActivity",
|
||||
"SimpleMapActivity",
|
||||
"RenderTestActivity",
|
||||
"SymbolLayerActivity"
|
||||
"SymbolLayerActivity",
|
||||
"LocationFragmentActivity"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user