@Test
public void testSplitPolygon() throws Exception {

    //Line intersects polygon
    Polygon polygon = (Polygon) wKTReader.read("POLYGON (( 0 0, 10 0, 10 10 , 0 10, 0 0))");
    LineString line = (LineString) wKTReader.read("LINESTRING (5 0, 5 10)");
    Geometry pols = GeometryEdit.splitPolygonWithLine(polygon, line);
    assertEquals(pols.getNumGeometries(), 2);
    Polygon pol1 = (Polygon) wKTReader.read("POLYGON (( 0 0, 5 0, 5 10 , 0 10, 0 0))");
    Polygon pol2 = (Polygon) wKTReader.read("POLYGON ((5 0, 10 0 , 10 10, 5 10, 5 0))");
    for (int i = 0; i < pols.getNumGeometries(); i++) {
        Geometry pol = pols.getGeometryN(i);        
        if (!pol.getEnvelopeInternal().equals(pol1.getEnvelopeInternal())
                && !pol.getEnvelopeInternal().equals(pol2.getEnvelopeInternal())) {
            fail();
        }
    }
    //Line within the polygon
    line = (LineString) wKTReader.read("LINESTRING (5 1, 5 8)");
    pols = GeometryEdit.splitPolygonWithLine(polygon, line);
    assertNull(pols);
    //Line with one point intersection
    line = (LineString) wKTReader.read("LINESTRING (5 1, 5 12)");
    pols = GeometryEdit.splitPolygonWithLine(polygon, line);
    assertNull(pols);
    //Line intersects a polygon with a hole
    polygon = (Polygon) wKTReader.read("POLYGON (( 0 0, 10 0, 10 10 , 0 10, 0 0), (2 2, 7 2, 7 7, 2 7, 2 2))");
    line = (LineString) wKTReader.read("LINESTRING (5 0, 5 10)");
    pols = GeometryEdit.splitPolygonWithLine(polygon, line);
    pol1 = (Polygon) wKTReader.read("POLYGON (( 0 0, 5 0, 5 2 ,2 2, 2 7, 5 7,  5 10, 0 10, 0 0))");
    pol2 = (Polygon) wKTReader.read("POLYGON ((5 0, 5 2, 7 2, 7 7 , 5 7, 5 10, 10 10, 10 0, 5 0))");
    for (int i = 0; i < pols.getNumGeometries(); i++) {
        Geometry pol = pols.getGeometryN(i);        
        if (!pol.getEnvelopeInternal().equals(pol1.getEnvelopeInternal())
                && !pol.getEnvelopeInternal().equals(pol2.getEnvelopeInternal())) {
            fail();
        }
    }
    //Line intersects 2,5 polygon
    //Test if z values already exist
    polygon = (Polygon) wKTReader.read("POLYGON (( 0 0 1, 10 0 5, 10 10 8 , 0 10 12, 0 0 12))");
    line = (LineString) wKTReader.read("LINESTRING (5 0, 5 10)");
    pols = GeometryEdit.splitPolygonWithLine(polygon, line);
    for (int i = 0; i < pols.getNumGeometries(); i++) {
        Geometry pol = pols.getGeometryN(i);        
        assertTrue(GeometryTypeUtil.is25Geometry(pol));
    }
}