Skip to content
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

Use BannerText roundabout degrees + Banner and Voice Milestone Tests #854

Merged
merged 8 commits into from
Apr 19, 2018

Conversation

danesfeder
Copy link
Contributor

@danesfeder danesfeder commented Apr 11, 2018

The directions API now provides a float degrees in BannerText indicating the where you will be exiting the roundabout. This PR takes this value from the API and uses it to draw the roundabout in the ManeuverView dynamically.

This is also a good opportunity to clean up some of the model work. Currently in a bit of a 🍝 state. Going to exercise the boyscout rule and clean it up a bit in this PR.

TODO:

  • VoiceInstructionsMilestoneTest
  • BannerInstructionsMilestoneTest

@danesfeder danesfeder added feature New feature request. navigation-ui labels Apr 11, 2018
@danesfeder danesfeder added this to the v0.13.0 milestone Apr 11, 2018
@danesfeder danesfeder self-assigned this Apr 11, 2018
@danesfeder danesfeder force-pushed the dan-use-roundabout-degrees branch 2 times, most recently from fc70b86 to 77cb3ed Compare April 16, 2018 17:50
@danesfeder
Copy link
Contributor Author

@devotaaabel @Guardiola31337 tests added, this PR is good to go for 👀

@danesfeder danesfeder changed the title [WIP] Use BannerText roundabout degrees to draw roundabout maneuver Use BannerText roundabout degrees + Banner and Voice Milestone Tests Apr 17, 2018
@Danny-James
Copy link

@danesfeder Do we know when this will be complete? I'm just waiting on the stable v13 👍

Copy link
Contributor

@Guardiola31337 Guardiola31337 left a comment

Choose a reason for hiding this comment

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

Nice test coverage @danesfeder ❤️ it!

This is looking great. A few comments / cleanup.

public class InstructionModel {

private BannerText primaryBannerText;
private BannerText secondaryBannerText;
private BannerText thenBannerText;
private Float roundaboutAngle = null;
private InstructionStepResources stepResources;
private RouteProgress progress;
private Locale locale;
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor thing annotations normally are on top of the definition like 👇

@NavigationUnitType.UnitType
private int unitType;

👇

@@ -135,7 +135,7 @@ protected void onDraw(Canvas canvas) {
case STEP_MANEUVER_TYPE_ROUNDABOUT:
Copy link
Contributor

Choose a reason for hiding this comment

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

What about decomposing the switch somehow? It's too long... There's even another switch in one of the branches 😅


import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

@RunWith(RobolectricTestRunner.class)
@Config(constants = com.mapbox.services.android.navigation.BuildConfig.class, manifest = Config.DEFAULT_MANIFEST_NAME)
public class NavigationViewEventDispatcherTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

In general, we should avoid inline setup 👀 https://speakerdeck.com/guardiola31337/elegant-unit-testing-mobilization-2016?slide=65
Could you extract this block of code into private "factory" methods and use them only in the tests that actually need it/across the rest of the tests?
IMO, it reflects better what's going on in the test and you don't break the triple A "rule".

return validInstructions(stepBannerInstructions)
&& validInstructions(instructions)
&& instructions.get(0).equals(stepBannerInstructions.get(0));
private boolean isFirstInstruction(BannerInstructions instructions) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not inlining it and use an explaining variable as with the rest of the booleans in shouldBeShown?

@@ -64,7 +55,10 @@ public String buildInstruction(RouteProgress routeProgress) {
* @since 0.8.0
*/
public String getSsmlAnnouncement() {
return ssmlAnnouncement;
if (instructions == null) {
return "";
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT magic number

public void onNullMilestoneInstructions_emptyInstructionsAreReturned() throws Exception {
VoiceInstructionMilestone milestone = buildVoiceInstructionMilestone();

assertEquals("", milestone.getAnnouncement());
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally is preferable having only 1 assertion per test 👀 https://speakerdeck.com/guardiola31337/elegant-unit-testing-mobilization-2016?slide=57
What's the value of adding assertEquals("", milestone.getSsmlAnnouncement()); if you're already testing it in onNullMilestoneInstructions_emptySsmlInstructionsAreReturned?

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNotSame;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;

public class RouteLegProgressTest extends BaseTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

👀 asserts inside a for loop are weird. What are we trying to test in fractionTraveled_equalsCorrectValueAtIntervals test?

double durationRemaining = route.duration();
double progressDurationRemaining = beginningRouteProgress.durationRemaining();

assertEquals(durationRemaining, progressDurationRemaining, BaseTest.DELTA);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

👀 asserts inside a for loop are weird. What are we trying to test in fractionTraveled_equalsCorrectValueAtIntervals and multiLeg_getFractionTraveled_equalsCorrectValueAtIntervals tests?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -242,19 +242,23 @@ public void fractionTraveled_equalsOneAtEndOfStep() throws Exception {
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

👀 asserts inside a for loop are weird.

currentStep, stepDistanceRemaining
);

assertEquals(null, currentBannerInstructions);
Copy link
Contributor

Choose a reason for hiding this comment

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

We could use assertNull instead.

The same thing happens with another tests included in RouteUtilsTest 👇

Copy link
Contributor

@Guardiola31337 Guardiola31337 left a comment

Choose a reason for hiding this comment

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

There are still some comments not addressed but this is in really good shape to 🚢

Great job @danesfeder

Loved how you completely removed that switch in ManeuverView 🙇

@danesfeder danesfeder merged commit f43d662 into master Apr 19, 2018
@danesfeder danesfeder deleted the dan-use-roundabout-degrees branch April 19, 2018 19:12
@danesfeder danesfeder mentioned this pull request May 3, 2018
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants