TextInstructions { public String laneConfig(LegStep step) { if (step.getIntersections() == null || step.getIntersections().size() == 0 || step.getIntersections().get(0).getLanes() == null || step.getIntersections().get(0).getLanes().length == 0) { throw new RuntimeException("No lanes object"); } StringBuilder config = new StringBuilder(); Boolean currentLaneValidity = null; for (IntersectionLanes lane : step.getIntersections().get(0).getLanes()) { if (currentLaneValidity == null || currentLaneValidity != lane.getValid()) { if (lane.getValid()) { config.append("o"); } else { config.append("x"); } currentLaneValidity = lane.getValid(); } } return config.toString(); } TextInstructions(String language, String version); TokenizedInstructionHook getTokenizedInstructionHook(); void setTokenizedInstructionHook(TokenizedInstructionHook tokenizedInstructionHook); JsonObject getRootObject(); JsonObject getVersionObject(); static String capitalizeFirstLetter(String text); String ordinalize(Integer number); String directionFromDegree(Double degree); String laneConfig(LegStep step); String compile(LegStep step);  }
@Test public void testLaneDiagram() { TextInstructions textInstructions = new TextInstructions("en", "v5"); Map<String, LegStep> map = new HashMap<>(); map.put("o", new LegStep(Collections.singletonList(new StepIntersection(new IntersectionLanes[] { new IntersectionLanes(true), new IntersectionLanes(true), new IntersectionLanes(true)})))); map.put("ox", new LegStep(Collections.singletonList(new StepIntersection(new IntersectionLanes[] { new IntersectionLanes(true), new IntersectionLanes(true), new IntersectionLanes(false)})))); map.put("ox", new LegStep(Collections.singletonList(new StepIntersection(new IntersectionLanes[] { new IntersectionLanes(true), new IntersectionLanes(true), new IntersectionLanes(false), new IntersectionLanes(false)})))); map.put("oxo", new LegStep(Collections.singletonList(new StepIntersection(new IntersectionLanes[] { new IntersectionLanes(true), new IntersectionLanes(false), new IntersectionLanes(true)})))); map.put("xox", new LegStep(Collections.singletonList(new StepIntersection(new IntersectionLanes[] { new IntersectionLanes(false), new IntersectionLanes(true), new IntersectionLanes(true), new IntersectionLanes(false)})))); map.put("xoxox", new LegStep(Collections.singletonList(new StepIntersection(new IntersectionLanes[] { new IntersectionLanes(false), new IntersectionLanes(true), new IntersectionLanes(false), new IntersectionLanes(true), new IntersectionLanes(false)})))); map.put("x", new LegStep(Collections.singletonList(new StepIntersection(new IntersectionLanes[] { new IntersectionLanes(false), new IntersectionLanes(false), new IntersectionLanes(false)})))); for (Object entry : map.entrySet()) { Map.Entry pair = (Map.Entry) entry; assertEquals(pair.getKey(), textInstructions.laneConfig((LegStep) pair.getValue())); } }
@Test public void testInvalidLaneDiagram() { TextInstructions textInstructions = new TextInstructions("en", "v5"); thrown.expect(RuntimeException.class); thrown.expectMessage(startsWith("No lanes object")); assertEquals("", textInstructions.laneConfig(new LegStep(Collections.singletonList( new StepIntersection(new IntersectionLanes[] {}))))); }