Skip to content

Commit 5036acd

Browse files
authored
Add voiceLocale to DirectionsRoute and update test fixtures (#804)
* Add voiceLocale to DirectionsRoute and update test fixtures * Change voiceLocale to voiceLanguage
1 parent d925bf6 commit 5036acd

14 files changed

Lines changed: 68 additions & 13 deletions

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ directions-fixtures:
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)" \
103103
-o services-directions/src/test/resources/directions_v5_voice_banner.json
104104

105+
# Directions: voice announcements invalid locale
106+
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
108+
105109
# Directions: No route found
106110
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)" \
107111
-o services-directions/src/test/resources/directions_v5_no_route.json

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ public static DirectionsRoute fromJson(String json) {
123123
@Nullable
124124
public abstract RouteOptions routeOptions();
125125

126+
127+
/**
128+
* String of the language to be used for voice instructions. Defaults to en, and
129+
* can be any accepted instruction language.
130+
*
131+
* @return String compatible with voice instructions, null otherwise
132+
* @since 3.1.0
133+
*/
134+
@Nullable
135+
@SerializedName("voiceLocale")
136+
public abstract String voiceLanguage();
137+
126138
/**
127139
* Convert the current {@link DirectionsRoute} to its builder holding the currently assigned
128140
* values. This allows you to modify a single property and then rebuild the object resulting in
@@ -219,6 +231,16 @@ public abstract static class Builder {
219231
*/
220232
public abstract Builder routeOptions(@Nullable RouteOptions routeOptions);
221233

234+
/**
235+
* String of the language to be used for voice instructions. Defaults to en, and
236+
* can be any accepted instruction language.
237+
*
238+
* @param voiceLanguage String compatible with voice instructions, null otherwise
239+
* @return this builder for chaining options together
240+
* @since 3.1.0
241+
*/
242+
public abstract Builder voiceLanguage(@Nullable String voiceLanguage);
243+
222244
/**
223245
* Build a new {@link DirectionsRoute} object.
224246
*

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
package com.mapbox.api.directions.v5.models;
22

3-
import static org.junit.Assert.assertEquals;
4-
import static org.junit.Assert.assertNotNull;
5-
63
import com.mapbox.core.TestUtils;
4+
75
import org.junit.Test;
86

7+
import static org.junit.Assert.assertEquals;
8+
import static org.junit.Assert.assertNotNull;
9+
import static org.junit.Assert.assertNull;
10+
911
public class DirectionsRouteTest extends TestUtils {
1012

13+
private static final String DIRECTIONS_V5_VOICE_BANNER_FIXTURE = "directions_v5_voice_banner.json";
14+
private static final String DIRECTIONS_V5_VOICE_INVALID_FIXTURE = "directions_v5_voice_invalid.json";
15+
private static final int FIRST_ROUTE = 0;
16+
1117
@Test
1218
public void sanity() throws Exception {
1319
DirectionsRoute route = DirectionsRoute.builder()
@@ -22,4 +28,26 @@ public void testSerializable() throws Exception {
2228
byte[] serialized = TestUtils.serialize(route);
2329
assertEquals(route, deserialize(serialized, DirectionsRoute.class));
2430
}
31+
32+
@Test
33+
public void directionsRoute_doesReturnVoiceLocale() throws Exception {
34+
String json = loadJsonFixture(DIRECTIONS_V5_VOICE_BANNER_FIXTURE);
35+
DirectionsResponse response = DirectionsResponse.fromJson(json);
36+
DirectionsRoute route = response.routes().get(FIRST_ROUTE);
37+
38+
String voiceLanguage = route.voiceLanguage();
39+
40+
assertEquals("en-US", voiceLanguage);
41+
}
42+
43+
@Test
44+
public void directionsRouteWithInvalidLanguage_doesReturnNullVoiceLanguage() throws Exception {
45+
String json = loadJsonFixture(DIRECTIONS_V5_VOICE_INVALID_FIXTURE);
46+
DirectionsResponse response = DirectionsResponse.fromJson(json);
47+
DirectionsRoute route = response.routes().get(FIRST_ROUTE);
48+
49+
String voiceLanguage = route.voiceLanguage();
50+
51+
assertNull(voiceLanguage);
52+
}
2553
}

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.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"routes":[{"geometry":"yjzbFfcygVV?vA?P@NAzAa@VGX`BRbAF\\@`@?P","legs":[{"summary":"Infinite Loop, Mariani Avenue","weight":77.2,"duration":66.4,"steps":[{"intersections":[{"out":0,"entry":[true],"bearings":[180],"location":[-122.03076,37.331808]},{"out":1,"in":0,"entry":[false,true,true],"bearings":[0,180,270],"location":[-122.03076,37.331686]},{"out":1,"in":0,"entry":[false,true,true],"bearings":[0,165,270],"location":[-122.030765,37.331157]}],"driving_side":"right","geometry":"yjzbFfcygVV?vA?P@NAzAa@VG","mode":"driving","maneuver":{"bearing_after":180,"bearing_before":0,"location":[-122.03076,37.331808],"modifier":"left","type":"depart","instruction":"Head south on Infinite Loop"},"weight":52.8,"duration":42.1,"name":"Infinite Loop","distance":148,"voiceInstructions":[{"distanceAlongGeometry":148,"announcement":"Head south on Infinite Loop, then turn right onto Mariani Avenue","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">Head south on Infinite Loop, then turn right onto Mariani Avenue</prosody></amazon:effect></speak>"},{"distanceAlongGeometry":52.7,"announcement":"Turn right onto Mariani Avenue, then you will arrive at your destination","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">Turn right onto Mariani Avenue, then you will arrive at your destination</prosody></amazon:effect></speak>"}],"bannerInstructions":[{"distanceAlongGeometry":148,"primary":{"type":"turn","modifier":"right","components":[{"text":"Mariani Avenue","type":"text","abbr":"Mariani Ave","abbr_priority":0}],"text":"Mariani Avenue"},"secondary":null}]},{"intersections":[{"out":1,"in":2,"entry":[true,true,false],"bearings":[90,255,345],"location":[-122.03055,37.3305]}],"driving_side":"right","geometry":"sbzbF|aygVX`BRbAF\\@`@?P","mode":"driving","maneuver":{"bearing_after":250,"bearing_before":163,"location":[-122.03055,37.3305],"modifier":"right","type":"end of road","instruction":"Turn right onto Mariani Avenue"},"weight":24.4,"duration":24.3,"name":"Mariani Avenue","distance":114.5,"voiceInstructions":[{"distanceAlongGeometry":14.1,"announcement":"You have arrived at your destination","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">You have arrived at your destination</prosody></amazon:effect></speak>"}],"bannerInstructions":[{"distanceAlongGeometry":114.5,"primary":{"type":"arrive","modifier":"straight","components":[{"text":"You will arrive","type":"text"}],"text":"You will arrive"},"secondary":{"type":"arrive","modifier":"straight","components":[{"text":"Mariani Avenue","type":"text","abbr":"Mariani Ave","abbr_priority":0}],"text":"Mariani Avenue"}},{"distanceAlongGeometry":15,"primary":{"type":"arrive","modifier":"straight","components":[{"text":"You have arrived","type":"text"}],"text":"You have arrived"},"secondary":{"type":"arrive","modifier":"straight","components":[{"text":"Mariani Avenue","type":"text","abbr":"Mariani Ave","abbr_priority":0}],"text":"Mariani Avenue"}}]},{"intersections":[{"in":0,"entry":[true],"bearings":[90],"location":[-122.031787,37.330217]}],"driving_side":"right","geometry":"{`zbFtiygV","mode":"driving","maneuver":{"bearing_after":0,"bearing_before":270,"location":[-122.031787,37.330217],"type":"arrive","instruction":"You have arrived at your destination"},"weight":0,"duration":0,"name":"Mariani Avenue","distance":0,"voiceInstructions":[],"bannerInstructions":[]}],"distance":262.5}],"weight_name":"routability","weight":77.2,"duration":66.4,"distance":262.5,"voiceLocale":"en-US"}],"waypoints":[{"name":"Infinite Loop","location":[-122.03076,37.331808]},{"name":"Mariani Avenue","location":[-122.031787,37.330217]}],"code":"Ok","uuid":"cjfe60xo206wx42pbqmyydvfy"}
1+
{"routes":[{"geometry":"yjzbFfcygVV?vA?P@NAzAa@VGX`BRbAF\\@`@?P","legs":[{"summary":"Infinite Loop, Mariani Avenue","weight":78.8,"duration":68,"steps":[{"intersections":[{"out":0,"entry":[true],"bearings":[180],"location":[-122.03076,37.331808]},{"out":1,"in":0,"entry":[false,true,true],"bearings":[0,180,270],"location":[-122.03076,37.331686]},{"out":1,"in":0,"entry":[false,true,true],"bearings":[0,165,270],"location":[-122.030765,37.331157]}],"driving_side":"right","geometry":"yjzbFfcygVV?vA?P@NAzAa@VG","mode":"driving","maneuver":{"bearing_after":180,"bearing_before":0,"location":[-122.03076,37.331808],"modifier":"left","type":"depart","instruction":"Head south on Infinite Loop"},"weight":52.8,"duration":42.1,"name":"Infinite Loop","distance":148,"voiceInstructions":[{"distanceAlongGeometry":148,"announcement":"Head south on Infinite Loop, then turn right onto Mariani Avenue","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">Head south on Infinite Loop, then turn right onto Mariani Avenue</prosody></amazon:effect></speak>"},{"distanceAlongGeometry":52.7,"announcement":"Turn right onto Mariani Avenue, then you will arrive at your destination","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">Turn right onto Mariani Avenue, then you will arrive at your destination</prosody></amazon:effect></speak>"}],"bannerInstructions":[{"distanceAlongGeometry":148,"primary":{"text":"Mariani Avenue","components":[{"text":"Mariani Avenue","type":"text","abbr":"Mariani Ave","abbr_priority":0}],"type":"turn","modifier":"right"},"secondary":null}]},{"intersections":[{"out":1,"in":2,"entry":[true,true,false],"bearings":[90,255,345],"location":[-122.03055,37.3305]}],"driving_side":"right","geometry":"sbzbF|aygVX`BRbAF\\@`@?P","mode":"driving","maneuver":{"bearing_after":250,"bearing_before":163,"location":[-122.03055,37.3305],"modifier":"right","type":"end of road","instruction":"Turn right onto Mariani Avenue"},"weight":26,"duration":25.9,"name":"Mariani Avenue","distance":114.5,"voiceInstructions":[{"distanceAlongGeometry":13.3,"announcement":"You have arrived at your destination","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">You have arrived at your destination</prosody></amazon:effect></speak>"}],"bannerInstructions":[{"distanceAlongGeometry":114.5,"primary":{"text":"You will arrive","components":[{"text":"You will arrive","type":"text"}],"type":"arrive","modifier":"straight"},"secondary":null},{"distanceAlongGeometry":15,"primary":{"text":"You have arrived","components":[{"text":"You have arrived","type":"text"}],"type":"arrive","modifier":"straight"},"secondary":null}]},{"intersections":[{"in":0,"entry":[true],"bearings":[90],"location":[-122.031787,37.330217]}],"driving_side":"right","geometry":"{`zbFtiygV","mode":"driving","maneuver":{"bearing_after":0,"bearing_before":270,"location":[-122.031787,37.330217],"type":"arrive","instruction":"You have arrived at your destination"},"weight":0,"duration":0,"name":"Mariani Avenue","distance":0,"voiceInstructions":[],"bannerInstructions":[]}],"distance":262.5}],"weight_name":"routability","weight":78.8,"duration":68,"distance":262.5,"voiceLocale":"en-US"}],"waypoints":[{"name":"Infinite Loop","location":[-122.03076,37.331808]},{"name":"Mariani Avenue","location":[-122.031787,37.330217]}],"code":"Ok","uuid":"cjge5fi1506sr3vpcd19wufgh"}

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

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"routes":[{"geometry":"ejnlFdvfuMeAeAIg@FgAGw@]{@YU]OU]G[?yA","legs":[{"summary":"New Hampshire Avenue Northwest, Dupont Circle NW","weight":129.6,"duration":104.4,"steps":[{"intersections":[{"out":0,"entry":[true],"bearings":[36],"location":[-77.044347,38.908673]},{"out":1,"in":2,"entry":[false,true,false],"bearings":[15,60,210],"location":[-77.044059,38.908982]}],"driving_side":"right","geometry":"ejnlFdvfuM}@y@GKEOCK?KAG","mode":"driving","maneuver":{"bearing_after":36,"bearing_before":0,"location":[-77.044347,38.908673],"type":"depart","instruction":"Head northeast on New Hampshire Avenue Northwest"},"weight":35.2,"duration":34.7,"name":"New Hampshire Avenue Northwest","distance":71.5},{"intersections":[{"out":0,"in":1,"entry":[true,false,false],"bearings":[105,270,300],"location":[-77.043755,38.909076]},{"out":0,"in":3,"entry":[true,true,true,false],"bearings":[105,120,135,285],"location":[-77.043591,38.909037]},{"out":0,"in":2,"entry":[true,false,false],"bearings":[45,195,225],"location":[-77.042939,38.909165]},{"out":0,"in":2,"entry":[true,true,false,false],"bearings":[30,75,210,255],"location":[-77.042775,38.909307]},{"out":1,"in":3,"entry":[true,true,false,false,true],"bearings":[15,45,135,195,345],"location":[-77.042669,38.909502]},{"out":0,"in":1,"entry":[true,false,false],"bearings":[90,255,300],"location":[-77.042382,38.909646]}],"driving_side":"right","geometry":"wlnlFnrfuMBK@I@K@I?I?I?I?GAI?ICIAGAICICGCGEGAECCCECCCCECCCGEGEGCECGAKKEGCICICQ?yA","mode":"driving","maneuver":{"exit":3,"bearing_after":111,"bearing_before":84,"location":[-77.043755,38.909076],"modifier":"slight right","type":"roundabout","instruction":"Enter the traffic circle and take the 3rd exit onto P Street Northwest"},"weight":94.4,"duration":69.7,"name":"P Street Northwest","distance":189.9},{"intersections":[{"in":0,"entry":[true],"bearings":[270],"location":[-77.041926,38.909646]}],"driving_side":"right","geometry":"ipnlF`gfuM","mode":"driving","maneuver":{"bearing_after":0,"bearing_before":90,"location":[-77.041926,38.909646],"type":"arrive","instruction":"You have arrived at your destination"},"weight":0,"duration":0,"name":"P Street Northwest","distance":0}],"distance":261.4}],"weight_name":"routability","weight":129.6,"duration":104.4,"distance":261.4}],"waypoints":[{"name":"New Hampshire Avenue Northwest","location":[-77.044347,38.908673]},{"name":"P Street Northwest","location":[-77.041926,38.909646]}],"code":"Ok","uuid":"cjfe60wqh055u4epbgoj7irfc"}
1+
{"routes":[{"geometry":"ejnlFdvfuM}@y@M[E_@JaAGm@Kc@[g@YSa@KGQIe@?yA","legs":[{"summary":"Dupont Circle Northwest, P Street Northwest","weight":122.6,"duration":90.9,"steps":[{"intersections":[{"out":0,"entry":[true],"bearings":[36],"location":[-77.044347,38.908673]},{"out":1,"in":2,"entry":[false,true,false],"bearings":[15,60,210],"location":[-77.044059,38.908982]}],"driving_side":"right","geometry":"ejnlFdvfuM}@y@GKEOCK?KAG","mode":"driving","maneuver":{"bearing_after":36,"bearing_before":0,"location":[-77.044347,38.908673],"type":"depart","instruction":"Head northeast on New Hampshire Avenue Northwest"},"weight":20.8,"duration":16.4,"name":"New Hampshire Avenue Northwest","distance":71.5},{"intersections":[{"out":0,"in":1,"entry":[true,false,false],"bearings":[105,255,300],"location":[-77.043755,38.909076]},{"out":0,"in":2,"entry":[true,true,false],"bearings":[90,150,285],"location":[-77.043518,38.909023]},{"out":0,"in":2,"entry":[true,true,false],"bearings":[90,120,270],"location":[-77.043427,38.909023]},{"out":0,"in":2,"entry":[true,false,false],"bearings":[45,195,225],"location":[-77.042939,38.909165]},{"out":0,"in":2,"entry":[true,true,false,false],"bearings":[30,90,210,255],"location":[-77.042775,38.909307]},{"out":0,"in":2,"entry":[true,false,false,true],"bearings":[15,135,195,345],"location":[-77.04267,38.909501]},{"out":1,"in":2,"entry":[true,true,false],"bearings":[15,75,180],"location":[-77.042655,38.909562]},{"out":0,"in":1,"entry":[true,false,false],"bearings":[90,255,300],"location":[-77.042382,38.909646]}],"driving_side":"right","geometry":"wlnlFnrfuMBKFc@?QCc@CIAGAICICGCGEGAECCCECCCCECCCGEGEGCECGAGAC?GQAICICQ?yA","mode":"driving","maneuver":{"exit":5,"bearing_after":111,"bearing_before":77,"location":[-77.043755,38.909076],"modifier":"slight right","type":"roundabout","instruction":"Enter the traffic circle and take the 5th exit onto P Street Northwest"},"weight":101.8,"duration":74.5,"name":"P Street Northwest","distance":191.8},{"intersections":[{"in":0,"entry":[true],"bearings":[270],"location":[-77.041926,38.909646]}],"driving_side":"right","geometry":"ipnlF`gfuM","mode":"driving","maneuver":{"bearing_after":0,"bearing_before":90,"location":[-77.041926,38.909646],"type":"arrive","instruction":"You have arrived at your destination"},"weight":0,"duration":0,"name":"P Street Northwest","distance":0}],"distance":263.4}],"weight_name":"routability","weight":122.6,"duration":90.9,"distance":263.4}],"waypoints":[{"name":"New Hampshire Avenue Northwest","location":[-77.044347,38.908673]},{"name":"P Street Northwest","location":[-77.041926,38.909646]}],"code":"Ok","uuid":"cjge5fh9l07x84ime4edkubph"}

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

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

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

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

0 commit comments

Comments
 (0)