@@ -13,8 +13,6 @@ import com.mapbox.navigation.base.options.NavigationOptions
13
13
import com.mapbox.navigation.base.options.RoutingTilesOptions
14
14
import com.mapbox.navigation.base.route.NavigationRoute
15
15
import com.mapbox.navigation.base.route.RouteRefreshOptions
16
- import com.mapbox.navigation.core.EVDataObserver
17
- import com.mapbox.navigation.core.EVDataUpdater
18
16
import com.mapbox.navigation.core.MapboxNavigation
19
17
import com.mapbox.navigation.core.MapboxNavigationProvider
20
18
import com.mapbox.navigation.core.directions.session.RoutesExtra
@@ -47,7 +45,6 @@ import org.junit.Before
47
45
import org.junit.Rule
48
46
import org.junit.Test
49
47
import java.net.URI
50
- import java.util.concurrent.CopyOnWriteArraySet
51
48
import java.util.concurrent.TimeUnit
52
49
53
50
private const val KEY_ENGINE = " engine"
@@ -78,8 +75,6 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
78
75
Point .fromLngLat(11.5852259 , 48.1760993 ),
79
76
Point .fromLngLat(10.3406374 , 49.16479 )
80
77
)
81
- private lateinit var routeHandler: MockDirectionsRequestHandler
82
- private val evDataUpdater = TestEVDataUpdater ()
83
78
84
79
override fun setupMockLocation (): Location = mockLocationUpdatesRule.generateLocationUpdate {
85
80
latitude = twoCoordinates[0 ].latitude()
@@ -110,7 +105,7 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
110
105
.build()
111
106
)
112
107
mockWebServerRule.requestHandlers.clear()
113
- routeHandler = MockDirectionsRequestHandler (
108
+ val routeHandler = MockDirectionsRequestHandler (
114
109
" driving-traffic" ,
115
110
readRawFileText(activity, R .raw.ev_route_response_for_refresh),
116
111
twoCoordinates,
@@ -128,8 +123,7 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
128
123
)
129
124
val requestedRoutes = requestRoutes(twoCoordinates, electric = false )
130
125
131
- mapboxNavigation.setEVDataUpdater(evDataUpdater)
132
- evDataUpdater.updateData(
126
+ mapboxNavigation.onEVDataUpdated(
133
127
mapOf (
134
128
KEY_ENERGY_CONSUMPTION_CURVE to " 0,300;20,120;40,150" ,
135
129
KEY_EV_INITIAL_CHARGE to " 80" ,
@@ -183,14 +177,13 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
183
177
val initialCharge = " 80"
184
178
val preconditioningTime = " 10"
185
179
val auxiliaryConsumption = " 300"
186
- mapboxNavigation.setEVDataUpdater(evDataUpdater)
187
180
val evData = mapOf (
188
181
KEY_ENERGY_CONSUMPTION_CURVE to consumptionCurve,
189
182
KEY_EV_INITIAL_CHARGE to initialCharge,
190
183
KEY_EV_PRECONDITIONING_TIME to preconditioningTime,
191
184
KEY_AUXILIARY_CONSUMPTION to auxiliaryConsumption
192
185
)
193
- evDataUpdater.updateData (evData)
186
+ mapboxNavigation.onEVDataUpdated (evData)
194
187
195
188
mapboxNavigation.setNavigationRoutes(requestedRoutes)
196
189
mapboxNavigation.startTripSession()
@@ -231,8 +224,7 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
231
224
KEY_EV_PRECONDITIONING_TIME to preconditioningTime,
232
225
KEY_AUXILIARY_CONSUMPTION to auxiliaryConsumption
233
226
)
234
- mapboxNavigation.setEVDataUpdater(evDataUpdater)
235
- evDataUpdater.updateData(firstEvData)
227
+ mapboxNavigation.onEVDataUpdated(firstEvData)
236
228
waitUntilNewRefresh()
237
229
238
230
checkHasParameters(
@@ -241,7 +233,7 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
241
233
)
242
234
243
235
val newInitialCharge = " 60"
244
- evDataUpdater.updateData (
236
+ mapboxNavigation.onEVDataUpdated (
245
237
mapOf (
246
238
KEY_EV_INITIAL_CHARGE to newInitialCharge,
247
239
KEY_EV_PRECONDITIONING_TIME to null ,
@@ -261,34 +253,7 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
261
253
)
262
254
checkDoesNotHaveParameters(urlWithTwiceUpdatedData, setOf (KEY_EV_PRECONDITIONING_TIME ))
263
255
264
- mapboxNavigation.setEVDataUpdater(null )
265
- waitUntilNewRefresh()
266
-
267
- val removedUpdaterRefreshUrl = refreshHandler.handledRequests.last().requestUrl!!
268
- checkHasParameters(
269
- removedUpdaterRefreshUrl,
270
- mapOf (
271
- KEY_ENGINE to VALUE_ELECTRIC ,
272
- KEY_ENERGY_CONSUMPTION_CURVE to consumptionCurve,
273
- KEY_EV_INITIAL_CHARGE to newInitialCharge,
274
- KEY_AUXILIARY_CONSUMPTION to auxiliaryConsumption
275
- )
276
- )
277
- checkDoesNotHaveParameters(removedUpdaterRefreshUrl, setOf (KEY_EV_PRECONDITIONING_TIME ))
278
-
279
- val newUpdater = TestEVDataUpdater ()
280
- mapboxNavigation.setEVDataUpdater(newUpdater)
281
- val newUpdaterCharge = " 45"
282
- evDataUpdater.updateData(mapOf (KEY_EV_INITIAL_CHARGE to " 50" ))
283
- newUpdater.updateData(mapOf (KEY_EV_INITIAL_CHARGE to newUpdaterCharge))
284
- waitUntilNewRefresh()
285
-
286
- checkHasParameters(
287
- refreshHandler.handledRequests.last().requestUrl!! ,
288
- mapOf (KEY_EV_INITIAL_CHARGE to newUpdaterCharge)
289
- )
290
-
291
- newUpdater.updateData(emptyMap())
256
+ mapboxNavigation.onEVDataUpdated(emptyMap())
292
257
waitUntilNewRefresh()
293
258
294
259
val urlAfterEmptyUpdate = refreshHandler.handledRequests.last().requestUrl!!
@@ -297,7 +262,7 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
297
262
mapOf (
298
263
KEY_ENGINE to VALUE_ELECTRIC ,
299
264
KEY_ENERGY_CONSUMPTION_CURVE to consumptionCurve,
300
- KEY_EV_INITIAL_CHARGE to newUpdaterCharge ,
265
+ KEY_EV_INITIAL_CHARGE to newInitialCharge ,
301
266
KEY_AUXILIARY_CONSUMPTION to auxiliaryConsumption
302
267
)
303
268
)
@@ -311,14 +276,13 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
311
276
acceptedGeometryIndex = 0
312
277
)
313
278
val requestedRoutes = requestRoutes(twoCoordinates, electric = true )
314
- mapboxNavigation.setEVDataUpdater(evDataUpdater)
315
279
val evData = mapOf (
316
280
KEY_ENERGY_CONSUMPTION_CURVE to " 0,300;20,160;80,140;120,180" ,
317
281
KEY_EV_INITIAL_CHARGE to " 17000" ,
318
282
KEY_EV_PRECONDITIONING_TIME to " 10" ,
319
283
KEY_AUXILIARY_CONSUMPTION to " 300"
320
284
)
321
- evDataUpdater.updateData (evData)
285
+ mapboxNavigation.onEVDataUpdated (evData)
322
286
323
287
mapboxNavigation.setNavigationRoutesAndWaitForUpdate(requestedRoutes)
324
288
mapboxNavigation.startTripSession()
@@ -361,14 +325,13 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
361
325
geometryIndex
362
326
)
363
327
val requestedRoutes = requestRoutes(twoCoordinates, electric = true )
364
- mapboxNavigation.setEVDataUpdater(evDataUpdater)
365
328
val evData = mapOf (
366
329
KEY_ENERGY_CONSUMPTION_CURVE to " 0,300;20,160;80,140;120,180" ,
367
330
KEY_EV_INITIAL_CHARGE to " 17000" ,
368
331
KEY_EV_PRECONDITIONING_TIME to " 10" ,
369
332
KEY_AUXILIARY_CONSUMPTION to " 300"
370
333
)
371
- evDataUpdater.updateData (evData)
334
+ mapboxNavigation.onEVDataUpdated (evData)
372
335
mapboxNavigation.setNavigationRoutes(requestedRoutes)
373
336
// corresponds to currentRouteGeometryIndex = 384
374
337
stayOnPosition(48.209765 , 11.478632 )
@@ -413,14 +376,13 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
413
376
acceptedGeometryIndex = 0
414
377
)
415
378
val requestedRoutes = requestRoutes(twoCoordinates, electric = true )
416
- mapboxNavigation.setEVDataUpdater(evDataUpdater)
417
379
val evData = mapOf (
418
380
KEY_ENERGY_CONSUMPTION_CURVE to " 0,300;20,160;80,140;120,180" ,
419
381
KEY_EV_INITIAL_CHARGE to " 17000" ,
420
382
KEY_EV_PRECONDITIONING_TIME to " 10" ,
421
383
KEY_AUXILIARY_CONSUMPTION to " 300"
422
384
)
423
- evDataUpdater.updateData (evData)
385
+ mapboxNavigation.onEVDataUpdated (evData)
424
386
mapboxNavigation.setNavigationRoutes(requestedRoutes)
425
387
stayOnInitialPosition()
426
388
mapboxNavigation.startTripSession()
@@ -456,24 +418,25 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
456
418
457
419
@Test
458
420
fun ev_route_refresh_updates_ev_annotations_and_waypoints_for_second_leg () = sdkTest {
459
- val routeGeometryIndex = 1050
460
- val legGeometryIndex = 300
421
+ val routeGeometryIndex = 774
422
+ val legGeometryIndex = 26
423
+ replaceOriginalResponseHandler(R .raw.ev_route_response_for_refresh_with_2_waypoints)
461
424
addRefreshRequestHandler(
462
425
R .raw.ev_route_refresh_response_for_second_leg,
463
- acceptedGeometryIndex = routeGeometryIndex
426
+ acceptedGeometryIndex = routeGeometryIndex,
427
+ testUuid = " ev_route_response_for_refresh_with_2_waypoints"
464
428
)
465
- val requestedRoutes = requestRoutes(twoCoordinates, electric = true )
466
- mapboxNavigation.setEVDataUpdater(evDataUpdater)
429
+ val requestedRoutes = requestRoutes(twoCoordinates, electric = true , minChargeAtDestination = 35000 )
467
430
val evData = mapOf (
468
431
KEY_ENERGY_CONSUMPTION_CURVE to " 0,300;20,160;80,140;120,180" ,
469
- KEY_EV_INITIAL_CHARGE to " 17000 " ,
432
+ KEY_EV_INITIAL_CHARGE to " 30000 " ,
470
433
KEY_EV_PRECONDITIONING_TIME to " 10" ,
471
434
KEY_AUXILIARY_CONSUMPTION to " 300"
472
435
)
473
- evDataUpdater.updateData (evData)
436
+ mapboxNavigation.onEVDataUpdated (evData)
474
437
mapboxNavigation.setNavigationRoutes(requestedRoutes, initialLegIndex = 1 )
475
- // corresponds to currentRouteGeometryIndex = 1050
476
- stayOnPosition(48.435946 , 10.86999 )
438
+ // corresponds to currentRouteGeometryIndex = 774
439
+ stayOnPosition(48.391238 , 11.064252 , 90f )
477
440
mapboxNavigation.startTripSession()
478
441
mapboxNavigation.routeProgressUpdates().filter { progress ->
479
442
progress.currentRouteGeometryIndex == routeGeometryIndex
@@ -486,11 +449,11 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
486
449
requestedRoutes[0 ].getSocAnnotationsFromLeg(0 )!! .firstLastAnd()
487
450
)
488
451
assertEquals(
489
- listOf (43 , 38 , 10 ),
452
+ listOf (39 , 39 , 10 ),
490
453
requestedRoutes[0 ].getSocAnnotationsFromLeg(1 )!! .firstLastAnd(legGeometryIndex)
491
454
)
492
455
assertEquals(
493
- listOf (null , 8097 , null ),
456
+ listOf (null , 7911 , 6000 , null ),
494
457
requestedRoutes[0 ].directionsResponse.waypoints()?.extractChargeAtArrival()
495
458
)
496
459
@@ -499,11 +462,11 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
499
462
updatedRoutes[0 ].getSocAnnotationsFromLeg(0 )!! .firstLastAnd()
500
463
)
501
464
assertEquals(
502
- listOf (43 , 28 , 1 ),
465
+ listOf (39 , 49 , 21 ),
503
466
updatedRoutes[0 ].getSocAnnotationsFromLeg(1 )!! .firstLastAnd(legGeometryIndex)
504
467
)
505
468
assertEquals(
506
- listOf (null , 8097 , null ),
469
+ listOf (null , 7911 , 12845 , null ),
507
470
updatedRoutes[0 ].directionsResponse.waypoints()?.extractChargeAtArrival()
508
471
)
509
472
}
@@ -512,18 +475,22 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
512
475
stayOnPosition(twoCoordinates[0 ].latitude(), twoCoordinates[0 ].longitude())
513
476
}
514
477
515
- private fun stayOnPosition (latitude : Double , longitude : Double ) {
478
+ private fun stayOnPosition (latitude : Double , longitude : Double , bearing : Float = 190f ) {
516
479
mockLocationReplayerRule.loopUpdate(
517
480
mockLocationUpdatesRule.generateLocationUpdate {
518
481
this .latitude = latitude
519
482
this .longitude = longitude
520
- bearing = 190f
483
+ this . bearing = bearing
521
484
},
522
485
times = 120
523
486
)
524
487
}
525
488
526
- private fun generateRouteOptions (coordinates : List <Point >, electric : Boolean ): RouteOptions {
489
+ private fun generateRouteOptions (
490
+ coordinates : List <Point >,
491
+ electric : Boolean ,
492
+ minChargeAtDestination : Int ,
493
+ ): RouteOptions {
527
494
return RouteOptions .builder().applyDefaultNavigationOptions()
528
495
.profile(DirectionsCriteria .PROFILE_DRIVING_TRAFFIC )
529
496
.alternatives(true )
@@ -540,7 +507,7 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
540
507
KEY_ENERGY_CONSUMPTION_CURVE to " 0,300;20,160;80,140;120,180" ,
541
508
KEY_EV_PRECONDITIONING_TIME to " 10" ,
542
509
" ev_min_charge_at_charging_station" to " 6000" ,
543
- " ev_min_charge_at_destination" to " 6000 " ,
510
+ " ev_min_charge_at_destination" to " $minChargeAtDestination " ,
544
511
" ev_max_charge" to " 60000" ,
545
512
" ev_connector_types" to " ccs_combo_type1,ccs_combo_type2" ,
546
513
" energy_consumption_curve" to " 0,300;20,160;80,140;120,180" ,
@@ -572,9 +539,12 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
572
539
573
540
private suspend fun requestRoutes (
574
541
coordinates : List <Point >,
575
- electric : Boolean
542
+ electric : Boolean ,
543
+ minChargeAtDestination : Int = 6000
576
544
): List <NavigationRoute > {
577
- return mapboxNavigation.requestRoutes(generateRouteOptions(coordinates, electric))
545
+ return mapboxNavigation.requestRoutes(
546
+ generateRouteOptions(coordinates, electric, minChargeAtDestination)
547
+ )
578
548
.getSuccessfulResultOrThrowException()
579
549
.routes
580
550
}
@@ -615,22 +585,27 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
615
585
616
586
private fun addRefreshRequestHandler (
617
587
@IdRes fileId : Int ,
618
- acceptedGeometryIndex : Int
588
+ acceptedGeometryIndex : Int ,
589
+ testUuid : String = responseTestUuid,
619
590
): MockDirectionsRefreshHandler {
620
591
return MockDirectionsRefreshHandler (
621
- responseTestUuid ,
592
+ testUuid ,
622
593
readRawFileText(activity, fileId),
623
594
acceptedGeometryIndex = acceptedGeometryIndex
624
595
).also {
625
596
mockWebServerRule.requestHandlers.add(FailByRequestMockRequestHandler (it))
626
597
}
627
598
}
628
599
629
- private fun getOffRouteLocation (originLocation : Point ): Location =
630
- mockLocationUpdatesRule.generateLocationUpdate {
631
- latitude = originLocation.latitude() + 0.002
632
- longitude = originLocation.longitude()
633
- }
600
+ private fun replaceOriginalResponseHandler (@IdRes fileId : Int ) {
601
+ val routeHandler = MockDirectionsRequestHandler (
602
+ " driving-traffic" ,
603
+ readRawFileText(activity, fileId),
604
+ twoCoordinates,
605
+ relaxedExpectedCoordinates = true
606
+ )
607
+ mockWebServerRule.requestHandlers.add(0 , routeHandler)
608
+ }
634
609
}
635
610
636
611
private class DynamicResponseModifier : (String ) -> String {
@@ -668,21 +643,3 @@ private class DynamicResponseModifier : (String) -> String {
668
643
.toJson()
669
644
}
670
645
}
671
-
672
- @OptIn(ExperimentalPreviewMapboxNavigationAPI ::class )
673
- private class TestEVDataUpdater : EVDataUpdater {
674
-
675
- private val observers = CopyOnWriteArraySet <EVDataObserver >()
676
-
677
- override fun registerEVDataObserver (observer : EVDataObserver ) {
678
- observers.add(observer)
679
- }
680
-
681
- override fun unregisterEVDataObserver (observer : EVDataObserver ) {
682
- observers.remove(observer)
683
- }
684
-
685
- fun updateData (data : Map <String , String ?>) {
686
- observers.forEach { it.onEVDataUpdated(data) }
687
- }
688
- }
0 commit comments