|
1 | 1 | package com.mapbox.services.android.navigation.v5.milestone; |
2 | 2 |
|
3 | | -import com.mapbox.api.directions.v5.models.BannerInstructions; |
4 | | -import com.mapbox.api.directions.v5.models.LegStep; |
| 3 | +import com.mapbox.navigator.BannerComponent; |
| 4 | +import com.mapbox.navigator.BannerInstruction; |
| 5 | +import com.mapbox.navigator.BannerSection; |
5 | 6 | import com.mapbox.services.android.navigation.v5.BaseTest; |
6 | 7 | import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress; |
7 | 8 |
|
8 | 9 | import org.junit.Test; |
9 | 10 |
|
10 | | -import java.util.List; |
| 11 | +import java.util.ArrayList; |
11 | 12 |
|
12 | | -import static junit.framework.Assert.assertEquals; |
13 | | -import static junit.framework.Assert.assertFalse; |
14 | | -import static junit.framework.Assert.assertNotNull; |
15 | | -import static junit.framework.Assert.assertTrue; |
| 13 | +import static org.junit.Assert.assertEquals; |
| 14 | +import static org.junit.Assert.assertFalse; |
| 15 | +import static org.junit.Assert.assertTrue; |
16 | 16 |
|
17 | 17 | public class BannerInstructionMilestoneTest extends BaseTest { |
18 | 18 |
|
19 | 19 | @Test |
20 | | - public void sanity() { |
21 | | - BannerInstructionMilestone milestone = buildBannerInstructionMilestone(); |
22 | | - |
23 | | - assertNotNull(milestone); |
24 | | - } |
25 | | - |
26 | | - @Test |
27 | | - public void onBeginningOfStep_bannerInstructionsShouldTrigger() throws Exception { |
| 20 | + public void checksNotBannerShownIfBannerInstructionIsNull() throws Exception { |
28 | 21 | RouteProgress routeProgress = buildDefaultTestRouteProgress(); |
29 | | - routeProgress = createBeginningOfStepRouteProgress(routeProgress); |
| 22 | + BannerInstruction nullBannerInstruction = null; |
| 23 | + routeProgress = add(nullBannerInstruction, routeProgress); |
30 | 24 | BannerInstructionMilestone milestone = buildBannerInstructionMilestone(); |
31 | 25 |
|
32 | 26 | boolean isOccurring = milestone.isOccurring(routeProgress, routeProgress); |
33 | 27 |
|
34 | | - assertTrue(isOccurring); |
35 | | - } |
36 | | - |
37 | | - @Test |
38 | | - public void onSameInstructionOccurring_milestoneDoesNotTriggerTwice() throws Exception { |
39 | | - RouteProgress routeProgress = buildDefaultTestRouteProgress(); |
40 | | - RouteProgress firstProgress = createBeginningOfStepRouteProgress(routeProgress); |
41 | | - double fortyMetersIntoStep = routeProgress.currentLegProgress().currentStep().distance() - 40; |
42 | | - RouteProgress secondProgress = routeProgress.toBuilder() |
43 | | - .stepDistanceRemaining(fortyMetersIntoStep) |
44 | | - .stepIndex(0) |
45 | | - .build(); |
46 | | - BannerInstructionMilestone milestone = buildBannerInstructionMilestone(); |
47 | | - |
48 | | - milestone.isOccurring(firstProgress, firstProgress); |
49 | | - boolean shouldNotBeOccurring = milestone.isOccurring(firstProgress, secondProgress); |
50 | | - |
51 | | - assertFalse(shouldNotBeOccurring); |
| 28 | + assertFalse(isOccurring); |
52 | 29 | } |
53 | 30 |
|
54 | 31 | @Test |
55 | | - public void nullInstructions_MilestoneDoesNotGetTriggered() throws Exception { |
| 32 | + public void checksBannerShownIfBannerInstructionIsNotNull() throws Exception { |
56 | 33 | RouteProgress routeProgress = buildDefaultTestRouteProgress(); |
57 | | - LegStep currentStep = routeProgress.currentLegProgress().currentStep(); |
58 | | - List<BannerInstructions> instructions = currentStep.bannerInstructions(); |
59 | | - instructions.clear(); |
60 | | - routeProgress = createBeginningOfStepRouteProgress(routeProgress); |
| 34 | + BannerInstruction emptyBannerInstruction = buildEmptyBannerInstructionWithPrimary(null); |
| 35 | + routeProgress = add(emptyBannerInstruction, routeProgress); |
61 | 36 | BannerInstructionMilestone milestone = buildBannerInstructionMilestone(); |
62 | 37 |
|
63 | 38 | boolean isOccurring = milestone.isOccurring(routeProgress, routeProgress); |
64 | 39 |
|
65 | | - assertFalse(isOccurring); |
| 40 | + assertTrue(isOccurring); |
66 | 41 | } |
67 | 42 |
|
68 | 43 | @Test |
69 | | - public void onOccurringMilestone_beginningOfStep_bannerInstructionsAreReturned() throws Exception { |
| 44 | + public void checksBannerMappingIfBannerSectionHasComponents() throws Exception { |
70 | 45 | RouteProgress routeProgress = buildDefaultTestRouteProgress(); |
71 | | - routeProgress = routeProgress.toBuilder() |
72 | | - .stepDistanceRemaining(routeProgress.currentLegProgress().currentStep().distance()) |
73 | | - .stepIndex(1) |
74 | | - .build(); |
75 | | - BannerInstructions instructions = routeProgress.currentLegProgress().currentStep().bannerInstructions().get(0); |
| 46 | + int anAbbrPriority = 0; |
| 47 | + boolean isActive = true; |
| 48 | + ArrayList<String> anyDirections = new ArrayList<>(); |
| 49 | + anyDirections.add("a direction"); |
| 50 | + BannerComponent aComponent = new BannerComponent("a type", "a text", "an abbr", anAbbrPriority, |
| 51 | + "an image base url", isActive, anyDirections); |
| 52 | + ArrayList<BannerComponent> components = new ArrayList<>(); |
| 53 | + components.add(aComponent); |
| 54 | + BannerSection sectionWithComponents = new BannerSection("a text", "a type", "a modifier", 60, "a driving side", |
| 55 | + components); |
| 56 | + BannerInstruction emptyBannerInstruction = buildEmptyBannerInstructionWithPrimary(sectionWithComponents); |
| 57 | + routeProgress = add(emptyBannerInstruction, routeProgress); |
76 | 58 | BannerInstructionMilestone milestone = buildBannerInstructionMilestone(); |
77 | 59 |
|
78 | | - milestone.isOccurring(routeProgress, routeProgress); |
| 60 | + boolean isOccurring = milestone.isOccurring(routeProgress, routeProgress); |
79 | 61 |
|
80 | | - assertEquals(instructions, milestone.getBannerInstructions()); |
| 62 | + assertTrue(isOccurring); |
| 63 | + assertEquals(1, routeProgress.bannerInstruction().getPrimary().getComponents().size()); |
81 | 64 | } |
82 | 65 |
|
83 | | - @Test |
84 | | - public void onOccurringMilestone_endOfStep_bannerInstructionsAreReturned() throws Exception { |
85 | | - RouteProgress routeProgress = buildDefaultTestRouteProgress(); |
86 | | - int tenMetersRemainingInStep = 10; |
87 | | - routeProgress = routeProgress.toBuilder() |
88 | | - .stepDistanceRemaining(tenMetersRemainingInStep) |
89 | | - .stepIndex(1) |
| 66 | + private RouteProgress add(BannerInstruction bannerInstruction, RouteProgress routeProgress) { |
| 67 | + return routeProgress.toBuilder() |
| 68 | + .bannerInstruction(bannerInstruction) |
90 | 69 | .build(); |
91 | | - List<BannerInstructions> bannerInstructions = routeProgress.currentLegProgress().currentStep().bannerInstructions(); |
92 | | - BannerInstructions instructions = bannerInstructions.get(bannerInstructions.size() - 1); |
93 | | - BannerInstructionMilestone milestone = buildBannerInstructionMilestone(); |
94 | | - |
95 | | - milestone.isOccurring(routeProgress, routeProgress); |
96 | | - |
97 | | - assertEquals(instructions, milestone.getBannerInstructions()); |
98 | 70 | } |
99 | 71 |
|
100 | | - private RouteProgress createBeginningOfStepRouteProgress(RouteProgress routeProgress) { |
101 | | - return routeProgress.toBuilder() |
102 | | - .stepDistanceRemaining(routeProgress.currentLegProgress().currentStep().distance()) |
103 | | - .stepIndex(0) |
104 | | - .build(); |
| 72 | + private BannerInstruction buildEmptyBannerInstructionWithPrimary(BannerSection section) { |
| 73 | + return new BannerInstruction(section, null, null, -1, -1); |
105 | 74 | } |
106 | 75 |
|
107 | 76 | private BannerInstructionMilestone buildBannerInstructionMilestone() { |
|
0 commit comments