From 345c06e5e8e3d1da981c997006b5bddb512ce25d Mon Sep 17 00:00:00 2001 From: Nicholas Knize Date: Fri, 14 Nov 2014 08:12:38 -0600 Subject: [PATCH] Correcting coordinate checks on LinearRing and LineString, updating test --- .../elasticsearch/common/geo/builders/ShapeBuilder.java | 7 +++---- .../test/hamcrest/ElasticsearchGeoAssertions.java | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/elasticsearch/common/geo/builders/ShapeBuilder.java b/src/main/java/org/elasticsearch/common/geo/builders/ShapeBuilder.java index f90f4fa660b..9a754dc7460 100644 --- a/src/main/java/org/elasticsearch/common/geo/builders/ShapeBuilder.java +++ b/src/main/java/org/elasticsearch/common/geo/builders/ShapeBuilder.java @@ -632,7 +632,7 @@ public abstract class ShapeBuilder implements ToXContent { */ if (coordinates.children.size() < 2) { throw new ElasticsearchParseException("Invalid number of points in LineString (found " + - coordinates.children.size() + " - must be 0 or >= 2)"); + coordinates.children.size() + " - must be >= 2)"); } LineStringBuilder line = newLineString(); @@ -659,9 +659,8 @@ public abstract class ShapeBuilder implements ToXContent { */ if (coordinates.children.size() < 4) { throw new ElasticsearchParseException("Invalid number of points in LinearRing (found " + - coordinates.children.size() + " - must be 0 or >= 4)"); - } else if (coordinates.children.size() != 0 && - !coordinates.children.get(0).coordinate.equals( + coordinates.children.size() + " - must be >= 4)"); + } else if (!coordinates.children.get(0).coordinate.equals( coordinates.children.get(coordinates.children.size() - 1).coordinate)) { throw new ElasticsearchParseException("Invalid LinearRing found (coordinates are not closed)"); } diff --git a/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchGeoAssertions.java b/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchGeoAssertions.java index 7f29fe855e2..ac8efff76b9 100644 --- a/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchGeoAssertions.java +++ b/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchGeoAssertions.java @@ -252,7 +252,7 @@ public class ElasticsearchGeoAssertions { public static void assertValidParseException(XContentParser parser) { try { ShapeBuilder.parse(parser); - throw new RuntimeException("process completed successfully when parse exception expected"); + Assert.fail("process completed successfully when parse exception expected"); } catch (Exception e) { assert(e instanceof ElasticsearchParseException): "expected ElasticsearchParse exception but found " + e.getClass().getName(); }