GeometryReducer implements GeometryOperator { @Override public Geometry apply(Geometry geometry, Context context) { if (geometry == null || geometry.isEmpty()) { return geometry; } return geometryPrecisionReducer.reduce(geometry); }  @Override Geometry apply(Geometry geometry, Context context);  }
@Test public void testNullSubpolygon() throws ParseException { Geometry geometry = null; GeometryReducer reducer = new GeometryReducer(); Geometry actual = reducer.apply(geometry, context); assertThat(actual, nullValue()); }
@Test public void testEmptySubpolygon() throws ParseException { Geometry geometry = GEOMETRY_FACTORY.createMultiPolygon(null); GeometryReducer reducer = new GeometryReducer(); Geometry actual = reducer.apply(geometry, context); assertThat(actual.isEmpty(), is(true)); }
@Test public void testSingleSubpolygon() throws ParseException { String wkt = "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))"; WKTReader wktReader = new WKTReader(); Geometry geometry = wktReader.read(wkt); GeometryReducer reducer = new GeometryReducer(); Geometry actual = reducer.apply(geometry, context); assertThat(actual, is(geometry)); }
@Test public void testTwoSubpolygons() throws ParseException { String wkt = "MULTIPOLYGON (((0 0, 2 10, 10 20, 20 20, 20 0, 0 0)),((0 40, 2 50, 10 60, 20 60, 20 40, 0 40)))"; WKTReader wktReader = new WKTReader(); Geometry geometry = wktReader.read(wkt); GeometryReducer reducer = new GeometryReducer(); Geometry actual = reducer.apply(geometry, context); Geometry expected = wktReader.read(wkt); assertThat(actual, is(expected)); }