@@ -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,29 @@ 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"
428
+ )
429
+ val requestedRoutes = requestRoutes(
430
+ twoCoordinates,
431
+ electric = true ,
432
+ minChargeAtDestination = 35000
464
433
)
465
- val requestedRoutes = requestRoutes(twoCoordinates, electric = true )
466
- mapboxNavigation.setEVDataUpdater(evDataUpdater)
467
434
val evData = mapOf (
468
435
KEY_ENERGY_CONSUMPTION_CURVE to " 0,300;20,160;80,140;120,180" ,
469
- KEY_EV_INITIAL_CHARGE to " 17000 " ,
436
+ KEY_EV_INITIAL_CHARGE to " 30000 " ,
470
437
KEY_EV_PRECONDITIONING_TIME to " 10" ,
471
438
KEY_AUXILIARY_CONSUMPTION to " 300"
472
439
)
473
- evDataUpdater.updateData (evData)
440
+ mapboxNavigation.onEVDataUpdated (evData)
474
441
mapboxNavigation.setNavigationRoutes(requestedRoutes, initialLegIndex = 1 )
475
- // corresponds to currentRouteGeometryIndex = 1050
476
- stayOnPosition(48.435946 , 10.86999 )
442
+ // corresponds to currentRouteGeometryIndex = 774
443
+ stayOnPosition(48.391238 , 11.064252 , 90f )
477
444
mapboxNavigation.startTripSession()
478
445
mapboxNavigation.routeProgressUpdates().filter { progress ->
479
446
progress.currentRouteGeometryIndex == routeGeometryIndex
@@ -486,11 +453,11 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
486
453
requestedRoutes[0 ].getSocAnnotationsFromLeg(0 )!! .firstLastAnd()
487
454
)
488
455
assertEquals(
489
- listOf (43 , 38 , 10 ),
456
+ listOf (39 , 39 , 10 ),
490
457
requestedRoutes[0 ].getSocAnnotationsFromLeg(1 )!! .firstLastAnd(legGeometryIndex)
491
458
)
492
459
assertEquals(
493
- listOf (null , 8097 , null ),
460
+ listOf (null , 7911 , 6000 , null ),
494
461
requestedRoutes[0 ].directionsResponse.waypoints()?.extractChargeAtArrival()
495
462
)
496
463
@@ -499,11 +466,11 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
499
466
updatedRoutes[0 ].getSocAnnotationsFromLeg(0 )!! .firstLastAnd()
500
467
)
501
468
assertEquals(
502
- listOf (43 , 28 , 1 ),
469
+ listOf (39 , 49 , 21 ),
503
470
updatedRoutes[0 ].getSocAnnotationsFromLeg(1 )!! .firstLastAnd(legGeometryIndex)
504
471
)
505
472
assertEquals(
506
- listOf (null , 8097 , null ),
473
+ listOf (null , 7911 , 12845 , null ),
507
474
updatedRoutes[0 ].directionsResponse.waypoints()?.extractChargeAtArrival()
508
475
)
509
476
}
@@ -512,18 +479,22 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
512
479
stayOnPosition(twoCoordinates[0 ].latitude(), twoCoordinates[0 ].longitude())
513
480
}
514
481
515
- private fun stayOnPosition (latitude : Double , longitude : Double ) {
482
+ private fun stayOnPosition (latitude : Double , longitude : Double , bearing : Float = 190f ) {
516
483
mockLocationReplayerRule.loopUpdate(
517
484
mockLocationUpdatesRule.generateLocationUpdate {
518
485
this .latitude = latitude
519
486
this .longitude = longitude
520
- bearing = 190f
487
+ this . bearing = bearing
521
488
},
522
489
times = 120
523
490
)
524
491
}
525
492
526
- private fun generateRouteOptions (coordinates : List <Point >, electric : Boolean ): RouteOptions {
493
+ private fun generateRouteOptions (
494
+ coordinates : List <Point >,
495
+ electric : Boolean ,
496
+ minChargeAtDestination : Int ,
497
+ ): RouteOptions {
527
498
return RouteOptions .builder().applyDefaultNavigationOptions()
528
499
.profile(DirectionsCriteria .PROFILE_DRIVING_TRAFFIC )
529
500
.alternatives(true )
@@ -540,7 +511,7 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
540
511
KEY_ENERGY_CONSUMPTION_CURVE to " 0,300;20,160;80,140;120,180" ,
541
512
KEY_EV_PRECONDITIONING_TIME to " 10" ,
542
513
" ev_min_charge_at_charging_station" to " 6000" ,
543
- " ev_min_charge_at_destination" to " 6000 " ,
514
+ " ev_min_charge_at_destination" to " $minChargeAtDestination " ,
544
515
" ev_max_charge" to " 60000" ,
545
516
" ev_connector_types" to " ccs_combo_type1,ccs_combo_type2" ,
546
517
" energy_consumption_curve" to " 0,300;20,160;80,140;120,180" ,
@@ -572,9 +543,12 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
572
543
573
544
private suspend fun requestRoutes (
574
545
coordinates : List <Point >,
575
- electric : Boolean
546
+ electric : Boolean ,
547
+ minChargeAtDestination : Int = 6000
576
548
): List <NavigationRoute > {
577
- return mapboxNavigation.requestRoutes(generateRouteOptions(coordinates, electric))
549
+ return mapboxNavigation.requestRoutes(
550
+ generateRouteOptions(coordinates, electric, minChargeAtDestination)
551
+ )
578
552
.getSuccessfulResultOrThrowException()
579
553
.routes
580
554
}
@@ -615,22 +589,27 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
615
589
616
590
private fun addRefreshRequestHandler (
617
591
@IdRes fileId : Int ,
618
- acceptedGeometryIndex : Int
592
+ acceptedGeometryIndex : Int ,
593
+ testUuid : String = responseTestUuid,
619
594
): MockDirectionsRefreshHandler {
620
595
return MockDirectionsRefreshHandler (
621
- responseTestUuid ,
596
+ testUuid ,
622
597
readRawFileText(activity, fileId),
623
598
acceptedGeometryIndex = acceptedGeometryIndex
624
599
).also {
625
600
mockWebServerRule.requestHandlers.add(FailByRequestMockRequestHandler (it))
626
601
}
627
602
}
628
603
629
- private fun getOffRouteLocation (originLocation : Point ): Location =
630
- mockLocationUpdatesRule.generateLocationUpdate {
631
- latitude = originLocation.latitude() + 0.002
632
- longitude = originLocation.longitude()
633
- }
604
+ private fun replaceOriginalResponseHandler (@IdRes fileId : Int ) {
605
+ val routeHandler = MockDirectionsRequestHandler (
606
+ " driving-traffic" ,
607
+ readRawFileText(activity, fileId),
608
+ twoCoordinates,
609
+ relaxedExpectedCoordinates = true
610
+ )
611
+ mockWebServerRule.requestHandlers.add(0 , routeHandler)
612
+ }
634
613
}
635
614
636
615
private class DynamicResponseModifier : (String ) -> String {
@@ -668,21 +647,3 @@ private class DynamicResponseModifier : (String) -> String {
668
647
.toJson()
669
648
}
670
649
}
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