@@ -8,9 +8,6 @@ import com.mapbox.maps.MapboxMap
8
8
import com.mapbox.maps.QueryFeaturesCallback
9
9
import com.mapbox.maps.RenderedQueryOptions
10
10
import 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
14
11
import com.mapbox.navigation.base.trip.model.RouteLegProgress
15
12
import com.mapbox.navigation.base.trip.model.RouteProgress
16
13
import io.mockk.every
@@ -26,111 +23,107 @@ class BuildingProcessorTest {
26
23
27
24
@Test
28
25
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
+ }
49
47
val mockRouteLegProgress = mockk<RouteLegProgress >(relaxed = true ) {
50
48
every { legIndex } returns 0
51
49
}
52
50
val mockRouteProgress = mockk<RouteProgress >(relaxed = true ) {
53
51
every { currentLegProgress } returns mockRouteLegProgress
54
- every { navigationRoute.internalWaypoints() } returns waypoints
52
+ every { route } returns mockRoute
55
53
}
56
54
val mockAction = BuildingAction .QueryBuildingOnWaypoint (mockRouteProgress)
57
55
58
56
val result = BuildingProcessor .queryBuildingOnWaypoint(mockAction)
59
57
60
- assertEquals(waypoints[ 1 ].target !! , result.point)
58
+ assertEquals(result.point, mockWaypointForWaypointTarget )
61
59
}
62
60
63
61
@Test
64
62
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
+ }
85
84
val mockRouteLegProgress = mockk<RouteLegProgress >(relaxed = true ) {
86
85
every { legIndex } returns 0
87
86
}
88
87
val mockRouteProgress = mockk<RouteProgress >(relaxed = true ) {
89
88
every { currentLegProgress } returns mockRouteLegProgress
90
- every { navigationRoute.internalWaypoints() } returns waypoints
89
+ every { route } returns mockRoute
91
90
}
92
91
93
92
val mockAction = BuildingAction .QueryBuildingOnWaypoint (mockRouteProgress)
94
93
95
94
val result = BuildingProcessor .queryBuildingOnWaypoint(mockAction)
96
95
97
- assertEquals(waypoints[ 1 ].location, result.point)
96
+ assertEquals(result.point, mockWaypointForCoordinates )
98
97
}
99
98
100
99
@Test
101
100
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
+ }
122
115
val mockRouteLegProgress = mockk<RouteLegProgress >(relaxed = true ) {
123
116
every { legIndex } returns 0
124
117
}
125
118
val mockRouteProgress = mockk<RouteProgress >(relaxed = true ) {
126
119
every { currentLegProgress } returns mockRouteLegProgress
127
- every { navigationRoute.internalWaypoints() } returns waypoints
120
+ every { route } returns mockRoute
128
121
}
129
122
val mockAction = BuildingAction .QueryBuildingOnWaypoint (mockRouteProgress)
130
123
131
124
val result = BuildingProcessor .queryBuildingOnWaypoint(mockAction)
132
125
133
- assertEquals(waypoints[ 1 ].location, result.point)
126
+ assertEquals(result.point, mockWaypointForCoordinates )
134
127
}
135
128
136
129
@Test
@@ -158,74 +151,69 @@ class BuildingProcessorTest {
158
151
159
152
@Test
160
153
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
+ }
181
175
val mockRouteLegProgress = mockk<RouteLegProgress >(relaxed = true ) {
182
176
every { legIndex } returns 0
183
177
}
184
178
val mockRouteProgress = mockk<RouteProgress >(relaxed = true ) {
185
179
every { currentLegProgress } returns mockRouteLegProgress
186
- every { navigationRoute.internalWaypoints() } returns waypoints
180
+ every { route } returns mockRoute
187
181
}
188
182
val mockAction = BuildingAction .QueryBuildingOnFinalDestination (mockRouteProgress)
189
183
190
184
val result = BuildingProcessor .queryBuildingOnFinalDestination(mockAction)
191
185
192
- assertEquals(waypoints.last().target !! , result.point)
186
+ assertEquals(result.point, mockFinalForWaypointTarget )
193
187
}
194
188
195
189
@Test
196
190
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
+ }
217
205
val mockRouteLegProgress = mockk<RouteLegProgress >(relaxed = true ) {
218
206
every { legIndex } returns 0
219
207
}
220
208
val mockRouteProgress = mockk<RouteProgress >(relaxed = true ) {
221
209
every { currentLegProgress } returns mockRouteLegProgress
222
- every { navigationRoute.internalWaypoints() } returns waypoints
210
+ every { route } returns mockRoute
223
211
}
224
212
val mockAction = BuildingAction .QueryBuildingOnFinalDestination (mockRouteProgress)
225
213
226
214
val result = BuildingProcessor .queryBuildingOnFinalDestination(mockAction)
227
215
228
- assertEquals(waypoints.last().location, result.point)
216
+ assertEquals(result.point, mockFinalForCoordinates )
229
217
}
230
218
231
219
@Test
@@ -253,16 +241,4 @@ class BuildingProcessorTest {
253
241
assertTrue(optionsSlot.captured.layerIds!! .contains(" building" ))
254
242
assertTrue(optionsSlot.captured.layerIds!! .contains(" building-extrusion" ))
255
243
}
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
- )
268
244
}
0 commit comments