Ngsi2ParsingHelper { public static List<Coordinate> parseCoordinates(String stringCoord) { String[] coords = stringCoord.split("\\s*(;|,)\\s*"); if (coords.length == 0 || coords.length % 2 != 0) { throw new InvalidatedSyntaxException("coords"); } List<Coordinate> coordinates = new ArrayList<>(); try { for (int i = 0; i < coords.length; i += 2) { coordinates.add(new Coordinate(Double.parseDouble(coords[i]), Double.parseDouble(coords[i + 1]))); } } catch (NumberFormatException e) { throw new InvalidatedSyntaxException("coords"); } return coordinates; }  static Object parseTextValue(String value); static GeoQuery parseGeoQuery(String georel, String geometry, String coords); static GeoQuery.Geometry parseGeometry(String geometry); static List<Coordinate> parseCoordinates(String stringCoord);  }
@Test public void testParseCoords() { assertEquals(12.3, Ngsi2ParsingHelper.parseCoordinates("12.3,14.2").get(0).getLatitude(), 0.1); assertEquals(14.2, Ngsi2ParsingHelper.parseCoordinates("12.3,14.2").get(0).getLongitude(), 0.1); assertEquals(2.1, Ngsi2ParsingHelper.parseCoordinates("12.3,14.2;2.1,2.3").get(1).getLatitude(), 0.1); assertEquals(2.3, Ngsi2ParsingHelper.parseCoordinates("12.3,14.2;2.1,2.3").get(1).getLongitude(), 0.1); }
@Test(expected = InvalidatedSyntaxException.class) public void testParseCoordsEmptyError() { Ngsi2ParsingHelper.parseCoordinates(""); }
@Test(expected = InvalidatedSyntaxException.class) public void testParseCoordsIncomplete() { Ngsi2ParsingHelper.parseCoordinates("12.3"); }
@Test(expected = InvalidatedSyntaxException.class) public void testParseCoordsIncomplete2() { Ngsi2ParsingHelper.parseCoordinates("12.3,1.2;23.3"); }
@Test(expected = InvalidatedSyntaxException.class) public void testParseCoordsBadNumber() { Ngsi2ParsingHelper.parseCoordinates("12.3,BAD"); }