### Question:
JGeometryConverter { public static JGeometry convert(Geometry geometry) { switch (geometry.getGeometryType()) { case POINT: return convert((Point) geometry); case GEOMETRY_COLLECTION: return convert((GeometryCollection) geometry); case LINE_STRING: return convert((LineString) geometry); case LINEAR_RING: return convert((LinearRing) geometry); case POLYGON: return convert((Polygon) geometry); case POLYHEDRAL_SURFACE: return convert((PolyHedralSurface) geometry); case MULTI_POINT: return convert((MultiPoint) geometry); case MULTI_POLYGON: return convert((MultiPolygon) geometry); case MULTI_LINE_STRING: return convert((MultiLineString) geometry); default: throw new IllegalArgumentException(geometry.toString()); } } private  JGeometryConverter(); static JGeometry convert(Geometry geometry); static Geometry convert(JGeometry geometry);  }### Answer:
@Test public void roundTrip() { List<Geometry> geometries = getGeometries(); for (Geometry geometry : geometries) { if (geometry instanceof MultiPolygon) { continue; } if (geometry instanceof GeometryCollection) { continue; } System.err.println(Wkt.toWkt(geometry)); JGeometry converted = JGeometryConverter.convert(geometry); Geometry back = JGeometryConverter.convert(converted); assertEquals(geometry, back); } }
@Test public void polygon() { Polygon polygon = (org.geolatte.geom.Polygon) Wkt.fromWkt("POLYGON (" + "(30 10, 40 40, 20 40, 10 20, 30 10), " + "(20 30, 35 35, 30 20, 20 30))"); JGeometry geo = JGeometryConverter.convert(polygon); double[] extRing = new double[]{30, 10, 40, 40, 20, 40, 10, 20, 30, 10}; double[] intRing = new double[]{20, 30, 35, 35, 30, 20, 20, 30}; JGeometry geo2 = JGeometry.createLinearPolygon(new Object[]{extRing, intRing}, polygon.getCoordinateDimension(), polygon.getSRID()); assertEquals(geo2, geo); }
@Test public void multiLineString() { MultiLineString multiLineString = (org.geolatte.geom.MultiLineString) Wkt.fromWkt("MULTILINESTRING (" + "(30 10, 40 40, 20 40, 10 20, 30 10), " + "(20 30, 35 35, 30 20, 20 30))"); JGeometry geo = JGeometryConverter.convert(multiLineString); double[] line1 = new double[]{30, 10, 40, 40, 20, 40, 10, 20, 30, 10}; double[] line2 = new double[]{20, 30, 35, 35, 30, 20, 20, 30}; JGeometry geo2 = JGeometry.createLinearMultiLineString(new Object[]{line1, line2}, multiLineString.getCoordinateDimension(), multiLineString.getSRID()); assertEquals(geo2, geo); }