* @throws Exception
*/
@Test
public void testDiffOnDonut() throws Exception {
GeometryFactory geometryFactory = new GeometryFactory();
WKTReader reader = new WKTReader( geometryFactory );
//create feature collection with 2 geometries:
//1. donut minus hole
Polygon donut = (Polygon) reader.read("POLYGON ((100 100, 120 100, 120 120, 100 120, 100 100),(112 112, 118 112, 118 118, 112 118, 112 112))");
//2. hole
Polygon hole = (Polygon) reader.read("POLYGON ((112 112, 118 112, 118 118, 112 118, 112 112))");
//add the two geometries to a FeatureCollection
SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
b.setName( "Test" );
b.add( "location", Polygon.class );
SimpleFeatureType type = b.buildFeatureType();
SimpleFeature donutFeature = SimpleFeatureBuilder.build(type, new Object[]{donut}, "fid.1");
SimpleFeature holeFeature = SimpleFeatureBuilder.build(type, new Object[]{hole}, "fid.2");
DefaultFeatureCollection fc = new DefaultFeatureCollection();
fc.add(donutFeature);
fc.add(holeFeature);
//create iterator for collection
FeatureIterator<SimpleFeature> iterator = fc.features();
//create List<Geometry> for the simulated "drawn" shape
Polygon userDrawnPoly = (Polygon) reader.read("POLYGON ((114 90, 130 90, 130 130, 114 130, 114 90))");
List<Geometry> geoms = new ArrayList<Geometry>();
geoms.add(userDrawnPoly);
DifferenceFeatureCommand.runDifferenceOp(iterator, geoms);
assertEquals(1, geoms.size());