Skip to content

Commit 2fa950d

Browse files
authored
Adjust maxspeed annotation (#777)
* Adjust maxspeed annotation * Update test fixtures and add test for maxspeed
1 parent e118fe0 commit 2fa950d

13 files changed

Lines changed: 61 additions & 23 deletions

Makefile

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

111+
# Directions: route with maxspeed
112+
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)" \
113+
-o services-directions/src/test/resources/directions_v5_max_speed_annotation.json
114+
111115
mapmatching-fixtures:
112116
curl "https://api.mapbox.com/matching/v5/mapbox/driving/$(MAP_MATCHING_COORDINATES)?geometries=polyline&language=sv&steps=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
113117
-o services-matching/src/test/resources/map_matching_v5_polyline.json

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static Builder builder() {
6868
* @since 3.0.0
6969
*/
7070
@Nullable
71-
public abstract List<MaxSpeed> maxSpeed();
71+
public abstract List<MaxSpeed> maxspeed();
7272

7373
/**
7474
* The congestion between each pair of coordinates.
@@ -134,11 +134,11 @@ public abstract static class Builder {
134134
* Maxspeed is only available for the `mapbox/driving` and `mapbox/driving-traffic`
135135
* profiles, other profiles will return `unknown`s only.
136136
*
137-
* @param maxSpeed list of speeds between each pair of coordinates
137+
* @param maxspeed list of speeds between each pair of coordinates
138138
* @return this builder for chaining options together
139139
* @since 3.0.0
140140
*/
141-
public abstract Builder maxSpeed(@Nullable List<MaxSpeed> maxSpeed);
141+
public abstract Builder maxspeed(@Nullable List<MaxSpeed> maxspeed);
142142

143143
/**
144144
* The congestion between each pair of coordinates.

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

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
11
package com.mapbox.api.directions.v5;
22

3-
import static org.hamcrest.CoreMatchers.containsString;
4-
import static org.hamcrest.junit.MatcherAssert.assertThat;
5-
import static org.junit.Assert.assertEquals;
6-
import static org.junit.Assert.assertTrue;
7-
3+
import com.google.gson.Gson;
4+
import com.google.gson.GsonBuilder;
85
import com.mapbox.api.directions.v5.models.DirectionsResponse;
6+
import com.mapbox.api.directions.v5.models.DirectionsRoute;
7+
import com.mapbox.api.directions.v5.models.LegAnnotation;
98
import com.mapbox.core.TestUtils;
109
import com.mapbox.core.exceptions.ServicesException;
1110
import com.mapbox.geojson.Point;
12-
import okhttp3.HttpUrl;
13-
import okhttp3.mockwebserver.MockResponse;
14-
import okhttp3.mockwebserver.MockWebServer;
15-
import okhttp3.mockwebserver.RecordedRequest;
11+
1612
import org.junit.After;
1713
import org.junit.Assert;
1814
import org.junit.Before;
1915
import org.junit.Rule;
2016
import org.junit.Test;
2117
import org.junit.rules.ExpectedException;
22-
import retrofit2.Response;
2318

2419
import java.io.IOException;
2520
import java.util.ArrayList;
2621
import java.util.List;
2722
import java.util.Locale;
2823

29-
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
24+
import okhttp3.HttpUrl;
25+
import okhttp3.mockwebserver.MockResponse;
26+
import okhttp3.mockwebserver.MockWebServer;
27+
import okhttp3.mockwebserver.RecordedRequest;
28+
import retrofit2.Response;
29+
30+
import static org.hamcrest.CoreMatchers.containsString;
31+
import static org.hamcrest.junit.MatcherAssert.assertThat;
32+
import static org.junit.Assert.assertEquals;
33+
import static org.junit.Assert.assertNotNull;
34+
import static org.junit.Assert.assertTrue;
3035

3136
public class MapboxDirectionsTest extends TestUtils {
3237

@@ -36,6 +41,7 @@ public class MapboxDirectionsTest extends TestUtils {
3641
private static final String DIRECTIONS_ROTARY_FIXTURE = "directions_v5_fixtures_rotary.json";
3742
private static final String DIRECTIONS_V5_ANNOTATIONS_FIXTURE = "directions_annotations_v5.json";
3843
private static final String DIRECTIONS_V5_NO_ROUTE = "directions_v5_no_route.json";
44+
private static final String DIRECTIONS_V5_MAX_SPEED_ANNOTATION = "directions_v5_max_speed_annotation.json";
3945

4046
private MockWebServer server;
4147
private HttpUrl mockUrl;
@@ -468,4 +474,31 @@ public void setCoordinates_localeShouldNotMatter() {
468474
assertThat(directions.cloneCall().request().url().toString(),
469475
containsString("1.234,2.345;13.493,9.958;5.29838,4.42189"));
470476
}
477+
478+
@Test
479+
public void maxSpeedAnnotation_doesGetFormattedInUrlCorrectly() {
480+
Locale.setDefault(Locale.GERMANY);
481+
MapboxDirections directions = MapboxDirections.builder()
482+
.accessToken(ACCESS_TOKEN)
483+
.origin(Point.fromLngLat(1.234,2.345))
484+
.addWaypoint(Point.fromLngLat(13.493,9.958))
485+
.destination(Point.fromLngLat(5.29838,4.42189))
486+
.annotations(DirectionsCriteria.ANNOTATION_MAXSPEED)
487+
.build();
488+
489+
assertThat(directions.cloneCall().request().url().toString(),
490+
containsString("annotations=maxspeed"));
491+
}
492+
493+
@Test
494+
public void maxSpeedAnnotation_doesGetCreatedInResponse() throws IOException {
495+
Gson gson = new GsonBuilder()
496+
.registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
497+
String body = loadJsonFixture(DIRECTIONS_V5_MAX_SPEED_ANNOTATION);
498+
DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);
499+
DirectionsRoute maxSpeedRoute = response.routes().get(0);
500+
LegAnnotation maxSpeedAnnotation = maxSpeedRoute.legs().get(0).annotation();
501+
502+
assertNotNull(maxSpeedAnnotation.maxspeed());
503+
}
471504
}

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":74.9,"duration":64.1,"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":50,"duration":39.3,"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":56.5,"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.9,"duration":24.8,"name":"Mariani Avenue","distance":114.5,"voiceInstructions":[{"distanceAlongGeometry":13.9,"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":74.9,"duration":64.1,"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":"cjeahg7sj3of747lgc2f0p3pp"}
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"}

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":"Dupont Circle NW, P Street Northwest","weight":107.4,"duration":93.3,"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":22.9,"duration":18.9,"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":84.5,"duration":74.4,"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":107.4,"duration":93.3,"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":"cjatu1k2o05ph5bp8eg0qhaoy"}
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"}

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

Lines changed: 1 addition & 0 deletions
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)