Skip to content

Commit 8273101

Browse files
author
Łukasz Paczos
committed
updated mapbox-java to v6.9.0-beta.1
Includes workaround for mockk/mockk#255.
1 parent c5a26f0 commit 8273101

File tree

8 files changed

+96
-74
lines changed

8 files changed

+96
-74
lines changed

gradle/dependencies.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ext {
1919

2020
version = [
2121
mapboxMapSdk : '10.9.0-rc.1',
22-
mapboxSdkServices : '6.8.0',
22+
mapboxSdkServices : '6.9.0-beta.1',
2323
mapboxCore : '5.0.2',
2424
mapboxNavigator : "${mapboxNavigatorVersion}",
2525
mapboxCommonNative : '23.1.0-rc.2',

libnavigation-base/src/test/java/com/mapbox/navigation/base/internal/route/NavigationRouteExTest.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,14 @@ class NavigationRouteExTest {
504504
),
505505
5
506506
)
507-
val validStep = mockk<LegStep>(relaxed = true) {
508-
every { geometry() } returns twoPointGeometry
509-
}
507+
val validStep = LegStep.builder()
508+
.geometry(twoPointGeometry)
509+
.distance(1.0)
510+
.duration(2.0)
511+
.weight(3.0)
512+
.mode("mode")
513+
.maneuver(mockk())
514+
.build()
510515
return NavigationRoute(
511516
DirectionsResponse.builder()
512517
.routes(

libnavigation-base/src/test/java/com/mapbox/navigation/base/route/NavigationRouteTest.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import com.mapbox.navigation.base.internal.NativeRouteParserWrapper
1010
import com.mapbox.navigation.base.internal.route.RouteCompatibilityCache
1111
import com.mapbox.navigation.base.internal.utils.DirectionsRouteMissingConditionsCheck
1212
import com.mapbox.navigation.testing.FileUtils
13+
import com.mapbox.navigation.testing.MapboxJavaObjectsFactory
1314
import com.mapbox.navigator.RouteInterface
1415
import io.mockk.every
1516
import io.mockk.mockk
1617
import io.mockk.mockkObject
1718
import io.mockk.slot
19+
import io.mockk.spyk
1820
import io.mockk.unmockkObject
1921
import io.mockk.verify
2022
import org.json.JSONObject
@@ -96,7 +98,7 @@ class NavigationRouteTest {
9698

9799
@Test
98100
fun `toNavigationRoute - waypoints back filled from route options`() {
99-
val directionsRoute = mockk<DirectionsRoute> {
101+
val directionsRoute = spyk(MapboxJavaObjectsFactory.directionsRoute()) {
100102
every { requestUuid() } returns "asdf"
101103
every { routeIndex() } returns "0"
102104
every { routeOptions() } returns RouteOptions.builder()
@@ -109,7 +111,6 @@ class NavigationRouteTest {
109111
)
110112
.build()
111113
every { legs() } returns null
112-
every { toBuilder() } returns mockk(relaxed = true)
113114
}
114115

115116
val navigationRoute = directionsRoute.toNavigationRoute()
@@ -133,7 +134,7 @@ class NavigationRouteTest {
133134

134135
@Test
135136
fun `toNavigationRoute - uuid from route used`() {
136-
val directionsRoute = mockk<DirectionsRoute> {
137+
val directionsRoute = spyk(MapboxJavaObjectsFactory.directionsRoute()) {
137138
every { requestUuid() } returns "asdf"
138139
every { routeIndex() } returns "0"
139140
every { routeOptions() } returns RouteOptions.builder()
@@ -146,7 +147,6 @@ class NavigationRouteTest {
146147
)
147148
.build()
148149
every { legs() } returns null
149-
every { toBuilder() } returns mockk(relaxed = true)
150150
}
151151

152152
val navigationRoute = directionsRoute.toNavigationRoute(RouterOrigin.Offboard)
@@ -165,7 +165,7 @@ class NavigationRouteTest {
165165

166166
@Test
167167
fun `toNavigationRoute - waypoints back filled from route options ignoring silent`() {
168-
val directionsRoute = mockk<DirectionsRoute> {
168+
val directionsRoute = spyk(MapboxJavaObjectsFactory.directionsRoute()) {
169169
every { requestUuid() } returns "asdf"
170170
every { routeIndex() } returns "0"
171171
every { routeOptions() } returns RouteOptions.builder()
@@ -181,7 +181,6 @@ class NavigationRouteTest {
181181
.waypointIndicesList(listOf(0, 2, 3))
182182
.build()
183183
every { legs() } returns null
184-
every { toBuilder() } returns mockk(relaxed = true)
185184
}
186185

187186
val navigationRoute = directionsRoute.toNavigationRoute()

libnavigation-core/src/test/java/com/mapbox/navigation/core/directions/session/MapboxDirectionsSessionTest.kt

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.mapbox.navigation.base.route.RouterFailure
1313
import com.mapbox.navigation.base.route.RouterOrigin
1414
import com.mapbox.navigation.core.BasicSetRoutesInfo
1515
import com.mapbox.navigation.core.NavigationComponentProvider
16+
import com.mapbox.navigation.testing.MapboxJavaObjectsFactory
1617
import io.mockk.clearMocks
1718
import io.mockk.every
1819
import io.mockk.just
@@ -33,7 +34,7 @@ class MapboxDirectionsSessionTest {
3334
private lateinit var session: MapboxDirectionsSession
3435

3536
private val router: NavigationRouterV2 = mockk(relaxUnitFun = true)
36-
private val routeOptions: RouteOptions = mockk(relaxUnitFun = true)
37+
private val routeOptions: RouteOptions = MapboxJavaObjectsFactory.routeOptions()
3738
private val routerCallback: NavigationRouterCallback = mockk(relaxUnitFun = true)
3839
private val routesRefreshRequestCallback: NavigationRouterRefreshCallback =
3940
mockk(relaxUnitFun = true)
@@ -50,19 +51,7 @@ class MapboxDirectionsSessionTest {
5051

5152
@Before
5253
fun setUp() {
53-
val routeOptionsBuilder: RouteOptions.Builder = mockk(relaxUnitFun = true)
54-
every { routeOptionsBuilder.waypointIndices(any()) } returns routeOptionsBuilder
55-
every { routeOptionsBuilder.waypointNames(any()) } returns routeOptionsBuilder
56-
every { routeOptionsBuilder.waypointTargets(any()) } returns routeOptionsBuilder
57-
every { routeOptionsBuilder.build() } returns routeOptions
58-
every { routeOptions.toBuilder() } returns routeOptionsBuilder
59-
every { routeOptions.waypointIndices() } returns ""
60-
every { routeOptions.waypointNames() } returns ""
61-
every { routeOptions.waypointTargets() } returns ""
62-
val routeBuilder: DirectionsRoute.Builder = mockk(relaxUnitFun = true)
63-
every { route.directionsRoute.toBuilder() } returns routeBuilder
64-
every { routeBuilder.routeOptions(any()) } returns routeBuilder
65-
every { routeBuilder.build() } returns mockk()
54+
every { route.directionsRoute } returns MapboxJavaObjectsFactory.directionsRoute()
6655

6756
val routeListener = slot<NavigationRouterCallback>()
6857
val refreshListener = slot<NavigationRouterRefreshCallback>()

libnavigation-core/src/test/java/com/mapbox/navigation/core/reroute/MapboxRerouteControllerTest.kt

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.mapbox.navigation.core.reroute
22

33
import com.mapbox.api.directions.v5.DirectionsCriteria
44
import com.mapbox.api.directions.v5.models.RouteOptions
5+
import com.mapbox.geojson.Point
56
import com.mapbox.navigation.base.internal.route.routerOrigin
67
import com.mapbox.navigation.base.options.RerouteOptions
78
import com.mapbox.navigation.base.route.NavigationRoute
@@ -14,8 +15,10 @@ import com.mapbox.navigation.core.trip.session.LocationMatcherResult
1415
import com.mapbox.navigation.core.trip.session.TripSession
1516
import com.mapbox.navigation.testing.LoggingFrontendTestRule
1617
import com.mapbox.navigation.testing.MainCoroutineRule
18+
import com.mapbox.navigation.testing.MapboxJavaObjectsFactory
1719
import com.mapbox.navigation.utils.internal.ThreadController
1820
import io.mockk.MockKAnnotations
21+
import io.mockk.clearMocks
1922
import io.mockk.every
2023
import io.mockk.impl.annotations.MockK
2124
import io.mockk.just
@@ -55,11 +58,12 @@ class MapboxRerouteControllerTest {
5558
@MockK
5659
private lateinit var rerouteOptions: RerouteOptions
5760

58-
@MockK
59-
private lateinit var successFromResult: RouteOptionsUpdater.RouteOptionsResult.Success
61+
private val routeOptionsFromSuccessResult = MapboxJavaObjectsFactory.routeOptions(
62+
coordinates = listOf(Point.fromLngLat(53.0, 27.0), Point.fromLngLat(76.5, 34.8))
63+
)
6064

61-
@MockK
62-
private lateinit var routeOptionsFromSuccessResult: RouteOptions
65+
private val successFromResult =
66+
RouteOptionsUpdater.RouteOptionsResult.Success(routeOptionsFromSuccessResult)
6367

6468
@MockK
6569
private lateinit var errorFromResult: RouteOptionsUpdater.RouteOptionsResult.Error
@@ -79,6 +83,9 @@ class MapboxRerouteControllerTest {
7983
@Before
8084
fun setup() {
8185
MockKAnnotations.init(this, relaxUnitFun = true, relaxed = true)
86+
every {
87+
directionsSession.getPrimaryRouteOptions()
88+
} returns MapboxJavaObjectsFactory.routeOptions()
8289
rerouteController = spyk(
8390
MapboxRerouteController(
8491
directionsSession,
@@ -88,7 +95,6 @@ class MapboxRerouteControllerTest {
8895
ThreadController()
8996
)
9097
)
91-
every { successFromResult.routeOptions } returns routeOptionsFromSuccessResult
9298
}
9399

94100
@After
@@ -142,9 +148,9 @@ class MapboxRerouteControllerTest {
142148
addRerouteStateObserver()
143149
val routes = listOf(
144150
mockk<NavigationRoute> {
145-
every { directionsRoute } returns mockk {
146-
every { routeOptions() } returns null
147-
}
151+
every {
152+
directionsRoute
153+
} returns MapboxJavaObjectsFactory.directionsRoute(routeOptions = null)
148154
}
149155
)
150156
val origin = mockk<RouterOrigin>()
@@ -242,7 +248,7 @@ class MapboxRerouteControllerTest {
242248
} returns 1L
243249

244250
rerouteController.reroute(routeCallback)
245-
routeRequestCallback.captured.onFailure(mockk(), mockk())
251+
routeRequestCallback.captured.onFailure(mockk(), MapboxJavaObjectsFactory.routeOptions())
246252

247253
verify(exactly = 1) {
248254
primaryRerouteObserver.onRerouteStateChanged(RerouteState.FetchingRoute)
@@ -274,7 +280,7 @@ class MapboxRerouteControllerTest {
274280
} returns 1L
275281

276282
rerouteController.reroute(routeCallback)
277-
routeRequestCallback.captured.onCanceled(mockk(), mockk())
283+
routeRequestCallback.captured.onCanceled(MapboxJavaObjectsFactory.routeOptions(), mockk())
278284

279285
verify(exactly = 1) {
280286
primaryRerouteObserver.onRerouteStateChanged(RerouteState.FetchingRoute)
@@ -343,7 +349,10 @@ class MapboxRerouteControllerTest {
343349
every {
344350
directionsSession.cancelRouteRequest(1L)
345351
} answers {
346-
routeRequestCallback.captured.onCanceled(mockk(), mockk())
352+
routeRequestCallback.captured.onCanceled(
353+
MapboxJavaObjectsFactory.routeOptions(),
354+
mockk()
355+
)
347356
}
348357

349358
rerouteController.reroute(routeCallback)
@@ -408,14 +417,10 @@ class MapboxRerouteControllerTest {
408417
Triple(5000f, 1, 1000.0),
409418
Triple(200f, 0, null),
410419
).forEach { (speed, secondsRadius, expectedMetersRadius) ->
411-
val mockRo = mockk<RouteOptions> {
412-
every { profile() } returns DirectionsCriteria.PROFILE_DRIVING_TRAFFIC
413-
}
414-
val mockRoBuilder = mockk<RouteOptions.Builder>()
415-
every { directionsSession.getPrimaryRouteOptions() } returns mockRo
416-
every { mockRo.toBuilder() } returns mockRoBuilder
417-
every { mockRoBuilder.avoidManeuverRadius(any()) } returns mockRoBuilder
418-
every { mockRoBuilder.build() } returns mockRo
420+
val mockRoute = MapboxJavaObjectsFactory.routeOptions(
421+
profile = DirectionsCriteria.PROFILE_DRIVING_TRAFFIC
422+
)
423+
every { directionsSession.getPrimaryRouteOptions() } returns mockRoute
419424
mockRouteOptionsResult(successFromResult)
420425
addRerouteStateObserver()
421426
every { rerouteOptions.avoidManeuverSeconds } returns secondsRadius
@@ -429,10 +434,15 @@ class MapboxRerouteControllerTest {
429434
}
430435
}
431436

437+
clearMocks(routeOptionsUpdater, answers = false)
432438
rerouteController.reroute(routeCallback)
433439

434440
verify(exactly = 1) {
435-
mockRoBuilder.avoidManeuverRadius(expectedMetersRadius)
441+
routeOptionsUpdater.update(
442+
mockRoute.toBuilder().avoidManeuverRadius(expectedMetersRadius).build(),
443+
any(),
444+
any()
445+
)
436446
}
437447
}
438448

@@ -455,14 +465,8 @@ class MapboxRerouteControllerTest {
455465
Pair(DirectionsCriteria.PROFILE_DRIVING_TRAFFIC, true),
456466
Pair(DirectionsCriteria.PROFILE_WALKING, false),
457467
).forEach { (profile, result) ->
458-
val mockRo = mockk<RouteOptions> {
459-
every { profile() } returns profile
460-
}
461-
val mockRoBuilder = mockk<RouteOptions.Builder>()
468+
val mockRo = MapboxJavaObjectsFactory.routeOptions(profile = profile)
462469
every { directionsSession.getPrimaryRouteOptions() } returns mockRo
463-
every { mockRo.toBuilder() } returns mockRoBuilder
464-
every { mockRoBuilder.avoidManeuverRadius(any()) } returns mockRoBuilder
465-
every { mockRoBuilder.build() } returns mockRo
466470
mockRouteOptionsResult(successFromResult)
467471
addRerouteStateObserver()
468472
every { rerouteOptions.avoidManeuverSeconds } returns 1
@@ -476,16 +480,15 @@ class MapboxRerouteControllerTest {
476480
}
477481
}
478482

483+
clearMocks(routeOptionsUpdater, answers = false)
479484
rerouteController.reroute(routeCallback)
480485

481-
verify(
482-
exactly = if (result) {
483-
1
484-
} else {
485-
0
486-
}
487-
) {
488-
mockRoBuilder.avoidManeuverRadius(any())
486+
verify(exactly = 1) {
487+
routeOptionsUpdater.update(
488+
mockRo.toBuilder().avoidManeuverRadius(if (result) 200.0 else null).build(),
489+
any(),
490+
any()
491+
)
489492
}
490493
}
491494

@@ -510,7 +513,7 @@ class MapboxRerouteControllerTest {
510513
@Test
511514
fun uses_route_options_delegate() {
512515
mockRouteOptionsResult(successFromResult)
513-
val mockNewRouteOptions = mockk<RouteOptions>()
516+
val mockNewRouteOptions = MapboxJavaObjectsFactory.routeOptions()
514517
val mockRerouteOptionsDelegateManger = mockk<RerouteOptionsAdapter> {
515518
every { onRouteOptions(any()) } returns mockNewRouteOptions
516519
}

libnavui-androidauto/src/test/java/com/mapbox/androidauto/car/preview/CarRoutePreviewRequestTest.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.mapbox.navigation.base.route.NavigationRoute
99
import com.mapbox.navigation.base.route.NavigationRouterCallback
1010
import com.mapbox.navigation.core.MapboxNavigation
1111
import com.mapbox.navigation.testing.LoggingFrontendTestRule
12+
import com.mapbox.navigation.testing.MapboxJavaObjectsFactory
1213
import io.mockk.CapturingSlot
1314
import io.mockk.Runs
1415
import io.mockk.every
@@ -32,9 +33,7 @@ class CarRoutePreviewRequestTest {
3233
private val routeOptionsSlot = CapturingSlot<RouteOptions>()
3334
private val routerCallbackSlot = CapturingSlot<NavigationRouterCallback>()
3435
private val options: MapboxCarOptions = mockk {
35-
every { routeOptionsInterceptor } returns mockk {
36-
every { intercept(any()) } answers { firstArg() }
37-
}
36+
every { routeOptionsInterceptor } returns CarRouteOptionsInterceptor { it }
3837
}
3938

4039
private val locationProvider = mockk<CarLocationProvider>()
@@ -221,11 +220,12 @@ class CarRoutePreviewRequestTest {
221220

222221
@Test
223222
fun `custom route options provided by interceptor are used for route request`() {
224-
val customRouteOptions = mockk<RouteOptions>()
225-
val customRouteOptionsBuilder = mockk<RouteOptions.Builder> {
226-
every { build() } returns customRouteOptions
227-
}
228-
every { options.routeOptionsInterceptor.intercept(any()) } returns customRouteOptionsBuilder
223+
val customRouteOptions = MapboxJavaObjectsFactory.routeOptions(
224+
coordinates = listOf(Point.fromLngLat(23.4, 12.56), Point.fromLngLat(98.7, 45.4))
225+
)
226+
every {
227+
options.routeOptionsInterceptor
228+
} returns CarRouteOptionsInterceptor { customRouteOptions.toBuilder() }
229229
every { locationProvider.lastLocation() } returns mockk {
230230
every { longitude } returns -121.4670161
231231
every { latitude } returns 38.5630514

libnavui-app/src/test/java/com/mapbox/navigation/ui/app/internal/routefetch/RouteOptionsProviderTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.mapbox.api.directions.v5.models.RouteOptions
55
import com.mapbox.geojson.Point
66
import com.mapbox.navigation.base.internal.extensions.inferDeviceLocale
77
import com.mapbox.navigation.core.MapboxNavigation
8+
import com.mapbox.navigation.testing.MapboxJavaObjectsFactory
89
import io.mockk.every
910
import io.mockk.mockk
1011
import io.mockk.mockkStatic
@@ -30,11 +31,6 @@ class RouteOptionsProviderTest {
3031
}
3132
private val origin = Point.fromLngLat(1.0, 2.0)
3233
private val destination = Point.fromLngLat(3.0, 4.0)
33-
private val routeOptions = mockk<RouteOptions>()
34-
private val optionsBuilder = mockk<RouteOptions.Builder> {
35-
every { build() } returns routeOptions
36-
}
37-
private val interceptor: (RouteOptions.Builder) -> RouteOptions.Builder = { optionsBuilder }
3834

3935
@Before
4036
fun `set up`() {
@@ -57,11 +53,15 @@ class RouteOptionsProviderTest {
5753

5854
@Test
5955
fun `provider returns options from interceptor if set`() {
56+
val resultBuilder = MapboxJavaObjectsFactory.routeOptions().toBuilder()
57+
val result = resultBuilder.build()
58+
val interceptor: (RouteOptions.Builder) -> RouteOptions.Builder = { resultBuilder }
59+
6060
routeOptionsProvider.setInterceptor(interceptor)
6161

6262
val options = routeOptionsProvider.getOptions(mapboxNavigation, origin, destination)
6363

64-
assertEquals(options, routeOptions)
64+
assertEquals(options, result)
6565
}
6666

6767
private companion object {

0 commit comments

Comments
 (0)