@@ -13,8 +13,6 @@ import com.mapbox.navigation.base.options.NavigationOptions
1313import com.mapbox.navigation.base.options.RoutingTilesOptions
1414import com.mapbox.navigation.base.route.NavigationRoute
1515import com.mapbox.navigation.base.route.RouteRefreshOptions
16- import com.mapbox.navigation.core.EVDataObserver
17- import com.mapbox.navigation.core.EVDataUpdater
1816import com.mapbox.navigation.core.MapboxNavigation
1917import com.mapbox.navigation.core.MapboxNavigationProvider
2018import com.mapbox.navigation.core.directions.session.RoutesExtra
@@ -47,7 +45,6 @@ import org.junit.Before
4745import org.junit.Rule
4846import org.junit.Test
4947import java.net.URI
50- import java.util.concurrent.CopyOnWriteArraySet
5148import java.util.concurrent.TimeUnit
5249
5350private const val KEY_ENGINE = " engine"
@@ -78,8 +75,6 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
7875 Point .fromLngLat(11.5852259 , 48.1760993 ),
7976 Point .fromLngLat(10.3406374 , 49.16479 )
8077 )
81- private lateinit var routeHandler: MockDirectionsRequestHandler
82- private val evDataUpdater = TestEVDataUpdater ()
8378
8479 override fun setupMockLocation (): Location = mockLocationUpdatesRule.generateLocationUpdate {
8580 latitude = twoCoordinates[0 ].latitude()
@@ -110,7 +105,7 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
110105 .build()
111106 )
112107 mockWebServerRule.requestHandlers.clear()
113- routeHandler = MockDirectionsRequestHandler (
108+ val routeHandler = MockDirectionsRequestHandler (
114109 " driving-traffic" ,
115110 readRawFileText(activity, R .raw.ev_route_response_for_refresh),
116111 twoCoordinates,
@@ -128,8 +123,7 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
128123 )
129124 val requestedRoutes = requestRoutes(twoCoordinates, electric = false )
130125
131- mapboxNavigation.setEVDataUpdater(evDataUpdater)
132- evDataUpdater.updateData(
126+ mapboxNavigation.onEVDataUpdated(
133127 mapOf (
134128 KEY_ENERGY_CONSUMPTION_CURVE to " 0,300;20,120;40,150" ,
135129 KEY_EV_INITIAL_CHARGE to " 80" ,
@@ -183,14 +177,13 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
183177 val initialCharge = " 80"
184178 val preconditioningTime = " 10"
185179 val auxiliaryConsumption = " 300"
186- mapboxNavigation.setEVDataUpdater(evDataUpdater)
187180 val evData = mapOf (
188181 KEY_ENERGY_CONSUMPTION_CURVE to consumptionCurve,
189182 KEY_EV_INITIAL_CHARGE to initialCharge,
190183 KEY_EV_PRECONDITIONING_TIME to preconditioningTime,
191184 KEY_AUXILIARY_CONSUMPTION to auxiliaryConsumption
192185 )
193- evDataUpdater.updateData (evData)
186+ mapboxNavigation.onEVDataUpdated (evData)
194187
195188 mapboxNavigation.setNavigationRoutes(requestedRoutes)
196189 mapboxNavigation.startTripSession()
@@ -231,8 +224,7 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
231224 KEY_EV_PRECONDITIONING_TIME to preconditioningTime,
232225 KEY_AUXILIARY_CONSUMPTION to auxiliaryConsumption
233226 )
234- mapboxNavigation.setEVDataUpdater(evDataUpdater)
235- evDataUpdater.updateData(firstEvData)
227+ mapboxNavigation.onEVDataUpdated(firstEvData)
236228 waitUntilNewRefresh()
237229
238230 checkHasParameters(
@@ -241,7 +233,7 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
241233 )
242234
243235 val newInitialCharge = " 60"
244- evDataUpdater.updateData (
236+ mapboxNavigation.onEVDataUpdated (
245237 mapOf (
246238 KEY_EV_INITIAL_CHARGE to newInitialCharge,
247239 KEY_EV_PRECONDITIONING_TIME to null ,
@@ -261,34 +253,7 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
261253 )
262254 checkDoesNotHaveParameters(urlWithTwiceUpdatedData, setOf (KEY_EV_PRECONDITIONING_TIME ))
263255
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())
292257 waitUntilNewRefresh()
293258
294259 val urlAfterEmptyUpdate = refreshHandler.handledRequests.last().requestUrl!!
@@ -297,7 +262,7 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
297262 mapOf (
298263 KEY_ENGINE to VALUE_ELECTRIC ,
299264 KEY_ENERGY_CONSUMPTION_CURVE to consumptionCurve,
300- KEY_EV_INITIAL_CHARGE to newUpdaterCharge ,
265+ KEY_EV_INITIAL_CHARGE to newInitialCharge ,
301266 KEY_AUXILIARY_CONSUMPTION to auxiliaryConsumption
302267 )
303268 )
@@ -311,14 +276,13 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
311276 acceptedGeometryIndex = 0
312277 )
313278 val requestedRoutes = requestRoutes(twoCoordinates, electric = true )
314- mapboxNavigation.setEVDataUpdater(evDataUpdater)
315279 val evData = mapOf (
316280 KEY_ENERGY_CONSUMPTION_CURVE to " 0,300;20,160;80,140;120,180" ,
317281 KEY_EV_INITIAL_CHARGE to " 17000" ,
318282 KEY_EV_PRECONDITIONING_TIME to " 10" ,
319283 KEY_AUXILIARY_CONSUMPTION to " 300"
320284 )
321- evDataUpdater.updateData (evData)
285+ mapboxNavigation.onEVDataUpdated (evData)
322286
323287 mapboxNavigation.setNavigationRoutesAndWaitForUpdate(requestedRoutes)
324288 mapboxNavigation.startTripSession()
@@ -361,14 +325,13 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
361325 geometryIndex
362326 )
363327 val requestedRoutes = requestRoutes(twoCoordinates, electric = true )
364- mapboxNavigation.setEVDataUpdater(evDataUpdater)
365328 val evData = mapOf (
366329 KEY_ENERGY_CONSUMPTION_CURVE to " 0,300;20,160;80,140;120,180" ,
367330 KEY_EV_INITIAL_CHARGE to " 17000" ,
368331 KEY_EV_PRECONDITIONING_TIME to " 10" ,
369332 KEY_AUXILIARY_CONSUMPTION to " 300"
370333 )
371- evDataUpdater.updateData (evData)
334+ mapboxNavigation.onEVDataUpdated (evData)
372335 mapboxNavigation.setNavigationRoutes(requestedRoutes)
373336 // corresponds to currentRouteGeometryIndex = 384
374337 stayOnPosition(48.209765 , 11.478632 )
@@ -413,14 +376,13 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
413376 acceptedGeometryIndex = 0
414377 )
415378 val requestedRoutes = requestRoutes(twoCoordinates, electric = true )
416- mapboxNavigation.setEVDataUpdater(evDataUpdater)
417379 val evData = mapOf (
418380 KEY_ENERGY_CONSUMPTION_CURVE to " 0,300;20,160;80,140;120,180" ,
419381 KEY_EV_INITIAL_CHARGE to " 17000" ,
420382 KEY_EV_PRECONDITIONING_TIME to " 10" ,
421383 KEY_AUXILIARY_CONSUMPTION to " 300"
422384 )
423- evDataUpdater.updateData (evData)
385+ mapboxNavigation.onEVDataUpdated (evData)
424386 mapboxNavigation.setNavigationRoutes(requestedRoutes)
425387 stayOnInitialPosition()
426388 mapboxNavigation.startTripSession()
@@ -456,24 +418,29 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
456418
457419 @Test
458420 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)
461424 addRefreshRequestHandler(
462425 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
464433 )
465- val requestedRoutes = requestRoutes(twoCoordinates, electric = true )
466- mapboxNavigation.setEVDataUpdater(evDataUpdater)
467434 val evData = mapOf (
468435 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 " ,
470437 KEY_EV_PRECONDITIONING_TIME to " 10" ,
471438 KEY_AUXILIARY_CONSUMPTION to " 300"
472439 )
473- evDataUpdater.updateData (evData)
440+ mapboxNavigation.onEVDataUpdated (evData)
474441 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 )
477444 mapboxNavigation.startTripSession()
478445 mapboxNavigation.routeProgressUpdates().filter { progress ->
479446 progress.currentRouteGeometryIndex == routeGeometryIndex
@@ -486,11 +453,11 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
486453 requestedRoutes[0 ].getSocAnnotationsFromLeg(0 )!! .firstLastAnd()
487454 )
488455 assertEquals(
489- listOf (43 , 38 , 10 ),
456+ listOf (39 , 39 , 10 ),
490457 requestedRoutes[0 ].getSocAnnotationsFromLeg(1 )!! .firstLastAnd(legGeometryIndex)
491458 )
492459 assertEquals(
493- listOf (null , 8097 , null ),
460+ listOf (null , 7911 , 6000 , null ),
494461 requestedRoutes[0 ].directionsResponse.waypoints()?.extractChargeAtArrival()
495462 )
496463
@@ -499,11 +466,11 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
499466 updatedRoutes[0 ].getSocAnnotationsFromLeg(0 )!! .firstLastAnd()
500467 )
501468 assertEquals(
502- listOf (43 , 28 , 1 ),
469+ listOf (39 , 49 , 21 ),
503470 updatedRoutes[0 ].getSocAnnotationsFromLeg(1 )!! .firstLastAnd(legGeometryIndex)
504471 )
505472 assertEquals(
506- listOf (null , 8097 , null ),
473+ listOf (null , 7911 , 12845 , null ),
507474 updatedRoutes[0 ].directionsResponse.waypoints()?.extractChargeAtArrival()
508475 )
509476 }
@@ -512,18 +479,22 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
512479 stayOnPosition(twoCoordinates[0 ].latitude(), twoCoordinates[0 ].longitude())
513480 }
514481
515- private fun stayOnPosition (latitude : Double , longitude : Double ) {
482+ private fun stayOnPosition (latitude : Double , longitude : Double , bearing : Float = 190f ) {
516483 mockLocationReplayerRule.loopUpdate(
517484 mockLocationUpdatesRule.generateLocationUpdate {
518485 this .latitude = latitude
519486 this .longitude = longitude
520- bearing = 190f
487+ this . bearing = bearing
521488 },
522489 times = 120
523490 )
524491 }
525492
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 {
527498 return RouteOptions .builder().applyDefaultNavigationOptions()
528499 .profile(DirectionsCriteria .PROFILE_DRIVING_TRAFFIC )
529500 .alternatives(true )
@@ -540,7 +511,7 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
540511 KEY_ENERGY_CONSUMPTION_CURVE to " 0,300;20,160;80,140;120,180" ,
541512 KEY_EV_PRECONDITIONING_TIME to " 10" ,
542513 " ev_min_charge_at_charging_station" to " 6000" ,
543- " ev_min_charge_at_destination" to " 6000 " ,
514+ " ev_min_charge_at_destination" to " $minChargeAtDestination " ,
544515 " ev_max_charge" to " 60000" ,
545516 " ev_connector_types" to " ccs_combo_type1,ccs_combo_type2" ,
546517 " energy_consumption_curve" to " 0,300;20,160;80,140;120,180" ,
@@ -572,9 +543,12 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
572543
573544 private suspend fun requestRoutes (
574545 coordinates : List <Point >,
575- electric : Boolean
546+ electric : Boolean ,
547+ minChargeAtDestination : Int = 6000
576548 ): List <NavigationRoute > {
577- return mapboxNavigation.requestRoutes(generateRouteOptions(coordinates, electric))
549+ return mapboxNavigation.requestRoutes(
550+ generateRouteOptions(coordinates, electric, minChargeAtDestination)
551+ )
578552 .getSuccessfulResultOrThrowException()
579553 .routes
580554 }
@@ -615,22 +589,27 @@ class EVRouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.
615589
616590 private fun addRefreshRequestHandler (
617591 @IdRes fileId : Int ,
618- acceptedGeometryIndex : Int
592+ acceptedGeometryIndex : Int ,
593+ testUuid : String = responseTestUuid,
619594 ): MockDirectionsRefreshHandler {
620595 return MockDirectionsRefreshHandler (
621- responseTestUuid ,
596+ testUuid ,
622597 readRawFileText(activity, fileId),
623598 acceptedGeometryIndex = acceptedGeometryIndex
624599 ).also {
625600 mockWebServerRule.requestHandlers.add(FailByRequestMockRequestHandler (it))
626601 }
627602 }
628603
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+ }
634613}
635614
636615private class DynamicResponseModifier : (String ) -> String {
@@ -668,21 +647,3 @@ private class DynamicResponseModifier : (String) -> String {
668647 .toJson()
669648 }
670649}
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