-
Notifications
You must be signed in to change notification settings - Fork 117
Bearing formatting fix #1121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bearing formatting fix #1121
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |||
| import com.mapbox.api.directions.v5.models.DirectionsRoute; | ||||
| import com.mapbox.api.directions.v5.models.LegAnnotation; | ||||
| import com.mapbox.api.directions.v5.models.RouteOptions; | ||||
| import com.mapbox.api.directions.v5.utils.ParseUtils; | ||||
| import com.mapbox.core.TestUtils; | ||||
| import com.mapbox.core.exceptions.ServicesException; | ||||
| import com.mapbox.geojson.Point; | ||||
|
|
@@ -470,6 +471,54 @@ public void addBearing_doesGetFormattedInUrlCorrectly() throws Exception { | |||
| directions.cloneCall().request().url().queryParameter("bearings")); | ||||
| } | ||||
|
|
||||
| @Test | ||||
| public void addNullBearings_doesGetFormattedInUrlCorrectly() throws Exception { | ||||
| List<Double> bearing1 = new ArrayList<>(); | ||||
| bearing1.add(45d); | ||||
| bearing1.add(90d); | ||||
|
|
||||
| List<Double> bearing2 = new ArrayList<>(); | ||||
| bearing2.add(2d); | ||||
| bearing2.add(90d); | ||||
|
|
||||
| List<List<Double>> bearings = new ArrayList<>(); | ||||
| bearings.add(null); | ||||
| bearings.add(null); | ||||
| bearings.add(bearing1); | ||||
| bearings.add(bearing2); | ||||
| bearings.add(null); | ||||
|
|
||||
| MapboxDirections directions = MapboxDirections.builder() | ||||
| .destination(Point.fromLngLat(13.4930, 9.958)) | ||||
| .origin(Point.fromLngLat(1.234, 2.345)) | ||||
| .bearings(bearings) | ||||
| .accessToken(ACCESS_TOKEN) | ||||
| .build(); | ||||
| assertEquals(";;45,90;2,90;", | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debugging this PR I found that @Test
public void checksParseToListOfListOfDoublesEmptyTrailing() {
List<List<Double>> bearings = ParseUtils.parseToListOfListOfDoubles(";;45,90;2,90;");
assertEquals(5, bearings.size());
}It should return a list of 5 elements and it's returning a list of 4 because of not splitting with trailing empty strings Line 141 in 123e7cd
After changing to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tested it with @kmadsen , @Guardiola31337 you are right,
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @korshaknn is
/cc @danpaz
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, looks like we commented at the same time @korshaknn :) Thanks for verifying!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @LukasPaczos |
||||
| directions.cloneCall().request().url().queryParameter("bearings")); | ||||
| } | ||||
|
|
||||
| @Test | ||||
| public void checksParseToListOfListOfDoublesEmptyTrailing() { | ||||
| List<List<Double>> bearings = ParseUtils.parseToListOfListOfDoubles(";;45,90;2,90;"); | ||||
|
|
||||
| assertEquals(5, bearings.size()); | ||||
|
|
||||
| List<Double> bearing1 = new ArrayList<>(); | ||||
| bearing1.add(45d); | ||||
| bearing1.add(90d); | ||||
|
|
||||
| List<Double> bearing2 = new ArrayList<>(); | ||||
| bearing2.add(2d); | ||||
| bearing2.add(90d); | ||||
|
|
||||
| assertEquals(null, bearings.get(0)); | ||||
| assertEquals(null, bearings.get(1)); | ||||
| assertEquals(bearing1, bearings.get(2)); | ||||
| assertEquals(bearing2, bearings.get(3)); | ||||
| assertEquals(null, bearings.get(4)); | ||||
| } | ||||
|
|
||||
| @Test | ||||
| public void bearing_doesGetFormattedInUrlCorrectly() throws Exception { | ||||
| List<List<Double>> bearings = new ArrayList<>(); | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,8 +25,11 @@ | |
| abstract class BaseCoordinatesTypeAdapter<T> extends TypeAdapter<T> { | ||
|
|
||
|
|
||
| protected void writePoint(JsonWriter out, Point value) throws IOException { | ||
| writePointList(out, value.coordinates()); | ||
| protected void writePoint(JsonWriter out, Point point) throws IOException { | ||
| if (point == null) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are now choosing to ignore nulls, while we should actually be able to support them when serializing and deserializing
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @LukasPaczos what logic should
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's what we'd need to refactor. Could we use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this because before
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Guardiola31337 @LukasPaczos I think it's only because of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @korshaknn could we add some tests in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's right @korshaknn, but we still need to serialize and deserialize this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @LukasPaczos how that
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Probably
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty string sounds correct. |
||
| return; | ||
| } | ||
| writePointList(out, point.coordinates()); | ||
| } | ||
|
|
||
| protected Point readPoint(JsonReader in) throws IOException { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.