@@ -2,6 +2,7 @@ package com.mapbox.navigation.base.internal.factory
22
33import com.mapbox.geojson.Geometry
44import com.mapbox.geojson.Point
5+ import com.mapbox.navigation.base.internal.factory.RoadObjectFactory.getUpdatedObjectsAhead
56import com.mapbox.navigation.base.internal.factory.RoadObjectFactory.toUpcomingRoadObjects
67import com.mapbox.navigation.base.trip.model.roadobject.RoadObjectType
78import com.mapbox.navigation.base.trip.model.roadobject.SDKAmenity
@@ -37,7 +38,7 @@ import org.junit.Assert.assertEquals
3738import org.junit.Assert.assertNotNull
3839import org.junit.Assert.assertTrue
3940import org.junit.Test
40- import java.util.*
41+ import java.util.Date
4142
4243private typealias SDKRouteAlertLocation =
4344 com.mapbox.navigation.base.trip.model.roadobject.location.RouteAlertLocation
@@ -321,6 +322,54 @@ class RoadObjectFactoryTest {
321322 }
322323 }
323324
325+ @Test
326+ fun `create upcoming route objects reusing existing` () {
327+ val firstUpdate: List <UpcomingRouteAlert > = listOf (
328+ UpcomingRouteAlert (
329+ createRoadObject(
330+ type = com.mapbox.navigator.RoadObjectType .RESTRICTED_AREA ,
331+ location = matchedRoadObjectLocation(location.shape),
332+ id = " 0"
333+ ),
334+ 5.0
335+ ),
336+ UpcomingRouteAlert (
337+ createRoadObject(
338+ type = com.mapbox.navigator.RoadObjectType .RESTRICTED_AREA ,
339+ location = matchedRoadObjectLocation(location.shape),
340+ id = " 1"
341+ ),
342+ 9.0
343+ ),
344+ )
345+ val secondUpdate: List <UpcomingRouteAlert > = listOf (
346+ UpcomingRouteAlert (
347+ createRoadObject(
348+ type = com.mapbox.navigator.RoadObjectType .RESTRICTED_AREA ,
349+ location = matchedRoadObjectLocation(location.shape),
350+ id = " 0"
351+ ),
352+ 4.0
353+ ),
354+ UpcomingRouteAlert (
355+ createRoadObject(
356+ type = com.mapbox.navigator.RoadObjectType .RESTRICTED_AREA ,
357+ location = matchedRoadObjectLocation(location.shape),
358+ id = " 1"
359+ ),
360+ 8.0
361+ ),
362+ )
363+ val existingUpcomingRoadObjects = firstUpdate.toUpcomingRoadObjects()
364+
365+ val roadObjects = existingUpcomingRoadObjects.getUpdatedObjectsAhead(secondUpdate)
366+
367+ assertEquals(4.0 , roadObjects[0 ].distanceToStart)
368+ assertEquals(8.0 , roadObjects[1 ].distanceToStart)
369+ assertTrue(roadObjects[0 ].roadObject == = existingUpcomingRoadObjects[0 ].roadObject)
370+ assertTrue(roadObjects[1 ].roadObject == = existingUpcomingRoadObjects[1 ].roadObject)
371+ }
372+
324373 private fun matchedRoadObjectLocation (geometry : Geometry ): MatchedRoadObjectLocation {
325374 return MatchedRoadObjectLocation .valueOf(object : RouteAlertLocation (1 ) {
326375 override fun getShape (): Geometry = geometry
@@ -435,6 +484,7 @@ class RoadObjectFactoryTest {
435484 tollCollectionInfo : com.mapbox.navigator.TollCollectionInfo ? = null,
436485 serviceAreaInfo : com.mapbox.navigator.ServiceAreaInfo ? = null,
437486 railwayCrossingInfo : com.mapbox.navigator.RailwayCrossingInfo ? = null,
487+ id : String = ID
438488 ): RoadObject {
439489 val metadata = when (type) {
440490 com.mapbox.navigator.RoadObjectType .INCIDENT ->
@@ -453,7 +503,7 @@ class RoadObjectFactoryTest {
453503 }
454504
455505 return RoadObject (
456- ID ,
506+ id ,
457507 LENGTH ,
458508 location,
459509 type,
0 commit comments