-
Notifications
You must be signed in to change notification settings - Fork 319
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
Check for null camera engine before returning from MapboxNavigation #866
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great you took the opportunity to refactor MapboxNavigationTest
🙇
Well done @danesfeder ❤️ it!
A few comments / cleanup not blocking the PR.
public void before() throws Exception { | ||
navigation = new MapboxNavigation(mock(Context.class), ACCESS_TOKEN, mock(NavigationTelemetry.class), | ||
mock(LocationEngine.class)); | ||
assertNotNull("should not be null", navigation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO Adding error messages to tests is kind of confusing because when you 👀 a test using JUnit you think always as expected
and actual
values being the first parameters and in this case "should not be null"
is not the expected value is actually the error message shown when the test fails (which is not giving any extra value because if it fails you're going to get ❌)
I'd rather working on improving the name of the test if needed in these cases.
MapboxNavigation navigationWithOptions = new MapboxNavigation(mock(Context.class), | ||
ACCESS_TOKEN, options, mock(NavigationTelemetry.class), mock(LocationEngine.class)); | ||
MapboxNavigation navigationWithOptions = buildMapboxNavigationWithOptions(options); | ||
|
||
assertNotNull("should not be null", navigationWithOptions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here ☝️
assertNotNull("should not be null", navigationWithOptions); | ||
} | ||
|
||
@Test | ||
public void voiceMilestone_onInitializationDoesGetAdded() throws Exception { | ||
MapboxNavigation navigation = buildMapboxNavigation(); | ||
|
||
assertTrue(navigation.getMilestones().get(0).getIdentifier() == VOICE_INSTRUCTION_MILESTONE_ID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally is good to structure the tests following the triple A 👀 https://speakerdeck.com/guardiola31337/elegant-unit-testing-mobilization-2016?slide=40 http://wiki.c2.com/?ArrangeActAssert
Here we're including the Act
inside the Assert
. It'd be great to have them separated and take advantage of giving great names to variables so it's easy to understand what's going on.
This applies to other tests included in MapboxNavigationTest
.
} | ||
|
||
@Test | ||
public void addMilestone_milestoneDidGetAdded() throws Exception { | ||
MapboxNavigation navigation = buildMapboxNavigation(); | ||
|
||
Milestone milestone = new StepMilestone.Builder().build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO These two lines of code belongs to the Arrange
part.
This applies to other tests included in MapboxNavigationTest
.
assertEquals(0, navigationWithOptions.getMilestones().size()); | ||
} | ||
|
||
@Test | ||
public void removeMilestone_correctMilestoneWithIdentifierGetsRemoved() throws Exception { | ||
MapboxNavigationOptions options = MapboxNavigationOptions.builder().defaultMilestonesEnabled(false).build(); | ||
MapboxNavigation navigationWithOptions = new MapboxNavigation(mock(Context.class), | ||
ACCESS_TOKEN, options, mock(NavigationTelemetry.class), mock(LocationEngine.class)); | ||
MapboxNavigation navigationWithOptions = buildMapboxNavigationWithOptions(options); | ||
Milestone milestone = new StepMilestone.Builder().setIdentifier(5678).build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using a well-named variable for 5678
reflecting what's useful for here? Maybe theMilestone
?
navigationWithOptions.addMilestone(new StepMilestone.Builder().build()); | ||
assertEquals(1, navigationWithOptions.getMilestones().size()); | ||
|
||
navigationWithOptions.removeMilestone(5678); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here ☝️ but reflecting that the milestone was not found.
assertEquals(1, navigationWithOptions.getMilestones().size()); | ||
} | ||
|
||
@Test | ||
public void getLocationEngine_returnsCorrectLocationEngine() throws Exception { | ||
MapboxNavigation navigation = buildMapboxNavigation(); | ||
LocationEngine locationEngine = mock(LocationEngine.class); | ||
LocationEngine locationEngine2 = mock(LocationEngine.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid adding "numbers" to variable names. Could we refactor-rename adding more context so it'll be easier to read and understand what's going on in the test?
40e9e12
to
602f589
Compare
@Guardiola31337 addressed, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danesfeder Some minor comments to take into account in the future when working again with MapboxNavigationTest
.
|
||
int identifier = navigation.getMilestones().get(0).getIdentifier(); | ||
|
||
assertEquals(identifier, VOICE_INSTRUCTION_MILESTONE_ID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be the other way around, "expected" value 👉 VOICE_INSTRUCTION_MILESTONE_ID
which would be better represented using the literal value instead of using the constant (👀 Expect Literals), "actual" value 👉 identifier
.
The same thing happens in bannerMilestone_onInitializationDoesGetAdded
test 👇
MapboxNavigation navigationWithOptions = new MapboxNavigation(mock(Context.class), | ||
ACCESS_TOKEN, options, mock(NavigationTelemetry.class), mock(LocationEngine.class)); | ||
MapboxNavigation navigationWithOptions = buildMapboxNavigationWithOptions(options); | ||
|
||
assertEquals(0, navigationWithOptions.getMilestones().size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀 #866 (comment)
navigationWithOptions.getMilestones().size()
is the Act
here.
This applies to other tests included in MapboxNavigationTest
👇
MapboxNavigation navigationWithOptions = new MapboxNavigation(mock(Context.class), | ||
ACCESS_TOKEN, options, mock(NavigationTelemetry.class), mock(LocationEngine.class)); | ||
MapboxNavigation navigationWithOptions = buildMapboxNavigationWithOptions(options); | ||
|
||
Milestone milestone = new StepMilestone.Builder().build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Milestone milestone = new StepMilestone.Builder().build();
should be in the Arrange
part.
MapboxNavigation navigationWithOptions = new MapboxNavigation(mock(Context.class), | ||
ACCESS_TOKEN, options, mock(NavigationTelemetry.class), mock(LocationEngine.class)); | ||
MapboxNavigation navigationWithOptions = buildMapboxNavigationWithOptions(options); | ||
|
||
Milestone milestone = new StepMilestone.Builder().build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Milestone milestone = new StepMilestone.Builder().build();
navigationWithOptions.addMilestone(milestone);
Should be in the Arrange
part.
MapboxNavigation navigationWithOptions = new MapboxNavigation(mock(Context.class), | ||
ACCESS_TOKEN, options, mock(NavigationTelemetry.class), mock(LocationEngine.class)); | ||
MapboxNavigation navigationWithOptions = buildMapboxNavigationWithOptions(options); | ||
|
||
Milestone milestone = new StepMilestone.Builder().build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Milestone milestone = new StepMilestone.Builder().build();
navigationWithOptions.addMilestone(new StepMilestone.Builder().build());
Should be in the Arrange
part.
We could take advantage of the naming here to understand clearer what's going on. Like naming new StepMilestone.Builder().build()
as inexistentMilestone
for example.
ACCESS_TOKEN, options, mock(NavigationTelemetry.class), mock(LocationEngine.class)); | ||
Milestone milestone = new StepMilestone.Builder().setIdentifier(5678).build(); | ||
MapboxNavigation navigationWithOptions = buildMapboxNavigationWithOptions(options); | ||
int removedMilestoneIdentifier = 5678; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO removedMilestoneIdentifier
is not a good name here 👀 #866 (comment)
LocationEngine locationEngine = mock(LocationEngine.class); | ||
LocationEngine locationEngine2 = mock(LocationEngine.class); | ||
LocationEngine locationEngineInstanceNotUsed = mock(LocationEngine.class); | ||
|
||
navigation.setLocationEngine(locationEngine); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be in the Arrange
part 👀 getLocationEngine_returnsCorrectLocationEngine
is telling us what's the Act
here getLocationEngine
.
NavigationEventListener navigationEventListener = mock(NavigationEventListener.class); | ||
|
||
navigation.addNavigationEventListener(navigationEventListener); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here ☝️
This applies to other tests included in MapboxNavigationTest
👇
navigation.setSnapEngine(snap); | ||
|
||
assertTrue(!(navigation.getSnapEngine() instanceof SnapToRoute)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using assertFalse
instead?
navigation.setOffRouteEngine(offRoute); | ||
|
||
assertTrue(!(navigation.getOffRouteEngine() instanceof OffRouteDetector)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here ☝️
Closes #842
Always return default
SimpleCamera
engine if one hasn't already been initialized.Took a moment to clean up
MapboxNavigationTest
as well.