summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.kt
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.kt')
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.kt217
1 files changed, 135 insertions, 82 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.kt
index c2d95d0e80..ab70f188c3 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.kt
@@ -27,6 +27,7 @@ import com.mapbox.mapboxsdk.testapp.R
import com.mapbox.mapboxsdk.testapp.activity.EspressoTest
import com.mapbox.mapboxsdk.testapp.utils.TestingAsyncUtils
import com.mapbox.mapboxsdk.utils.BitmapUtils
+import kotlin.math.abs
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.CoreMatchers.notNullValue
import org.hamcrest.Matchers.equalTo
@@ -37,7 +38,6 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
-import kotlin.math.abs
@RunWith(AndroidJUnit4::class)
class LocationLayerControllerTest : EspressoTest() {
@@ -77,10 +77,12 @@ class LocationLayerControllerTest : EspressoTest() {
uiController: UiController,
context: Context
) {
- component.activateLocationComponent(LocationComponentActivationOptions
- .builder(context, style)
- .useDefaultLocationEngine(false)
- .build())
+ component.activateLocationComponent(
+ LocationComponentActivationOptions
+ .builder(context, style)
+ .useDefaultLocationEngine(false)
+ .build()
+ )
component.isLocationComponentEnabled = true
component.renderMode = RenderMode.NORMAL
TestingAsyncUtils.waitForLayer(uiController, mapView)
@@ -105,10 +107,12 @@ class LocationLayerControllerTest : EspressoTest() {
uiController: UiController,
context: Context
) {
- component.activateLocationComponent(LocationComponentActivationOptions
- .builder(context, style)
- .useDefaultLocationEngine(false)
- .build())
+ component.activateLocationComponent(
+ LocationComponentActivationOptions
+ .builder(context, style)
+ .useDefaultLocationEngine(false)
+ .build()
+ )
component.isLocationComponentEnabled = true
component.renderMode = RenderMode.NORMAL
component.forceLocationUpdate(location)
@@ -134,10 +138,12 @@ class LocationLayerControllerTest : EspressoTest() {
uiController: UiController,
context: Context
) {
- component.activateLocationComponent(LocationComponentActivationOptions
- .builder(context, style)
- .useDefaultLocationEngine(false)
- .build())
+ component.activateLocationComponent(
+ LocationComponentActivationOptions
+ .builder(context, style)
+ .useDefaultLocationEngine(false)
+ .build()
+ )
component.isLocationComponentEnabled = true
component.renderMode = RenderMode.COMPASS
component.forceLocationUpdate(location)
@@ -163,10 +169,12 @@ class LocationLayerControllerTest : EspressoTest() {
uiController: UiController,
context: Context
) {
- component.activateLocationComponent(LocationComponentActivationOptions
- .builder(context, style)
- .useDefaultLocationEngine(false)
- .build())
+ component.activateLocationComponent(
+ LocationComponentActivationOptions
+ .builder(context, style)
+ .useDefaultLocationEngine(false)
+ .build()
+ )
component.isLocationComponentEnabled = true
component.renderMode = RenderMode.GPS
component.forceLocationUpdate(location)
@@ -192,10 +200,12 @@ class LocationLayerControllerTest : EspressoTest() {
uiController: UiController,
context: Context
) {
- component.activateLocationComponent(LocationComponentActivationOptions
- .builder(context, style)
- .useDefaultLocationEngine(false)
- .build())
+ component.activateLocationComponent(
+ LocationComponentActivationOptions
+ .builder(context, style)
+ .useDefaultLocationEngine(false)
+ .build()
+ )
component.isLocationComponentEnabled = true
component.forceLocationUpdate(location)
component.isLocationComponentEnabled = false
@@ -222,10 +232,12 @@ class LocationLayerControllerTest : EspressoTest() {
uiController: UiController,
context: Context
) {
- component.activateLocationComponent(LocationComponentActivationOptions
- .builder(context, style)
- .useDefaultLocationEngine(false)
- .build())
+ component.activateLocationComponent(
+ LocationComponentActivationOptions
+ .builder(context, style)
+ .useDefaultLocationEngine(false)
+ .build()
+ )
component.isLocationComponentEnabled = true
component.renderMode = RenderMode.NORMAL
component.forceLocationUpdate(location)
@@ -253,10 +265,12 @@ class LocationLayerControllerTest : EspressoTest() {
uiController: UiController,
context: Context
) {
- component.activateLocationComponent(LocationComponentActivationOptions
- .builder(context, style)
- .useDefaultLocationEngine(false)
- .build())
+ component.activateLocationComponent(
+ LocationComponentActivationOptions
+ .builder(context, style)
+ .useDefaultLocationEngine(false)
+ .build()
+ )
component.isLocationComponentEnabled = true
component.renderMode = RenderMode.NORMAL
component.forceLocationUpdate(location)
@@ -290,22 +304,30 @@ class LocationLayerControllerTest : EspressoTest() {
uiController: UiController,
context: Context
) {
- component.activateLocationComponent(LocationComponentActivationOptions
- .builder(context, style)
- .useDefaultLocationEngine(false)
- .build())
+ component.activateLocationComponent(
+ LocationComponentActivationOptions
+ .builder(context, style)
+ .useDefaultLocationEngine(false)
+ .build()
+ )
component.isLocationComponentEnabled = true
component.applyStyle(LocationComponentOptions.builder(context).staleStateTimeout(100).build())
component.forceLocationUpdate(location)
TestingAsyncUtils.waitForLayer(uiController, mapView)
uiController.loopMainThreadForAtLeast(150)
- assertThat(mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getBooleanProperty(PROPERTY_LOCATION_STALE), `is`(true))
+ assertThat(
+ mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getBooleanProperty(PROPERTY_LOCATION_STALE),
+ `is`(true)
+ )
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
TestingAsyncUtils.waitForLayer(uiController, mapView)
- assertThat(mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getBooleanProperty(PROPERTY_LOCATION_STALE), `is`(true))
+ assertThat(
+ mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getBooleanProperty(PROPERTY_LOCATION_STALE),
+ `is`(true)
+ )
}
}
executeComponentTest(componentAction)
@@ -321,10 +343,12 @@ class LocationLayerControllerTest : EspressoTest() {
uiController: UiController,
context: Context
) {
- component.activateLocationComponent(LocationComponentActivationOptions
- .builder(context, style)
- .useDefaultLocationEngine(false)
- .build())
+ component.activateLocationComponent(
+ LocationComponentActivationOptions
+ .builder(context, style)
+ .useDefaultLocationEngine(false)
+ .build()
+ )
component.isLocationComponentEnabled = true
component.forceLocationUpdate(location)
TestingAsyncUtils.waitForLayer(uiController, mapView)
@@ -333,9 +357,9 @@ class LocationLayerControllerTest : EspressoTest() {
assertThat(mapboxMap.queryRenderedFeatures(location, FOREGROUND_LAYER).isEmpty(), `is`(true))
val options = component.locationComponentOptions
- .toBuilder()
- .layerBelow("road-label")
- .build()
+ .toBuilder()
+ .layerBelow("road-label")
+ .build()
component.applyStyle(options)
TestingAsyncUtils.waitForLayer(uiController, mapView)
@@ -355,10 +379,12 @@ class LocationLayerControllerTest : EspressoTest() {
uiController: UiController,
context: Context
) {
- component.activateLocationComponent(LocationComponentActivationOptions
- .builder(context, style)
- .useDefaultLocationEngine(false)
- .build())
+ component.activateLocationComponent(
+ LocationComponentActivationOptions
+ .builder(context, style)
+ .useDefaultLocationEngine(false)
+ .build()
+ )
component.isLocationComponentEnabled = true
component.applyStyle(LocationComponentOptions.builder(context).staleStateTimeout(1).build())
styleChangeIdlingResource.waitForStyle(mapboxMap, MAPBOX_HEAVY_STYLE)
@@ -386,10 +412,12 @@ class LocationLayerControllerTest : EspressoTest() {
styleChangeIdlingResource.waitForStyle(mapboxMap, MAPBOX_HEAVY_STYLE)
uiController.loopMainThreadForAtLeast(100)
var show = true
- component.activateLocationComponent(LocationComponentActivationOptions
- .builder(context, mapboxMap.style!!)
- .useDefaultLocationEngine(false)
- .build())
+ component.activateLocationComponent(
+ LocationComponentActivationOptions
+ .builder(context, mapboxMap.style!!)
+ .useDefaultLocationEngine(false)
+ .build()
+ )
pushSourceUpdates(styleChangeIdlingResource) {
component.isLocationComponentEnabled = show
show = !show
@@ -414,19 +442,23 @@ class LocationLayerControllerTest : EspressoTest() {
uiController: UiController,
context: Context
) {
- component.activateLocationComponent(LocationComponentActivationOptions
- .builder(context, style)
- .useDefaultLocationEngine(false)
- .build())
+ component.activateLocationComponent(
+ LocationComponentActivationOptions
+ .builder(context, style)
+ .useDefaultLocationEngine(false)
+ .build()
+ )
component.isLocationComponentEnabled = true
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(location), 16.0))
component.forceLocationUpdate(location)
TestingAsyncUtils.waitForLayer(uiController, mapView)
uiController.loopMainThreadForAtLeast(ACCURACY_RADIUS_ANIMATION_DURATION)
- assertEquals(Utils.calculateZoomLevelRadius(mapboxMap, location) /*meters projected to radius on zoom 16*/,
+ assertEquals(
+ Utils.calculateZoomLevelRadius(mapboxMap, location) /*meters projected to radius on zoom 16*/,
mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0]
- .getNumberProperty(PROPERTY_ACCURACY_RADIUS).toFloat(), 0.1f)
+ .getNumberProperty(PROPERTY_ACCURACY_RADIUS).toFloat(), 0.1f
+ )
}
}
executeComponentTest(componentAction)
@@ -442,10 +474,12 @@ class LocationLayerControllerTest : EspressoTest() {
uiController: UiController,
context: Context
) {
- component.activateLocationComponent(LocationComponentActivationOptions
- .builder(context, style)
- .useDefaultLocationEngine(false)
- .build())
+ component.activateLocationComponent(
+ LocationComponentActivationOptions
+ .builder(context, style)
+ .useDefaultLocationEngine(false)
+ .build()
+ )
component.isLocationComponentEnabled = true
component.forceLocationUpdate(location)
@@ -455,15 +489,23 @@ class LocationLayerControllerTest : EspressoTest() {
uiController.loopMainThreadForAtLeast(300)
TestingAsyncUtils.waitForLayer(uiController, mapView)
- assertThat(Math.abs(zoom - mapboxMap.cameraPosition.zoom) < 0.1 &&
- Math.abs(target.latitude - mapboxMap.cameraPosition.target.latitude) < 0.1 &&
- Math.abs(target.longitude - mapboxMap.cameraPosition.target.longitude) < 0.1,
- `is`(true))
-
- val expectedRadius = Utils.calculateZoomLevelRadius(mapboxMap, location) /*meters projected to radius on zoom 16*/
assertThat(
- Math.abs(expectedRadius - mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getNumberProperty(PROPERTY_ACCURACY_RADIUS).toFloat()) < 0.1,
- `is`(true))
+ Math.abs(zoom - mapboxMap.cameraPosition.zoom) < 0.1 &&
+ Math.abs(target.latitude - mapboxMap.cameraPosition.target.latitude) < 0.1 &&
+ Math.abs(target.longitude - mapboxMap.cameraPosition.target.longitude) < 0.1,
+ `is`(true)
+ )
+
+ val expectedRadius =
+ Utils.calculateZoomLevelRadius(mapboxMap, location) /*meters projected to radius on zoom 16*/
+ assertThat(
+ Math.abs(
+ expectedRadius - mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getNumberProperty(
+ PROPERTY_ACCURACY_RADIUS
+ ).toFloat()
+ ) < 0.1,
+ `is`(true)
+ )
}
}
executeComponentTest(componentAction)
@@ -479,10 +521,12 @@ class LocationLayerControllerTest : EspressoTest() {
uiController: UiController,
context: Context
) {
- component.activateLocationComponent(LocationComponentActivationOptions
- .builder(context, style)
- .useDefaultLocationEngine(false)
- .build())
+ component.activateLocationComponent(
+ LocationComponentActivationOptions
+ .builder(context, style)
+ .useDefaultLocationEngine(false)
+ .build()
+ )
component.isLocationComponentEnabled = true
component.forceLocationUpdate(location)
@@ -493,14 +537,21 @@ class LocationLayerControllerTest : EspressoTest() {
assertThat(
abs(zoom - mapboxMap.cameraPosition.zoom) < 0.1 &&
- abs(target.latitude - mapboxMap.cameraPosition.target.latitude) < 0.1 &&
- abs(target.longitude - mapboxMap.cameraPosition.target.longitude) < 0.1,
- `is`(true))
+ abs(target.latitude - mapboxMap.cameraPosition.target.latitude) < 0.1 &&
+ abs(target.longitude - mapboxMap.cameraPosition.target.longitude) < 0.1,
+ `is`(true)
+ )
- val expectedRadius = Utils.calculateZoomLevelRadius(mapboxMap, location) /*meters projected to radius on zoom 16*/
+ val expectedRadius =
+ Utils.calculateZoomLevelRadius(mapboxMap, location) /*meters projected to radius on zoom 16*/
assertThat(
- Math.abs(expectedRadius - mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getNumberProperty(PROPERTY_ACCURACY_RADIUS).toFloat()) < 0.1,
- `is`(true))
+ Math.abs(
+ expectedRadius - mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getNumberProperty(
+ PROPERTY_ACCURACY_RADIUS
+ ).toFloat()
+ ) < 0.1,
+ `is`(true)
+ )
}
}
executeComponentTest(componentAction)
@@ -516,10 +567,12 @@ class LocationLayerControllerTest : EspressoTest() {
uiController: UiController,
context: Context
) {
- component.activateLocationComponent(LocationComponentActivationOptions
- .builder(context, style)
- .useDefaultLocationEngine(false)
- .build())
+ component.activateLocationComponent(
+ LocationComponentActivationOptions
+ .builder(context, style)
+ .useDefaultLocationEngine(false)
+ .build()
+ )
component.isLocationComponentEnabled = true
component.forceLocationUpdate(location)
TestingAsyncUtils.waitForLayer(uiController, mapView)