Skip to content

Commit be91fa6

Browse files
authored
Move Incidents from LegStep to RouteLeg (#1207)
* move Incidents from LegStep to RouteLeg * test Incidents parsing with MockWebServer
1 parent 112d2f2 commit be91fa6

File tree

5 files changed

+70
-20
lines changed

5 files changed

+70
-20
lines changed

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,6 @@ public static Builder builder() {
5959
@SerializedName("duration_typical")
6060
public abstract Double durationTypical();
6161

62-
/**
63-
* A list of incidents that occur on the route.
64-
*
65-
* @return a list of {@link Incident}
66-
*/
67-
@Nullable
68-
public abstract List<Incident> incidents();
69-
7062
/**
7163
* Gives the geometry of the leg step.
7264
*
@@ -296,14 +288,6 @@ public abstract static class Builder {
296288
*/
297289
public abstract Builder durationTypical(@Nullable Double durationTypical);
298290

299-
/**
300-
* A list of incidents that occur on the route.
301-
*
302-
* @param incidents a list of {@link Incident}
303-
* @return this builder for chaining options together
304-
*/
305-
public abstract Builder incidents(@Nullable List<Incident> incidents);
306-
307291
/**
308292
* Gives the geometry of the leg step.
309293
*

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ public static Builder builder() {
8585
@Nullable
8686
public abstract List<LegStep> steps();
8787

88+
/**
89+
* A list of incidents that occur on this leg.
90+
*
91+
* @return a list of {@link Incident}
92+
*/
93+
@Nullable
94+
public abstract List<Incident> incidents();
95+
8896
/**
8997
* A {@link LegAnnotation} that contains additional details about each line segment along the
9098
* route geometry. If you'd like to receiving this, you must request it inside your Directions
@@ -199,6 +207,14 @@ public abstract static class Builder {
199207
*/
200208
public abstract Builder steps(@Nullable List<LegStep> steps);
201209

210+
/**
211+
* A list of incidents that occur on this leg.
212+
*
213+
* @param incidents a list of {@link Incident}
214+
* @return this builder for chaining options together
215+
*/
216+
public abstract Builder incidents(@Nullable List<Incident> incidents);
217+
202218
/**
203219
* A {@link LegAnnotation} that contains additional details about each line segment along the
204220
* route geometry. If you'd like to receiving this, you must request it inside your Directions

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public void testToFromJson1() {
7373

7474
List<LegStep> steps = new ArrayList<>();
7575

76+
List<Incident> incidents = new ArrayList<>();
77+
7678
LegAnnotation annotation = LegAnnotation.builder()
7779
.congestion(new ArrayList<String>())
7880
.distance(distanceList)
@@ -84,9 +86,9 @@ public void testToFromJson1() {
8486
RouteLeg routeLeg = RouteLeg.builder()
8587
.annotation(annotation)
8688
.distance(53.4)
87-
//.weight(14.3)
8889
.duration(14.3)
8990
.steps(steps)
91+
.incidents(incidents)
9092
.summary("")
9193
.build();
9294

@@ -97,21 +99,26 @@ public void testToFromJson1() {
9799
}
98100

99101
@Test
100-
public void testAdmins() {
102+
public void testFromJson() {
101103
String routeLegJsonString = "{"
102104
+ "\"distance\": 53.4,"
103105
+ "\"duration\": 14.3,"
104106
+ "\"summary\": \"route summary\","
105-
+ "\"admins\": [{ \"iso_3166_1_alpha3\": \"USA\", \"iso_3166_1\": \"US\" }]"
107+
+ "\"admins\": [{ \"iso_3166_1_alpha3\": \"USA\", \"iso_3166_1\": \"US\" }],"
108+
+ "\"incidents\": [{ \"id\": \"15985415522454461962\" }]"
106109
+ "}";
107110
List<Admin> admins = new ArrayList<>();
108111
admins.add(Admin.builder().countryCode("US").countryCodeAlpha3("USA").build());
109112

113+
List<Incident> incidents = new ArrayList<>();
114+
incidents.add(Incident.builder().id("15985415522454461962").build());
115+
110116
RouteLeg routeLeg = RouteLeg.builder()
111117
.distance(53.4)
112118
.duration(14.3)
113119
.summary("route summary")
114120
.admins(admins)
121+
.incidents(incidents)
115122
.build();
116123

117124
RouteLeg routeLegFromJson = RouteLeg.fromJson(routeLegJsonString);

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.mapbox.api.directions.v5.models.BannerInstructions;
77
import com.mapbox.api.directions.v5.models.DirectionsResponse;
88
import com.mapbox.api.directions.v5.models.DirectionsRoute;
9+
import com.mapbox.api.directions.v5.models.Incident;
910
import com.mapbox.api.directions.v5.models.LegAnnotation;
1011
import com.mapbox.api.directions.v5.models.RouteOptions;
1112
import com.mapbox.api.directions.v5.utils.ParseUtils;
@@ -1344,6 +1345,48 @@ public void getIsUsed() {
13441345
assertEquals("GET", call.request().method());
13451346
}
13461347

1348+
@Test
1349+
public void withIncidents() throws Exception {
1350+
MapboxDirections mapboxDirections = MapboxDirections.builder()
1351+
.baseUrl(mockUrl.toString())
1352+
.geometries(GEOMETRY_POLYLINE)
1353+
.accessToken(ACCESS_TOKEN)
1354+
.origin(Point.fromLngLat(1.0, 1.0))
1355+
.destination(Point.fromLngLat(2.0, 2.0))
1356+
.build();
1357+
1358+
assertNotNull(mapboxDirections);
1359+
1360+
Response<DirectionsResponse> response = mapboxDirections.executeCall();
1361+
assertEquals(200, response.code());
1362+
assertEquals("Ok", response.body().code());
1363+
assertEquals(1, response.body().routes().size());
1364+
1365+
List<Incident> incidents = response.body().routes().get(0).legs().get(0).incidents();
1366+
assertEquals(1, incidents.size());
1367+
1368+
List<Integer> alertcCodes = new ArrayList<>();
1369+
alertcCodes.add(501);
1370+
alertcCodes.add(803);
1371+
1372+
Incident incident = incidents.get(0);
1373+
assertEquals("15985415522454461962", incident.id());
1374+
assertEquals("construction", incident.type());
1375+
assertEquals(true, incident.closed());
1376+
assertEquals(55, incident.congestion().value());
1377+
assertEquals("Zwischen Eching", incident.description());
1378+
assertEquals("Zwischen Eching und Oberpfaffenhofen", incident.longDescription());
1379+
assertEquals("minor", incident.impact());
1380+
assertEquals("CONSTRUCTION", incident.subType());
1381+
assertEquals("construction description", incident.subTypeDescription());
1382+
assertEquals(alertcCodes, incident.alertcCodes());
1383+
assertEquals(805, (int) incident.geometryIndexStart());
1384+
assertEquals(896, (int) incident.geometryIndexEnd());
1385+
assertEquals("2020-10-08T11:34:14Z", incident.creationTime());
1386+
assertEquals("2020-10-06T12:52:02Z", incident.startTime());
1387+
assertEquals("2020-11-27T16:00:00Z", incident.endTime());
1388+
}
1389+
13471390
private void addWaypoints(MapboxDirections.Builder builder, int number) {
13481391
for (int i = 0; i < number; i++) {
13491392
builder.addWaypoint(Point.fromLngLat(getRandomLng(), getRandomLat()));

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)