TextInstructions { public String directionFromDegree(Double degree) { if (degree == null) { return ""; } else if (degree >= 0 && degree <= 20) { return getVersionObject().getAsJsonObject("constants").getAsJsonObject("direction") .getAsJsonPrimitive("north").getAsString(); } else if (degree > 20 && degree < 70) { return getVersionObject().getAsJsonObject("constants").getAsJsonObject("direction") .getAsJsonPrimitive("northeast").getAsString(); } else if (degree >= 70 && degree <= 110) { return getVersionObject().getAsJsonObject("constants").getAsJsonObject("direction") .getAsJsonPrimitive("east").getAsString(); } else if (degree > 110 && degree < 160) { return getVersionObject().getAsJsonObject("constants").getAsJsonObject("direction") .getAsJsonPrimitive("southeast").getAsString(); } else if (degree >= 160 && degree <= 200) { return getVersionObject().getAsJsonObject("constants").getAsJsonObject("direction") .getAsJsonPrimitive("south").getAsString(); } else if (degree > 200 && degree < 250) { return getVersionObject().getAsJsonObject("constants").getAsJsonObject("direction") .getAsJsonPrimitive("southwest").getAsString(); } else if (degree >= 250 && degree <= 290) { return getVersionObject().getAsJsonObject("constants").getAsJsonObject("direction") .getAsJsonPrimitive("west").getAsString(); } else if (degree > 290 && degree < 340) { return getVersionObject().getAsJsonObject("constants").getAsJsonObject("direction") .getAsJsonPrimitive("northwest").getAsString(); } else if (degree >= 340 && degree <= 360) { return getVersionObject().getAsJsonObject("constants").getAsJsonObject("direction") .getAsJsonPrimitive("north").getAsString(); } else { throw new RuntimeException("Degree is invalid: " + degree); } } 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 testValidDirectionFromDegree() { TextInstructions textInstructions = new TextInstructions("en", "v5"); assertEquals("", textInstructions.directionFromDegree(null)); assertEquals("north", textInstructions.directionFromDegree(0.)); assertEquals("north", textInstructions.directionFromDegree(1.)); assertEquals("north", textInstructions.directionFromDegree(20.)); assertEquals("northeast", textInstructions.directionFromDegree(21.)); assertEquals("northeast", textInstructions.directionFromDegree(69.)); assertEquals("east", textInstructions.directionFromDegree(70.)); assertEquals("east", textInstructions.directionFromDegree(110.)); assertEquals("southeast", textInstructions.directionFromDegree(111.)); assertEquals("southeast", textInstructions.directionFromDegree(159.)); assertEquals("south", textInstructions.directionFromDegree(160.)); assertEquals("south", textInstructions.directionFromDegree(200.)); assertEquals("southwest", textInstructions.directionFromDegree(201.)); assertEquals("southwest", textInstructions.directionFromDegree(249.)); assertEquals("west", textInstructions.directionFromDegree(250.)); assertEquals("west", textInstructions.directionFromDegree(290.)); assertEquals("northwest", textInstructions.directionFromDegree(291.)); assertEquals("northwest", textInstructions.directionFromDegree(339.)); assertEquals("north", textInstructions.directionFromDegree(340.)); assertEquals("north", textInstructions.directionFromDegree(360.)); }
@Test public void testInvalidDirectionFromDegree() { TextInstructions textInstructions = new TextInstructions("en", "v5"); thrown.expect(RuntimeException.class); thrown.expectMessage(startsWith("Degree is invalid: 361")); assertEquals("", textInstructions.directionFromDegree(361.)); }