GeometryCollectionBuilder { public GeometryCollectionBuilder polygon(double... points) { if (points.length % 2 != 0) { throw new IllegalArgumentException("Must have even number of points"); } if (points.length < 6) { throw new IllegalArgumentException("Must have at least 3 pairs of points"); } if (notEmpty) { stringBuilder.append(", "); } stringBuilder.append("POLYGON (("); for (int i = 0; i < points.length - 1; i++) { stringBuilder.append(points[i]); if (i % 2 != 0) { stringBuilder.append(", "); } else { stringBuilder.append(" "); } } stringBuilder.append(points[points.length - 1]).append("))"); notEmpty = true; return this; } GeometryCollectionBuilder(); GeometryCollectionBuilder polygon(double... points); GeometryCollectionBuilder addWkt(String wkt); @Override String toString();  }
@Test(expected = IllegalArgumentException.class) public void testPolygonOddCoordinateCount() { GeometryCollectionBuilder geometryCollectionBuilder = new GeometryCollectionBuilder(); geometryCollectionBuilder.polygon(1.0, 2.1, 3.0, 4.0, 5.0, 6.0, 7.0); }
@Test(expected = IllegalArgumentException.class) public void testPolygonTooFewPoints() { GeometryCollectionBuilder geometryCollectionBuilder = new GeometryCollectionBuilder(); geometryCollectionBuilder.polygon(1.0, 1.1, 2.0, 2.1, 3.0); }