Skip to content

Commit

Permalink
Fix IllegalArgumentException when updating InstructionList
Browse files Browse the repository at this point in the history
  • Loading branch information
danesfeder committed Jul 19, 2018
1 parent 6f03468 commit 8d9d4a0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private boolean addBannerInstructions(RouteProgress routeProgress) {
List<LegStep> steps = currentLeg.steps();
for (LegStep step : steps) {
List<BannerInstructions> bannerInstructions = step.bannerInstructions();
if (bannerInstructions != null) {
if (bannerInstructions != null && !bannerInstructions.isEmpty()) {
instructions.addAll(bannerInstructions);
didAddInstructions = true;
}
Expand Down Expand Up @@ -150,8 +150,8 @@ private boolean removeInstructionsFrom(int currentInstructionIndex) {
if (currentInstructionIndex == FIRST_INSTRUCTION_INDEX) {
instructions.remove(FIRST_INSTRUCTION_INDEX);
return true;
} else if (currentInstructionIndex < instructions.size() - 1) {
instructions.subList(0, currentInstructionIndex).clear();
} else if (currentInstructionIndex <= instructions.size()) {
instructions.subList(FIRST_INSTRUCTION_INDEX, currentInstructionIndex).clear();
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.List;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyDouble;
Expand Down Expand Up @@ -107,6 +108,19 @@ public void updateBannerListWith_instructionListIsPopulated() throws Exception {
assertTrue(didUpdate);
}

@Test
public void updateBannerListWith_emptyInstructionsReturnFalse() throws Exception {
RouteProgress routeProgress = buildRouteProgress();
RouteUtils routeUtils = buildRouteUtils(routeProgress);
clearInstructions(routeProgress);
DistanceFormatter distanceFormatter = mock(DistanceFormatter.class);
InstructionListPresenter presenter = new InstructionListPresenter(routeUtils, distanceFormatter);

boolean didUpdate = presenter.updateBannerListWith(routeProgress);

assertFalse(didUpdate);
}

@NonNull
private RouteProgress buildRouteProgress() throws Exception {
DirectionsRoute route = buildTestDirectionsRoute();
Expand Down Expand Up @@ -140,4 +154,13 @@ private int retrieveInstructionSizeFrom(RouteLeg routeLeg) {
}
return instructions.size() - 1;
}

private void clearInstructions(RouteProgress routeProgress) {
for (LegStep step : routeProgress.currentLeg().steps()) {
List<BannerInstructions> instructions = step.bannerInstructions();
if (instructions != null) {
instructions.clear();
}
}
}
}

0 comments on commit 8d9d4a0

Please sign in to comment.