@@ -8,9 +8,6 @@ import com.mapbox.maps.MapboxMap
88import com.mapbox.maps.QueryFeaturesCallback
99import com.mapbox.maps.RenderedQueryOptions
1010import com.mapbox.maps.ScreenCoordinate
11- import com.mapbox.navigation.base.internal.route.Waypoint
12- import com.mapbox.navigation.base.internal.utils.WaypointFactory
13- import com.mapbox.navigation.base.internal.utils.internalWaypoints
1411import com.mapbox.navigation.base.trip.model.RouteLegProgress
1512import com.mapbox.navigation.base.trip.model.RouteProgress
1613import io.mockk.every
@@ -26,111 +23,107 @@ class BuildingProcessorTest {
2623
2724 @Test
2825 fun `map query on waypoint arrival with waypoint targets` () {
29- val waypoints = listOf (
30- provideWaypoint(
31- Point .fromLngLat(- 122.4192 , 37.7627 ),
32- Waypoint .REGULAR ,
33- " " ,
34- Point .fromLngLat(- 122.4192 , 37.7627 ),
35- ),
36- provideWaypoint(
37- Point .fromLngLat(- 122.4182 , 37.7651 ),
38- Waypoint .REGULAR ,
39- " " ,
40- Point .fromLngLat(- 122.4183 , 37.7653 ),
41- ),
42- provideWaypoint(
43- Point .fromLngLat(- 122.4145 , 37.7653 ),
44- Waypoint .REGULAR ,
45- " " ,
46- Point .fromLngLat(- 122.4146 , 37.7655 ),
47- ),
48- )
26+ val mockOriginForWaypointTarget = Point .fromLngLat(- 122.4192 , 37.7627 )
27+ val mockWaypointForWaypointTarget = Point .fromLngLat(- 122.4183 , 37.7653 )
28+ val mockFinalForWaypointTarget = Point .fromLngLat(- 122.4146 , 37.7655 )
29+ val mockOriginForCoordinates = Point .fromLngLat(- 122.4192 , 37.7627 )
30+ val mockWaypointForCoordinates = Point .fromLngLat(- 122.4182 , 37.7651 )
31+ val mockFinalForCoordinates = Point .fromLngLat(- 122.4145 , 37.7653 )
32+ val mockRouteOptions = mockk<RouteOptions >(relaxed = true ) {
33+ every { coordinatesList() } returns listOf (
34+ mockOriginForCoordinates,
35+ mockWaypointForCoordinates,
36+ mockFinalForCoordinates
37+ )
38+ every { waypointTargetsList() } returns listOf (
39+ mockOriginForWaypointTarget,
40+ mockWaypointForWaypointTarget,
41+ mockFinalForWaypointTarget
42+ )
43+ }
44+ val mockRoute = mockk<DirectionsRoute >(relaxed = true ) {
45+ every { routeOptions() } returns mockRouteOptions
46+ }
4947 val mockRouteLegProgress = mockk<RouteLegProgress >(relaxed = true ) {
5048 every { legIndex } returns 0
5149 }
5250 val mockRouteProgress = mockk<RouteProgress >(relaxed = true ) {
5351 every { currentLegProgress } returns mockRouteLegProgress
54- every { navigationRoute.internalWaypoints() } returns waypoints
52+ every { route } returns mockRoute
5553 }
5654 val mockAction = BuildingAction .QueryBuildingOnWaypoint (mockRouteProgress)
5755
5856 val result = BuildingProcessor .queryBuildingOnWaypoint(mockAction)
5957
60- assertEquals(waypoints[ 1 ].target !! , result.point)
58+ assertEquals(result.point, mockWaypointForWaypointTarget )
6159 }
6260
6361 @Test
6462 fun `map query on waypoint arrival with some waypoint targets` () {
65- val waypoints = listOf (
66- provideWaypoint(
67- Point .fromLngLat(- 122.4192 , 37.7627 ),
68- Waypoint .REGULAR ,
69- " " ,
70- Point .fromLngLat(- 122.4192 , 37.7627 ),
71- ),
72- provideWaypoint(
73- Point .fromLngLat(- 122.4182 , 37.7651 ),
74- Waypoint .REGULAR ,
75- " " ,
76- null ,
77- ),
78- provideWaypoint(
79- Point .fromLngLat(- 122.4145 , 37.7653 ),
80- Waypoint .REGULAR ,
81- " " ,
82- Point .fromLngLat(- 122.4146 , 37.7655 ),
83- ),
84- )
63+ val mockOriginForWaypointTarget = Point .fromLngLat(- 122.4192 , 37.7627 )
64+ val mockWaypointForWaypointTarget = null
65+ val mockFinalForWaypointTarget = Point .fromLngLat(- 122.4146 , 37.7655 )
66+ val mockOriginForCoordinates = Point .fromLngLat(- 122.4192 , 37.7627 )
67+ val mockWaypointForCoordinates = Point .fromLngLat(- 122.4182 , 37.7651 )
68+ val mockFinalForCoordinates = Point .fromLngLat(- 122.4145 , 37.7653 )
69+ val mockRouteOptions = mockk<RouteOptions >(relaxed = true ) {
70+ every { coordinatesList() } returns listOf (
71+ mockOriginForCoordinates,
72+ mockWaypointForCoordinates,
73+ mockFinalForCoordinates
74+ )
75+ every { waypointTargetsList() } returns listOf (
76+ mockOriginForWaypointTarget,
77+ mockWaypointForWaypointTarget,
78+ mockFinalForWaypointTarget
79+ )
80+ }
81+ val mockRoute = mockk<DirectionsRoute >(relaxed = true ) {
82+ every { routeOptions() } returns mockRouteOptions
83+ }
8584 val mockRouteLegProgress = mockk<RouteLegProgress >(relaxed = true ) {
8685 every { legIndex } returns 0
8786 }
8887 val mockRouteProgress = mockk<RouteProgress >(relaxed = true ) {
8988 every { currentLegProgress } returns mockRouteLegProgress
90- every { navigationRoute.internalWaypoints() } returns waypoints
89+ every { route } returns mockRoute
9190 }
9291
9392 val mockAction = BuildingAction .QueryBuildingOnWaypoint (mockRouteProgress)
9493
9594 val result = BuildingProcessor .queryBuildingOnWaypoint(mockAction)
9695
97- assertEquals(waypoints[ 1 ].location, result.point)
96+ assertEquals(result.point, mockWaypointForCoordinates )
9897 }
9998
10099 @Test
101100 fun `map query on waypoint arrival without waypoint targets` () {
102- val waypoints = listOf (
103- provideWaypoint(
104- Point .fromLngLat(- 122.4192 , 37.7627 ),
105- Waypoint .REGULAR ,
106- " " ,
107- null ,
108- ),
109- provideWaypoint(
110- Point .fromLngLat(- 122.4182 , 37.7651 ),
111- Waypoint .REGULAR ,
112- " " ,
113- null ,
114- ),
115- provideWaypoint(
116- Point .fromLngLat(- 122.4145 , 37.7653 ),
117- Waypoint .REGULAR ,
118- " " ,
119- null ,
120- ),
121- )
101+ val mockOriginForCoordinates = Point .fromLngLat(- 122.4192 , 37.7627 )
102+ val mockWaypointForCoordinates = Point .fromLngLat(- 122.4182 , 37.7651 )
103+ val mockFinalForCoordinates = Point .fromLngLat(- 122.4145 , 37.7653 )
104+ val mockRouteOptions = mockk<RouteOptions >(relaxed = true ) {
105+ every { coordinatesList() } returns listOf (
106+ mockOriginForCoordinates,
107+ mockWaypointForCoordinates,
108+ mockFinalForCoordinates
109+ )
110+ every { waypointTargetsList() } returns null
111+ }
112+ val mockRoute = mockk<DirectionsRoute >(relaxed = true ) {
113+ every { routeOptions() } returns mockRouteOptions
114+ }
122115 val mockRouteLegProgress = mockk<RouteLegProgress >(relaxed = true ) {
123116 every { legIndex } returns 0
124117 }
125118 val mockRouteProgress = mockk<RouteProgress >(relaxed = true ) {
126119 every { currentLegProgress } returns mockRouteLegProgress
127- every { navigationRoute.internalWaypoints() } returns waypoints
120+ every { route } returns mockRoute
128121 }
129122 val mockAction = BuildingAction .QueryBuildingOnWaypoint (mockRouteProgress)
130123
131124 val result = BuildingProcessor .queryBuildingOnWaypoint(mockAction)
132125
133- assertEquals(waypoints[ 1 ].location, result.point)
126+ assertEquals(result.point, mockWaypointForCoordinates )
134127 }
135128
136129 @Test
@@ -158,74 +151,69 @@ class BuildingProcessorTest {
158151
159152 @Test
160153 fun `map query on final destination arrival with waypoint targets` () {
161- val waypoints = listOf (
162- provideWaypoint(
163- Point .fromLngLat(- 122.4192 , 37.7627 ),
164- Waypoint .REGULAR ,
165- " " ,
166- Point .fromLngLat(- 122.4192 , 37.7627 ),
167- ),
168- provideWaypoint(
169- Point .fromLngLat(- 122.4182 , 37.7651 ),
170- Waypoint .REGULAR ,
171- " " ,
172- Point .fromLngLat(- 122.4183 , 37.7653 ),
173- ),
174- provideWaypoint(
175- Point .fromLngLat(- 122.4145 , 37.7653 ),
176- Waypoint .REGULAR ,
177- " " ,
178- Point .fromLngLat(- 122.4146 , 37.7655 ),
179- ),
180- )
154+ val mockOriginForWaypointTarget = Point .fromLngLat(- 122.4192 , 37.7627 )
155+ val mockWaypointForWaypointTarget = Point .fromLngLat(- 122.4183 , 37.7653 )
156+ val mockFinalForWaypointTarget = Point .fromLngLat(- 122.4146 , 37.7655 )
157+ val mockOriginForCoordinates = Point .fromLngLat(- 122.4192 , 37.7627 )
158+ val mockWaypointForCoordinates = Point .fromLngLat(- 122.4182 , 37.7651 )
159+ val mockFinalForCoordinates = Point .fromLngLat(- 122.4145 , 37.7653 )
160+ val mockRouteOptions = mockk<RouteOptions >(relaxed = true ) {
161+ every { coordinatesList() } returns listOf (
162+ mockOriginForCoordinates,
163+ mockWaypointForCoordinates,
164+ mockFinalForCoordinates
165+ )
166+ every { waypointTargetsList() } returns listOf (
167+ mockOriginForWaypointTarget,
168+ mockWaypointForWaypointTarget,
169+ mockFinalForWaypointTarget
170+ )
171+ }
172+ val mockRoute = mockk<DirectionsRoute >(relaxed = true ) {
173+ every { routeOptions() } returns mockRouteOptions
174+ }
181175 val mockRouteLegProgress = mockk<RouteLegProgress >(relaxed = true ) {
182176 every { legIndex } returns 0
183177 }
184178 val mockRouteProgress = mockk<RouteProgress >(relaxed = true ) {
185179 every { currentLegProgress } returns mockRouteLegProgress
186- every { navigationRoute.internalWaypoints() } returns waypoints
180+ every { route } returns mockRoute
187181 }
188182 val mockAction = BuildingAction .QueryBuildingOnFinalDestination (mockRouteProgress)
189183
190184 val result = BuildingProcessor .queryBuildingOnFinalDestination(mockAction)
191185
192- assertEquals(waypoints.last().target !! , result.point)
186+ assertEquals(result.point, mockFinalForWaypointTarget )
193187 }
194188
195189 @Test
196190 fun `map query on final destination arrival without waypoint targets` () {
197- val waypoints = listOf (
198- provideWaypoint(
199- Point .fromLngLat(- 122.4192 , 37.7627 ),
200- Waypoint .REGULAR ,
201- " " ,
202- null ,
203- ),
204- provideWaypoint(
205- Point .fromLngLat(- 122.4182 , 37.7651 ),
206- Waypoint .REGULAR ,
207- " " ,
208- null ,
209- ),
210- provideWaypoint(
211- Point .fromLngLat(- 122.4145 , 37.7653 ),
212- Waypoint .REGULAR ,
213- " " ,
214- null ,
215- ),
216- )
191+ val mockOriginForCoordinates = Point .fromLngLat(- 122.4192 , 37.7627 )
192+ val mockWaypointForCoordinates = Point .fromLngLat(- 122.4182 , 37.7651 )
193+ val mockFinalForCoordinates = Point .fromLngLat(- 122.4145 , 37.7653 )
194+ val mockRouteOptions = mockk<RouteOptions >(relaxed = true ) {
195+ every { coordinatesList() } returns listOf (
196+ mockOriginForCoordinates,
197+ mockWaypointForCoordinates,
198+ mockFinalForCoordinates
199+ )
200+ every { waypointTargetsList() } returns null
201+ }
202+ val mockRoute = mockk<DirectionsRoute >(relaxed = true ) {
203+ every { routeOptions() } returns mockRouteOptions
204+ }
217205 val mockRouteLegProgress = mockk<RouteLegProgress >(relaxed = true ) {
218206 every { legIndex } returns 0
219207 }
220208 val mockRouteProgress = mockk<RouteProgress >(relaxed = true ) {
221209 every { currentLegProgress } returns mockRouteLegProgress
222- every { navigationRoute.internalWaypoints() } returns waypoints
210+ every { route } returns mockRoute
223211 }
224212 val mockAction = BuildingAction .QueryBuildingOnFinalDestination (mockRouteProgress)
225213
226214 val result = BuildingProcessor .queryBuildingOnFinalDestination(mockAction)
227215
228- assertEquals(waypoints.last().location, result.point)
216+ assertEquals(result.point, mockFinalForCoordinates )
229217 }
230218
231219 @Test
@@ -253,16 +241,4 @@ class BuildingProcessorTest {
253241 assertTrue(optionsSlot.captured.layerIds!! .contains(" building" ))
254242 assertTrue(optionsSlot.captured.layerIds!! .contains(" building-extrusion" ))
255243 }
256-
257- private fun provideWaypoint (
258- location : Point ,
259- @Waypoint.Type type : Int ,
260- name : String ,
261- target : Point ? ,
262- ): Waypoint = WaypointFactory .provideWaypoint(
263- location,
264- name,
265- target,
266- type
267- )
268244}
0 commit comments