Correcting coordinate checks on LinearRing and LineString, updating test

This commit is contained in:
Nicholas Knize 2014-11-14 08:12:38 -06:00
parent c39ca479c7
commit 345c06e5e8
2 changed files with 4 additions and 5 deletions

View File

@ -632,7 +632,7 @@ public abstract class ShapeBuilder implements ToXContent {
*/ */
if (coordinates.children.size() < 2) { if (coordinates.children.size() < 2) {
throw new ElasticsearchParseException("Invalid number of points in LineString (found " + 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(); LineStringBuilder line = newLineString();
@ -659,9 +659,8 @@ public abstract class ShapeBuilder implements ToXContent {
*/ */
if (coordinates.children.size() < 4) { if (coordinates.children.size() < 4) {
throw new ElasticsearchParseException("Invalid number of points in LinearRing (found " + throw new ElasticsearchParseException("Invalid number of points in LinearRing (found " +
coordinates.children.size() + " - must be 0 or >= 4)"); coordinates.children.size() + " - must be >= 4)");
} else if (coordinates.children.size() != 0 && } else if (!coordinates.children.get(0).coordinate.equals(
!coordinates.children.get(0).coordinate.equals(
coordinates.children.get(coordinates.children.size() - 1).coordinate)) { coordinates.children.get(coordinates.children.size() - 1).coordinate)) {
throw new ElasticsearchParseException("Invalid LinearRing found (coordinates are not closed)"); throw new ElasticsearchParseException("Invalid LinearRing found (coordinates are not closed)");
} }

View File

@ -252,7 +252,7 @@ public class ElasticsearchGeoAssertions {
public static void assertValidParseException(XContentParser parser) { public static void assertValidParseException(XContentParser parser) {
try { try {
ShapeBuilder.parse(parser); 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) { } catch (Exception e) {
assert(e instanceof ElasticsearchParseException): "expected ElasticsearchParse exception but found " + e.getClass().getName(); assert(e instanceof ElasticsearchParseException): "expected ElasticsearchParse exception but found " + e.getClass().getName();
} }