Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] updated location tracking gestures management tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasPaczos committed Sep 7, 2018
1 parent 1caddb9 commit dfb64fb
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,41 @@ public void setCameraMode_gestureThresholdIsAdjusted() {
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);

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
Expand Down Expand Up @@ -180,7 +199,9 @@ public void onNewLatLngValue_focalPointIsAdjusted() {
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);

Expand Down Expand Up @@ -310,32 +331,70 @@ public void onNewZoomValue_cameraIsUpdated() {
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) {
MapboxMap mapboxMap = mock(MapboxMap.class);
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, 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, androidGesturesManager);
onCameraTrackingChangedListener, onCameraMoveInvalidateListener, initialGesturesManager, internalGesturesManager);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -338,6 +342,7 @@ class LocationComponentTest : BaseActivityTest() {
uiController: UiController, context: Context) {

component.activateLocationComponent(context,
null,
LocationComponentOptions.builder(context)
.gpsName("custom-gps-bitmap")
.build())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion platform/android/scripts/exclude-activity-gen.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@
"TextureViewTransparentBackgroundActivity",
"SimpleMapActivity",
"RenderTestActivity",
"SymbolLayerActivity"
"SymbolLayerActivity",
"LocationFragmentActivity"
]

0 comments on commit dfb64fb

Please sign in to comment.