Skip to content

Commit ee1b13f

Browse files
author
Guardiola31337
committed
opt-in mocking of final classes/methods and fix voice instruction milestone tests
1 parent f2cfe93 commit ee1b13f

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

libandroid-navigation/src/test/java/com/mapbox/services/android/navigation/v5/milestone/VoiceInstructionMilestoneTest.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package com.mapbox.services.android.navigation.v5.milestone;
22

33
import com.mapbox.api.directions.v5.models.DirectionsRoute;
4+
import com.mapbox.navigator.VoiceInstruction;
45
import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress;
56

67
import org.junit.Test;
78

89
import static junit.framework.Assert.assertEquals;
910
import static junit.framework.Assert.assertFalse;
1011
import static junit.framework.Assert.assertNotNull;
12+
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
1113
import static org.mockito.Mockito.mock;
1214
import static org.mockito.Mockito.when;
1315

@@ -23,26 +25,25 @@ public void sanity() {
2325
@Test
2426
public void onSameInstructionOccurring_milestoneDoesNotTriggerTwice() {
2527
RouteProgress firstProgress = mock(RouteProgress.class);
26-
when(firstProgress.currentAnnouncement()).thenReturn("instruction");
28+
VoiceInstruction voiceInstruction = mock(VoiceInstruction.class);
29+
when(firstProgress.voiceInstruction()).thenReturn(voiceInstruction, null);
30+
when(voiceInstruction.getAnnouncement()).thenReturn("instruction");
2731
when(firstProgress.directionsRoute()).thenReturn(mock(DirectionsRoute.class));
28-
RouteProgress secondProgress = mock(RouteProgress.class);
29-
when(secondProgress.directionsRoute()).thenReturn(mock(DirectionsRoute.class));
30-
when(secondProgress.currentAnnouncement()).thenReturn("instruction");
3132
VoiceInstructionMilestone milestone = buildVoiceInstructionMilestone();
3233

3334
milestone.isOccurring(firstProgress, firstProgress);
34-
boolean shouldNotBeOccurring = milestone.isOccurring(firstProgress, secondProgress);
35+
boolean shouldNotBeOccurring = milestone.isOccurring(firstProgress, firstProgress);
3536

3637
assertFalse(shouldNotBeOccurring);
3738
}
3839

3940
@Test
4041
public void onOccurringMilestone_voiceSsmlInstructionsAreReturned() {
41-
RouteProgress routeProgress = mock(RouteProgress.class);
42+
RouteProgress routeProgress = mock(RouteProgress.class, RETURNS_DEEP_STUBS);
4243
when(routeProgress.directionsRoute()).thenReturn(mock(DirectionsRoute.class));
43-
when(routeProgress.currentAnnouncement()).thenReturn("current announcement");
44+
when(routeProgress.voiceInstruction().getAnnouncement()).thenReturn("current announcement");
4445
String currentSsmlAnnouncement = "current SSML announcement";
45-
when(routeProgress.currentSsmlAnnouncement()).thenReturn(currentSsmlAnnouncement);
46+
when(routeProgress.voiceInstruction().getSsmlAnnouncement()).thenReturn(currentSsmlAnnouncement);
4647
VoiceInstructionMilestone milestone = buildVoiceInstructionMilestone();
4748

4849
milestone.isOccurring(routeProgress, routeProgress);
@@ -52,12 +53,12 @@ public void onOccurringMilestone_voiceSsmlInstructionsAreReturned() {
5253

5354
@Test
5455
public void onOccurringMilestone_voiceInstructionsAreReturned() {
55-
RouteProgress routeProgress = mock(RouteProgress.class);
56+
RouteProgress routeProgress = mock(RouteProgress.class, RETURNS_DEEP_STUBS);
5657
when(routeProgress.directionsRoute()).thenReturn(mock(DirectionsRoute.class));
5758
String currentAnnouncement = "current announcement";
58-
when(routeProgress.currentAnnouncement()).thenReturn(currentAnnouncement);
59+
when(routeProgress.voiceInstruction().getAnnouncement()).thenReturn(currentAnnouncement);
5960
String currentSsmlAnnouncement = "current SSML announcement";
60-
when(routeProgress.currentSsmlAnnouncement()).thenReturn(currentSsmlAnnouncement);
61+
when(routeProgress.voiceInstruction().getSsmlAnnouncement()).thenReturn(currentSsmlAnnouncement);
6162
VoiceInstructionMilestone milestone = buildVoiceInstructionMilestone();
6263

6364
milestone.isOccurring(routeProgress, routeProgress);
@@ -67,12 +68,12 @@ public void onOccurringMilestone_voiceInstructionsAreReturned() {
6768

6869
@Test
6970
public void onOccurringMilestone_instructionsAreReturned() {
70-
RouteProgress routeProgress = mock(RouteProgress.class);
71+
RouteProgress routeProgress = mock(RouteProgress.class, RETURNS_DEEP_STUBS);
7172
when(routeProgress.directionsRoute()).thenReturn(mock(DirectionsRoute.class));
7273
String currentAnnouncement = "current announcement";
73-
when(routeProgress.currentAnnouncement()).thenReturn(currentAnnouncement);
74+
when(routeProgress.voiceInstruction().getAnnouncement()).thenReturn(currentAnnouncement);
7475
String currentSsmlAnnouncement = "current SSML announcement";
75-
when(routeProgress.currentSsmlAnnouncement()).thenReturn(currentSsmlAnnouncement);
76+
when(routeProgress.voiceInstruction().getSsmlAnnouncement()).thenReturn(currentSsmlAnnouncement);
7677
VoiceInstructionMilestone milestone = buildVoiceInstructionMilestone();
7778

7879
milestone.isOccurring(routeProgress, routeProgress);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mock-maker-inline

0 commit comments

Comments
 (0)