@@ -2,6 +2,7 @@ package com.mapbox.navigation.core.reroute
2
2
3
3
import com.mapbox.api.directions.v5.DirectionsCriteria
4
4
import com.mapbox.api.directions.v5.models.RouteOptions
5
+ import com.mapbox.geojson.Point
5
6
import com.mapbox.navigation.base.internal.route.routerOrigin
6
7
import com.mapbox.navigation.base.options.RerouteOptions
7
8
import com.mapbox.navigation.base.route.NavigationRoute
@@ -14,8 +15,10 @@ import com.mapbox.navigation.core.trip.session.LocationMatcherResult
14
15
import com.mapbox.navigation.core.trip.session.TripSession
15
16
import com.mapbox.navigation.testing.LoggingFrontendTestRule
16
17
import com.mapbox.navigation.testing.MainCoroutineRule
18
+ import com.mapbox.navigation.testing.MapboxJavaObjectsFactory
17
19
import com.mapbox.navigation.utils.internal.ThreadController
18
20
import io.mockk.MockKAnnotations
21
+ import io.mockk.clearMocks
19
22
import io.mockk.every
20
23
import io.mockk.impl.annotations.MockK
21
24
import io.mockk.just
@@ -55,11 +58,12 @@ class MapboxRerouteControllerTest {
55
58
@MockK
56
59
private lateinit var rerouteOptions: RerouteOptions
57
60
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
+ )
60
64
61
- @MockK
62
- private lateinit var routeOptionsFromSuccessResult : RouteOptions
65
+ private val successFromResult =
66
+ RouteOptionsUpdater . RouteOptionsResult . Success (routeOptionsFromSuccessResult)
63
67
64
68
@MockK
65
69
private lateinit var errorFromResult: RouteOptionsUpdater .RouteOptionsResult .Error
@@ -79,6 +83,9 @@ class MapboxRerouteControllerTest {
79
83
@Before
80
84
fun setup () {
81
85
MockKAnnotations .init (this , relaxUnitFun = true , relaxed = true )
86
+ every {
87
+ directionsSession.getPrimaryRouteOptions()
88
+ } returns MapboxJavaObjectsFactory .routeOptions()
82
89
rerouteController = spyk(
83
90
MapboxRerouteController (
84
91
directionsSession,
@@ -88,7 +95,6 @@ class MapboxRerouteControllerTest {
88
95
ThreadController ()
89
96
)
90
97
)
91
- every { successFromResult.routeOptions } returns routeOptionsFromSuccessResult
92
98
}
93
99
94
100
@After
@@ -142,9 +148,9 @@ class MapboxRerouteControllerTest {
142
148
addRerouteStateObserver()
143
149
val routes = listOf (
144
150
mockk<NavigationRoute > {
145
- every { directionsRoute } returns mockk {
146
- every { routeOptions() } returns null
147
- }
151
+ every {
152
+ directionsRoute
153
+ } returns MapboxJavaObjectsFactory .directionsRoute(routeOptions = null )
148
154
}
149
155
)
150
156
val origin = mockk<RouterOrigin >()
@@ -242,7 +248,7 @@ class MapboxRerouteControllerTest {
242
248
} returns 1L
243
249
244
250
rerouteController.reroute(routeCallback)
245
- routeRequestCallback.captured.onFailure(mockk(), mockk ())
251
+ routeRequestCallback.captured.onFailure(mockk(), MapboxJavaObjectsFactory .routeOptions ())
246
252
247
253
verify(exactly = 1 ) {
248
254
primaryRerouteObserver.onRerouteStateChanged(RerouteState .FetchingRoute )
@@ -274,7 +280,7 @@ class MapboxRerouteControllerTest {
274
280
} returns 1L
275
281
276
282
rerouteController.reroute(routeCallback)
277
- routeRequestCallback.captured.onCanceled(mockk (), mockk())
283
+ routeRequestCallback.captured.onCanceled(MapboxJavaObjectsFactory .routeOptions (), mockk())
278
284
279
285
verify(exactly = 1 ) {
280
286
primaryRerouteObserver.onRerouteStateChanged(RerouteState .FetchingRoute )
@@ -343,7 +349,10 @@ class MapboxRerouteControllerTest {
343
349
every {
344
350
directionsSession.cancelRouteRequest(1L )
345
351
} answers {
346
- routeRequestCallback.captured.onCanceled(mockk(), mockk())
352
+ routeRequestCallback.captured.onCanceled(
353
+ MapboxJavaObjectsFactory .routeOptions(),
354
+ mockk()
355
+ )
347
356
}
348
357
349
358
rerouteController.reroute(routeCallback)
@@ -408,14 +417,10 @@ class MapboxRerouteControllerTest {
408
417
Triple (5000f , 1 , 1000.0 ),
409
418
Triple (200f , 0 , null ),
410
419
).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
419
424
mockRouteOptionsResult(successFromResult)
420
425
addRerouteStateObserver()
421
426
every { rerouteOptions.avoidManeuverSeconds } returns secondsRadius
@@ -429,10 +434,15 @@ class MapboxRerouteControllerTest {
429
434
}
430
435
}
431
436
437
+ clearMocks(routeOptionsUpdater, answers = false )
432
438
rerouteController.reroute(routeCallback)
433
439
434
440
verify(exactly = 1 ) {
435
- mockRoBuilder.avoidManeuverRadius(expectedMetersRadius)
441
+ routeOptionsUpdater.update(
442
+ mockRoute.toBuilder().avoidManeuverRadius(expectedMetersRadius).build(),
443
+ any(),
444
+ any()
445
+ )
436
446
}
437
447
}
438
448
@@ -455,14 +465,8 @@ class MapboxRerouteControllerTest {
455
465
Pair (DirectionsCriteria .PROFILE_DRIVING_TRAFFIC , true ),
456
466
Pair (DirectionsCriteria .PROFILE_WALKING , false ),
457
467
).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)
462
469
every { directionsSession.getPrimaryRouteOptions() } returns mockRo
463
- every { mockRo.toBuilder() } returns mockRoBuilder
464
- every { mockRoBuilder.avoidManeuverRadius(any()) } returns mockRoBuilder
465
- every { mockRoBuilder.build() } returns mockRo
466
470
mockRouteOptionsResult(successFromResult)
467
471
addRerouteStateObserver()
468
472
every { rerouteOptions.avoidManeuverSeconds } returns 1
@@ -476,16 +480,15 @@ class MapboxRerouteControllerTest {
476
480
}
477
481
}
478
482
483
+ clearMocks(routeOptionsUpdater, answers = false )
479
484
rerouteController.reroute(routeCallback)
480
485
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
+ )
489
492
}
490
493
}
491
494
@@ -510,7 +513,7 @@ class MapboxRerouteControllerTest {
510
513
@Test
511
514
fun uses_route_options_delegate () {
512
515
mockRouteOptionsResult(successFromResult)
513
- val mockNewRouteOptions = mockk< RouteOptions > ()
516
+ val mockNewRouteOptions = MapboxJavaObjectsFactory .routeOptions ()
514
517
val mockRerouteOptionsDelegateManger = mockk<RerouteOptionsAdapter > {
515
518
every { onRouteOptions(any()) } returns mockNewRouteOptions
516
519
}
0 commit comments