Skip to content

Commit 1d7ebd5

Browse files
authored
Added sub - to BannerInstructions and (#823)
directions & active - to BannerText
1 parent b075a78 commit 1d7ebd5

16 files changed

Lines changed: 160 additions & 33 deletions

Makefile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,19 @@ directions-fixtures:
100100

101101
# Directions: voice announcements fixture
102102
curl "https://api.mapbox.com/directions/v5/mapbox/driving/-77.04014240930304,38.91313201360546;-77.04573453985853,38.90725177816208.json?steps=true&overview=full&geometries=polyline6&roundabout_exits=true&voice_instructions=true&banner_instructions=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
103-
-o services-directions/src/test/resources/directions_v5_voice_banner.json
103+
-o services-directions/src/test/resources/directions_v5_voice_banner.json
104104

105105
# Directions: voice announcements invalid locale
106106
curl "https://api.mapbox.com/directions/v5/mapbox/driving/-77.04014240930304,38.91313201360546;-77.04573453985853,38.90725177816208.json?steps=true&overview=full&geometries=polyline6&roundabout_exits=true&voice_instructions=true&language=he&access_token=$(MAPBOX_ACCESS_TOKEN)" \
107-
-o services-directions/src/test/resources/directions_v5_voice_invalid.json
107+
-o services-directions/src/test/resources/directions_v5_voice_invalid.json
108108

109109
# Directions: No route found
110-
curl "https://api.mapbox.com/directions/v5/mapbox/driving/149.72227,-37.59764;170.72975,-42.96489.json?steps=true&overview=full&geometries=polyline6&roundabout_exits=true&voice_instructions=true&banner_instructions=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
111-
-o services-directions/src/test/resources/directions_v5_no_route.json
110+
curl "https://api.mapbox.com/directions/v5/mapbox/driving/-151.2302,-33.9283;-174.7654,-36.8641.json?access_token=$(MAPBOX_ACCESS_TOKEN)" \
111+
-o services-directions/src/test/resources/directions_v5_no_route.json
112112

113113
# Directions: route with banner shield
114114
curl "https://api.mapbox.com/directions/v5/mapbox/driving/-95.69263,29.78771;-95.54899,29.78284.json?steps=true&overview=full&geometries=polyline6&roundabout_exits=true&voice_instructions=true&banner_instructions=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
115-
-o services-directions/src/test/resources/directions_v5_banner_with_shield.json
115+
-o services-directions/src/test/resources/directions_v5_banner_with_shield.json
116116

117117
# Directions: route with bannerText
118118
curl "https://api.mapbox.com/directions/v5/mapbox/driving/-122.03067988107114,37.331808179989494;-122.03178702099605,37.3302383113533?voice_units=imperial&roundabout_exits=true&geometries=polyline&overview=full&steps=true&voice_instructions=true&banner_instructions=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
@@ -122,6 +122,10 @@ directions-fixtures:
122122
curl "https://api.mapbox.com/directions/v5/mapbox/driving-traffic/9.950072,52.150015;7.569915,52.916751?alternatives=true&geometries=polyline6&overview=full&steps=true&bearings=%3B&continue_straight=true&annotations=maxspeed&language=en&access_token=$(MAPBOX_ACCESS_TOKEN)" \
123123
-o services-directions/src/test/resources/directions_v5_max_speed_annotation.json
124124

125+
# Directions: route with sub (and lane data) in BannerInstructions
126+
curl "https://api.mapbox.com/directions/v5/mapbox/driving/-122.403561,37.777689;-122.405786,37.770369.json?access_token=$(MAPBOX_ACCESS_TOKEN)&steps=true&geometries=polyline&banner_instructions=true" \
127+
-o services-directions/src/test/resources/directions_v5_banner_instructions.json
128+
125129
mapmatching-fixtures:
126130
curl "https://api.mapbox.com/matching/v5/mapbox/driving/$(MAP_MATCHING_COORDINATES)?geometries=polyline&language=sv&steps=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
127131
-o services-matching/src/test/resources/map_matching_v5_polyline.json

services-directions/src/main/java/com/mapbox/api/directions/v5/models/BannerComponents.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.mapbox.api.directions.v5.MapboxDirections;
1010

1111
import java.io.Serializable;
12+
import java.util.List;
1213

1314
/**
1415
* A part of the {@link BannerText} which includes a snippet of the full banner text instruction. In
@@ -101,6 +102,29 @@ public static Builder builder() {
101102
@SerializedName("imageBaseURL")
102103
public abstract String imageBaseUrl();
103104

105+
/**
106+
* A List of directions indicating which way you can go from a lane
107+
* (left, right, or straight). If the value is ['left', 'straight'],
108+
* the driver can go straight or left from that lane.
109+
* Present if this is a lane component.
110+
*
111+
* @return List of allowed directions from that lane.
112+
* @since 3.2.0
113+
*/
114+
@Nullable
115+
public abstract List<String> directions();
116+
117+
/**
118+
* A boolean telling you if that lane can be used to complete the upcoming maneuver.
119+
* If multiple lanes are active, then they can all be used to complete the upcoming maneuver.
120+
* Present if this is a lane component.
121+
*
122+
* @return List of allowed directions from that lane.
123+
* @since 3.2.0
124+
*/
125+
@Nullable
126+
public abstract Boolean active();
127+
104128
/**
105129
* Convert the current {@link BannerComponents} to its builder holding the currently assigned
106130
* values. This allows you to modify a single property and then rebuild the object resulting in
@@ -226,6 +250,29 @@ public abstract static class Builder {
226250
*/
227251
public abstract Builder imageBaseUrl(@Nullable String imageBaseUrl);
228252

253+
/**
254+
* A List of directions indicating which way you can go from a lane
255+
* (left, right, or straight). If the value is ['left', 'straight'],
256+
* the driver can go straight or left from that lane.
257+
* Present if this is a lane component.
258+
*
259+
* @param directions List of allowed directions from that lane
260+
* @return this builder for chaining options together
261+
* @since 3.2.0
262+
*/
263+
public abstract Builder directions(List<String> directions);
264+
265+
/**
266+
* A boolean telling you if that lane can be used to complete the upcoming maneuver.
267+
* If multiple lanes are active, then they can all be used to complete the upcoming maneuver.
268+
* Present if this is a lane component.
269+
*
270+
* @param activeState true, if the lane could be used for upcoming maneuver, false - otherwise
271+
* @return this builder for chaining options together
272+
* @since 3.2.0
273+
*/
274+
public abstract Builder active(Boolean activeState);
275+
229276
/**
230277
* Build a new {@link BannerComponents} object.
231278
*

services-directions/src/main/java/com/mapbox/api/directions/v5/models/BannerInstructions.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ public static Builder builder() {
5757
@Nullable
5858
public abstract BannerText secondary();
5959

60+
61+
/**
62+
* Additional information that is included if we feel the driver needs a heads up about something.
63+
* Can include information about the next maneuver (the one after the upcoming one),
64+
* if the step is short - can be null, or can be lane information.
65+
* If we have lane information, that trumps information about the next maneuver.
66+
* @return {@link BannerText} representing the sub visual information
67+
* @since 3.2.0
68+
*/
69+
@Nullable
70+
public abstract BannerText sub();
71+
6072
/**
6173
* Convert the current {@link BannerInstructions} to its builder holding the currently assigned
6274
* values. This allows you to modify a single property and then rebuild the object resulting in
@@ -116,6 +128,18 @@ public abstract static class Builder {
116128
*/
117129
public abstract Builder secondary(@Nullable BannerText secondary);
118130

131+
/**
132+
* Additional information that is included
133+
* if we feel the driver needs a heads up about something.
134+
* Can include information about the next maneuver (the one after the upcoming one),
135+
* if the step is short - can be null, or can be lane information.
136+
* If we have lane information, that trumps information about the next maneuver.
137+
* @param sub {@link BannerText} representing the sub visual information
138+
* @return {@link BannerText} representing the sub visual information
139+
* @since 3.2.0
140+
*/
141+
public abstract Builder sub(@Nullable BannerText sub);
142+
119143
/**
120144
* Build a new {@link BannerInstructions} object.
121145
*

services-directions/src/test/java/com/mapbox/api/directions/v5/MapboxDirectionsTest.java

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.google.gson.Gson;
44
import com.google.gson.GsonBuilder;
5+
import com.mapbox.api.directions.v5.models.BannerComponents;
6+
import com.mapbox.api.directions.v5.models.BannerInstructions;
57
import com.mapbox.api.directions.v5.models.DirectionsResponse;
68
import com.mapbox.api.directions.v5.models.DirectionsRoute;
79
import com.mapbox.api.directions.v5.models.LegAnnotation;
@@ -27,6 +29,8 @@
2729
import okhttp3.mockwebserver.RecordedRequest;
2830
import retrofit2.Response;
2931

32+
import static com.mapbox.api.directions.v5.DirectionsCriteria.GEOMETRY_POLYLINE;
33+
import static com.mapbox.api.directions.v5.DirectionsCriteria.PROFILE_DRIVING;
3034
import static org.hamcrest.CoreMatchers.containsString;
3135
import static org.hamcrest.junit.MatcherAssert.assertThat;
3236
import static org.junit.Assert.assertEquals;
@@ -42,6 +46,7 @@ public class MapboxDirectionsTest extends TestUtils {
4246
private static final String DIRECTIONS_V5_ANNOTATIONS_FIXTURE = "directions_annotations_v5.json";
4347
private static final String DIRECTIONS_V5_NO_ROUTE = "directions_v5_no_route.json";
4448
private static final String DIRECTIONS_V5_MAX_SPEED_ANNOTATION = "directions_v5_max_speed_annotation.json";
49+
private static final String DIRECTIONS_V5_BANNER_INSTRUCTIONS = "directions_v5_banner_instructions.json";
4550

4651
private MockWebServer server;
4752
private HttpUrl mockUrl;
@@ -56,21 +61,20 @@ public MockResponse dispatch(RecordedRequest request) throws InterruptedExceptio
5661

5762
// Switch response on geometry parameter (only false supported, so nice and simple)
5863
String resource = DIRECTIONS_V5_FIXTURE;
59-
if (request.getPath().contains("geometries=polyline6")) {
60-
resource = DIRECTIONS_V5_PRECISION6_FIXTURE;
61-
}
62-
if (request.getPath().contains("driving-traffic")) {
63-
resource = DIRECTIONS_TRAFFIC_FIXTURE;
64-
}
6564
if (request.getPath().contains("-77.04430")) {
6665
resource = DIRECTIONS_ROTARY_FIXTURE;
67-
}
68-
if (request.getPath().contains("annotations")) {
66+
} else if (request.getPath().contains("annotations")) {
6967
resource = DIRECTIONS_V5_ANNOTATIONS_FIXTURE;
70-
}
71-
if (request.getPath().contains("151.2302,-33.9283")) {
68+
} else if (request.getPath().contains("-151.2302")) {
7269
resource = DIRECTIONS_V5_NO_ROUTE;
70+
} else if (request.getPath().contains("-122.403561,37.777689")) {
71+
resource = DIRECTIONS_V5_BANNER_INSTRUCTIONS;
72+
} else if (request.getPath().contains("driving-traffic")) {
73+
resource = DIRECTIONS_TRAFFIC_FIXTURE;
74+
} else if (request.getPath().contains("geometries=polyline6")) {
75+
resource = DIRECTIONS_V5_PRECISION6_FIXTURE;
7376
}
77+
7478
try {
7579
String body = loadJsonFixture(resource);
7680
return new MockResponse().setBody(body);
@@ -360,7 +364,7 @@ public void voiceUnits_doesGetFormattedInUrlCorrectly() throws Exception {
360364
.destination(Point.fromLngLat(13.4930, 9.958))
361365
.origin(Point.fromLngLat(1.234, 2.345))
362366
.accessToken(ACCESS_TOKEN)
363-
.baseUrl(mockUrl.toString())
367+
.baseUrl("https://foobar.com")
364368
.voiceUnits(DirectionsCriteria.METRIC)
365369
.build();
366370

@@ -374,7 +378,7 @@ public void bannerInstructions_doesGetFormattedInUrlCorrectly() throws Exception
374378
.destination(Point.fromLngLat(13.4930, 9.958))
375379
.origin(Point.fromLngLat(1.234, 2.345))
376380
.accessToken(ACCESS_TOKEN)
377-
.baseUrl(mockUrl.toString())
381+
.baseUrl("https://foobar.com")
378382
.bannerInstructions(true)
379383
.build();
380384

@@ -388,7 +392,7 @@ public void voiceInstructions_doesGetFormattedInUrlCorrectly() throws Exception
388392
.destination(Point.fromLngLat(13.4930, 9.958))
389393
.origin(Point.fromLngLat(1.234, 2.345))
390394
.accessToken(ACCESS_TOKEN)
391-
.baseUrl(mockUrl.toString())
395+
.baseUrl("https://foobar.com")
392396
.voiceInstructions(true)
393397
.build();
394398

@@ -402,7 +406,7 @@ public void exclude_doesGetFormattedInUrlCorrectly() throws Exception {
402406
.destination(Point.fromLngLat(13.4930, 9.958))
403407
.origin(Point.fromLngLat(1.234, 2.345))
404408
.accessToken(ACCESS_TOKEN)
405-
.baseUrl(mockUrl.toString())
409+
.baseUrl("https://foobar.com")
406410
.exclude(DirectionsCriteria.EXCLUDE_MOTORWAY)
407411
.build();
408412

@@ -439,7 +443,7 @@ public void testRadiusWithUnlimitedDistance() throws IOException {
439443
.origin(coordinates.get(0))
440444
.addWaypoint(coordinates.get(1))
441445
.destination(coordinates.get(2))
442-
.baseUrl(mockUrl.toString())
446+
.baseUrl("https://foobar.com")
443447
.radiuses(100, Double.POSITIVE_INFINITY, 100)
444448
.build();
445449

@@ -450,8 +454,8 @@ public void testRadiusWithUnlimitedDistance() throws IOException {
450454
@Test
451455
public void noValidRouteTest() throws Exception {
452456
MapboxDirections mapboxDirections = MapboxDirections.builder()
453-
.origin(Point.fromLngLat(151.2302, -33.9283))
454-
.destination(Point.fromLngLat(174.7654, -36.8641))
457+
.origin(Point.fromLngLat(-151.2302, -33.9283))
458+
.destination(Point.fromLngLat(-174.7654, -36.8641))
455459
.baseUrl(mockUrl.toString())
456460
.accessToken(ACCESS_TOKEN)
457461
.steps(true)
@@ -501,4 +505,51 @@ public void maxSpeedAnnotation_doesGetCreatedInResponse() throws IOException {
501505

502506
assertNotNull(maxSpeedAnnotation.maxspeed());
503507
}
508+
509+
@Test
510+
public void subBannerInstructions() throws Exception {
511+
Gson gson = new GsonBuilder()
512+
.registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
513+
String body = loadJsonFixture(DIRECTIONS_V5_BANNER_INSTRUCTIONS);
514+
DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);
515+
516+
BannerInstructions bannerInstructions =
517+
response.routes().get(0).legs().get(0).steps().get(0).bannerInstructions().get(1);
518+
519+
assertNotNull(bannerInstructions.sub());
520+
assertNotNull(bannerInstructions.sub().components());
521+
522+
BannerComponents component = bannerInstructions.sub().components().get(1);
523+
assertNotNull(component.active());
524+
assertNotNull(component.directions());
525+
assertEquals(2, component.directions().size());
526+
}
527+
528+
@Test
529+
public void subBannerInstructionsFromJson() throws Exception {
530+
531+
MapboxDirections mapboxDirections = MapboxDirections.builder()
532+
.origin(Point.fromLngLat(-122.403561,37.777689))
533+
.destination(Point.fromLngLat(-122.405786,37.770369))
534+
.accessToken(ACCESS_TOKEN)
535+
.profile(PROFILE_DRIVING)
536+
.steps(true)
537+
.geometries(GEOMETRY_POLYLINE)
538+
.bannerInstructions(true)
539+
.baseUrl(mockUrl.toString())
540+
.build();
541+
542+
Response<DirectionsResponse> response = mapboxDirections.executeCall();
543+
544+
BannerInstructions bannerInstructions =
545+
response.body().routes().get(0).legs().get(0).steps().get(0).bannerInstructions().get(1);
546+
547+
assertNotNull(bannerInstructions.sub());
548+
assertNotNull(bannerInstructions.sub().components());
549+
550+
BannerComponents component = bannerInstructions.sub().components().get(1);
551+
assertNotNull(component.active());
552+
assertNotNull(component.directions());
553+
assertEquals(2, component.directions().size());
554+
}
504555
}

services-directions/src/test/resources/directions_annotations_v5.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

services-directions/src/test/resources/directions_v5.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)