|
14 | 14 |
|
15 | 15 | import java.io.IOException; |
16 | 16 | import java.util.ArrayList; |
| 17 | +import java.util.Arrays; |
17 | 18 | import java.util.List; |
18 | 19 | import java.util.Locale; |
19 | 20 |
|
@@ -214,4 +215,93 @@ public void toJson_fromJson() throws Exception { |
214 | 215 |
|
215 | 216 | assertEquals(routeOptions, routeOptionsFromJson); |
216 | 217 | } |
| 218 | + |
| 219 | + @Test |
| 220 | + public void fromJson() { |
| 221 | + String jsonString = "{" + |
| 222 | + "\"profile\": \"auto\"," + |
| 223 | + "\"user\": \"mapbox\"," + |
| 224 | + "\"baseUrl\": \"https://api.mapbox.com\"," + |
| 225 | + "\"coordinates\": [[-3.707788,40.395039],[-3.712179,40.401819]]," + |
| 226 | + "\"access_token\": \"ACCESS_TOKEN\"," + |
| 227 | + "\"geometries\": \"polyline6\"," + |
| 228 | + "\"overview\": \"full\"," + |
| 229 | + "\"steps\": true," + |
| 230 | + "\"bearings\": \";\"," + |
| 231 | + "\"continue_straight\": true," + |
| 232 | + "\"annotations\": \"congestion,distance\"," + |
| 233 | + "\"language\": \"en\"," + |
| 234 | + "\"roundabout_exits\": true," + |
| 235 | + "\"voice_instructions\": true," + |
| 236 | + "\"banner_instructions\": true," + |
| 237 | + "\"voice_units\": \"imperial\"," + |
| 238 | + "\"uuid\": \"uuid1\"" + |
| 239 | + "}"; |
| 240 | + |
| 241 | + RouteOptions routeOptions = RouteOptions.fromJson(jsonString); |
| 242 | + |
| 243 | + assertEquals("auto", routeOptions.profile()); |
| 244 | + assertEquals("mapbox", routeOptions.user()); |
| 245 | + assertEquals("https://api.mapbox.com", routeOptions.baseUrl()); |
| 246 | + assertEquals(2, routeOptions.coordinates().size()); |
| 247 | + assertEquals("ACCESS_TOKEN", routeOptions.accessToken()); |
| 248 | + assertEquals("polyline6", routeOptions.geometries()); |
| 249 | + assertEquals("full", routeOptions.overview()); |
| 250 | + assertEquals(true, routeOptions.steps()); |
| 251 | + assertEquals(";", routeOptions.bearings()); |
| 252 | + assertEquals(true, routeOptions.continueStraight()); |
| 253 | + assertEquals("congestion,distance", routeOptions.annotations()); |
| 254 | + assertEquals("en", routeOptions.language()); |
| 255 | + assertEquals(true, routeOptions.roundaboutExits()); |
| 256 | + assertEquals(true, routeOptions.voiceInstructions()); |
| 257 | + assertEquals(true, routeOptions.bannerInstructions()); |
| 258 | + assertEquals("imperial", routeOptions.voiceUnits()); |
| 259 | + assertEquals("uuid1", routeOptions.requestUuid()); |
| 260 | + } |
| 261 | + |
| 262 | + @Test |
| 263 | + public void toJson() { |
| 264 | + RouteOptions routeOptions = RouteOptions.builder() |
| 265 | + .profile("auto") |
| 266 | + .user("mapbox") |
| 267 | + .coordinates(Arrays.asList(Point.fromLngLat(-3.707788, 40.395039), |
| 268 | + Point.fromLngLat(-3.712179, 40.401819))) |
| 269 | + .accessToken("ACCESS_TOKEN") |
| 270 | + .baseUrl("https://api.mapbox.com") |
| 271 | + .geometries("polyline6") |
| 272 | + .overview("full") |
| 273 | + .steps(true) |
| 274 | + .bearings(";") |
| 275 | + .continueStraight(true) |
| 276 | + .annotations("congestion,distance") |
| 277 | + .language("en") |
| 278 | + .roundaboutExits(true) |
| 279 | + .voiceInstructions(true) |
| 280 | + .bannerInstructions(true) |
| 281 | + .voiceUnits("imperial") |
| 282 | + .requestUuid("uuid1") |
| 283 | + .build(); |
| 284 | + |
| 285 | + String jsonString = routeOptions.toJson(); |
| 286 | + |
| 287 | + String expectedJsonString = "{" + |
| 288 | + "\"profile\": \"auto\"," + |
| 289 | + "\"user\": \"mapbox\"," + |
| 290 | + "\"baseUrl\": \"https://api.mapbox.com\"," + |
| 291 | + "\"coordinates\": [[-3.707788,40.395039],[-3.712179,40.401819]]," + |
| 292 | + "\"access_token\": \"ACCESS_TOKEN\"," + |
| 293 | + "\"geometries\": \"polyline6\"," + |
| 294 | + "\"overview\": \"full\"," + |
| 295 | + "\"steps\": true," + |
| 296 | + "\"bearings\": \";\"," + |
| 297 | + "\"continue_straight\": true," + |
| 298 | + "\"annotations\": \"congestion,distance\"," + |
| 299 | + "\"language\": \"en\"," + |
| 300 | + "\"roundabout_exits\": true," + |
| 301 | + "\"voice_instructions\": true," + |
| 302 | + "\"banner_instructions\": true," + |
| 303 | + "\"voice_units\": \"imperial\"," + |
| 304 | + "\"uuid\": \"uuid1\"}"; |
| 305 | + compareJson(expectedJsonString, jsonString); |
| 306 | + } |
217 | 307 | } |
0 commit comments