Skip to content

Fix set origin and destination#383

Closed
Guardiola31337 wants to merge 2 commits into
masterfrom
378_replace_origin_destination
Closed

Fix set origin and destination#383
Guardiola31337 wants to merge 2 commits into
masterfrom
378_replace_origin_destination

Conversation

@Guardiola31337

Copy link
Copy Markdown
Contributor

Fixes #378

Fix setOrigin and setDestination replacing beginning and end positions instead of adding them.

👀 @cammace @zugaldia

@Guardiola31337 Guardiola31337 self-assigned this Mar 8, 2017
@mention-bot

Copy link
Copy Markdown

@Guardiola31337, thanks for your PR! By analyzing the history of the files in this pull request, we identified @cammace, @zugaldia and @ghoshkaj to be potential reviewers.

*/
public static class Builder<T extends Builder> extends MapboxBuilder {

private static final int TWO_COORDINATES = 2;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constants can go in the Constants.java file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cammace I don't like the approach of having this kind of all-constant classes. Constants should be in their pertinent classes, basically because it's where they belong and provide more context. Actually, using an all-constant class approach is a well known antipattern.

assertEquals(response.body().getCode(), DirectionsCriteria.RESPONSE_OK);

assertEquals(200, response.code());
assertEquals("Ok", response.body().getCode());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Guardiola31337 why replacing the constant with its value?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zugaldia it's a technique what I learnt from the book Working Effectively With Unit Tests. I really like the techniques described on it in favor of DAMP (Descriptive And Maintainable Procedures). Mainly because they increase maintainability and readability of tests.
In this concrete case, why I prefer expecting literals?

  • The main advantage of expecting literals is that you only need to focus on the actual value of the assertion, increasing readability and traceability.
    If neither your expected nor actual values are literals you’re forced to determine the value of both when a test fails. Conversely, if your expected value is a literal, only the actual value will need to be traced when a test is failing.
  • Literals will reflect the examples from the business.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Guardiola31337 Thanks for the explanation. While agree with these general goals, I disagree in this particular case. This test really intends to test response.body().getCode().equals(DirectionsCriteria.RESPONSE_OK) which is what the developer would type in their code. The fact that DirectionsCriteria.RESPONSE_OK has the value Ok or OK or something else is secondary in this case. In fact, if the server happened to change its response from Ok to OK and we simply updated the literal here, the test would now pass, but we'd miss updating the value of DirectionsCriteria.RESPONSE_OK.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zugaldia Ok agreed. It's also explanatory using the constant so I leave it as it was 👍

assertEquals(body.getRoutes().size(), 1);
assertEquals(body.getWaypoints().size(), 2);

assertEquals("Ok", body.getCode());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Guardiola31337 same comnent as above.


private static final int TWO_COORDINATES = 2;
private static final int END = 1;
public static final int BEGINNING = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Guardiola31337 why public?

@Guardiola31337 Guardiola31337 Mar 9, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right 😅 I missed that.

}
return new MapboxDirections(this);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a second thought, I think we should fix this in a simpler way.

  • setOrigin(Position origin) should set a private Position origin value.
  • setDestination(Position destination) should set a private Position destination value.
  • setCoordinates(List<Position> coordinates) should set a private List<Position> coordinates value.

Then, at build time we check if both (origin, destination) and coordinates have been set. If the developer has mixed them we through a ServicesException.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zugaldia Since I don't know in depth the SDK, does it mean that coordinates would be a list of coordinates in between the origin and the destination? At the moment, origin is the first element of the list and destination is the last one. When you try to add a new origin, if you already had more than two coordinates, the new origin is prepended to the coordinates list. Similarly, when you try to add a new destination, if you already had more than two coordinates, the new destination is appended. But, if you called setCoordinates the whole coordinates is reset. Is that the behavior that we are looking for?
cc/ @cammace

@cammace

cammace commented Mar 30, 2017

Copy link
Copy Markdown

closing this in favor of #420.

@cammace cammace closed this Mar 30, 2017
@cammace cammace deleted the 378_replace_origin_destination branch March 30, 2017 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants