|
19 | 19 |
|
20 | 20 | package org.elasticsearch.common.geo;
|
21 | 21 |
|
22 |
| -import org.locationtech.spatial4j.exception.InvalidShapeException; |
23 |
| -import org.locationtech.spatial4j.shape.Circle; |
24 |
| -import org.locationtech.spatial4j.shape.Point; |
25 |
| -import org.locationtech.spatial4j.shape.Rectangle; |
26 |
| -import org.locationtech.spatial4j.shape.Shape; |
27 |
| -import org.locationtech.spatial4j.shape.impl.PointImpl; |
28 | 22 | import com.vividsolutions.jts.geom.Coordinate;
|
29 | 23 | import com.vividsolutions.jts.geom.LineString;
|
30 | 24 | import com.vividsolutions.jts.geom.Polygon;
|
|
35 | 29 | import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
36 | 30 | import org.elasticsearch.common.geo.builders.ShapeBuilders;
|
37 | 31 | import org.elasticsearch.test.ESTestCase;
|
| 32 | +import org.locationtech.spatial4j.exception.InvalidShapeException; |
| 33 | +import org.locationtech.spatial4j.shape.Circle; |
| 34 | +import org.locationtech.spatial4j.shape.Point; |
| 35 | +import org.locationtech.spatial4j.shape.Rectangle; |
| 36 | +import org.locationtech.spatial4j.shape.Shape; |
| 37 | +import org.locationtech.spatial4j.shape.impl.PointImpl; |
38 | 38 |
|
39 | 39 | import static org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions.assertMultiLineString;
|
40 | 40 | import static org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions.assertMultiPolygon;
|
@@ -183,17 +183,13 @@ public void testMultiLineString() {
|
183 | 183 | }
|
184 | 184 |
|
185 | 185 | public void testPolygonSelfIntersection() {
|
186 |
| - try { |
187 |
| - ShapeBuilders.newPolygon(new CoordinatesBuilder() |
| 186 | + PolygonBuilder newPolygon = ShapeBuilders.newPolygon(new CoordinatesBuilder() |
188 | 187 | .coordinate(-40.0, 50.0)
|
189 | 188 | .coordinate(40.0, 50.0)
|
190 | 189 | .coordinate(-40.0, -50.0)
|
191 |
| - .coordinate(40.0, -50.0).close()) |
192 |
| - .build(); |
193 |
| - fail("Expected InvalidShapeException"); |
194 |
| - } catch (InvalidShapeException e) { |
195 |
| - assertThat(e.getMessage(), containsString("Self-intersection at or near point (0.0")); |
196 |
| - } |
| 190 | + .coordinate(40.0, -50.0).close()); |
| 191 | + Exception e = expectThrows(InvalidShapeException.class, () -> newPolygon.build()); |
| 192 | + assertThat(e.getMessage(), containsString("Self-intersection at or near point (0.0")); |
197 | 193 | }
|
198 | 194 |
|
199 | 195 | public void testGeoCircle() {
|
@@ -550,12 +546,8 @@ public void testShapeWithInvalidTangentialHole() {
|
550 | 546 | .coordinate(179, -10)
|
551 | 547 | .coordinate(164, 0)
|
552 | 548 | ));
|
553 |
| - try { |
554 |
| - builder.close().build(); |
555 |
| - fail("Expected InvalidShapeException"); |
556 |
| - } catch (InvalidShapeException e) { |
557 |
| - assertThat(e.getMessage(), containsString("interior cannot share more than one point with the exterior")); |
558 |
| - } |
| 549 | + Exception e = expectThrows(InvalidShapeException.class, () -> builder.close().build()); |
| 550 | + assertThat(e.getMessage(), containsString("interior cannot share more than one point with the exterior")); |
559 | 551 | }
|
560 | 552 |
|
561 | 553 | public void testBoundaryShapeWithTangentialHole() {
|
@@ -602,12 +594,8 @@ public void testBoundaryShapeWithInvalidTangentialHole() {
|
602 | 594 | .coordinate(176, -10)
|
603 | 595 | .coordinate(-177, 10)
|
604 | 596 | ));
|
605 |
| - try { |
606 |
| - builder.close().build(); |
607 |
| - fail("Expected InvalidShapeException"); |
608 |
| - } catch (InvalidShapeException e) { |
609 |
| - assertThat(e.getMessage(), containsString("interior cannot share more than one point with the exterior")); |
610 |
| - } |
| 597 | + Exception e = expectThrows(InvalidShapeException.class, () -> builder.close().build()); |
| 598 | + assertThat(e.getMessage(), containsString("interior cannot share more than one point with the exterior")); |
611 | 599 | }
|
612 | 600 |
|
613 | 601 | /**
|
@@ -659,11 +647,7 @@ public void testInvalidShapeWithConsecutiveDuplicatePoints() {
|
659 | 647 | .coordinate(-176, 4)
|
660 | 648 | .coordinate(180, 0)
|
661 | 649 | );
|
662 |
| - try { |
663 |
| - builder.close().build(); |
664 |
| - fail("Expected InvalidShapeException"); |
665 |
| - } catch (InvalidShapeException e) { |
666 |
| - assertThat(e.getMessage(), containsString("duplicate consecutive coordinates at: (")); |
667 |
| - } |
| 650 | + Exception e = expectThrows(InvalidShapeException.class, () -> builder.close().build()); |
| 651 | + assertThat(e.getMessage(), containsString("duplicate consecutive coordinates at: (")); |
668 | 652 | }
|
669 | 653 | }
|
0 commit comments