TurfAssertions { public static void featureOf(Feature feature, String type, String name) { if (name == null || name.length() == 0) { throw new TurfException(".featureOf() requires a name"); } if (feature == null || !feature.type().equals("Feature") || feature.geometry() == null) { throw new TurfException(String.format( "Invalid input to %s, Feature with geometry required", name)); } if (feature.geometry() == null || !feature.geometry().type().equals(type)) { throw new TurfException(String.format( "Invalid input to %s: must be a %s, given %s", name, type, feature.geometry().type())); } } private  TurfAssertions(); @Deprecated static Point getCoord(Feature obj); static void geojsonType(GeoJson value, String type, String name); static void featureOf(Feature feature, String type, String name); static void collectionOf(FeatureCollection featureCollection, String type, String name);  }
@Test public void testInvariantFeatureOf1() throws TurfException { String json = "{ type: 'Feature', geometry: { type: 'Point', coordinates: [0, 0] }, " + "properties: {}}"; thrown.expect(TurfException.class); thrown.expectMessage(startsWith(".featureOf() requires a name")); TurfAssertions.featureOf(Feature.fromJson(json), "Polygon", null); }
@Test public void testInvariantFeatureOf2() throws TurfException { String json = "{ type: 'Feature'}"; thrown.expect(TurfException.class); thrown.expectMessage(startsWith("Invalid input to foo, Feature with geometry required")); TurfAssertions.featureOf(Feature.fromJson(json), "Polygon", "foo"); }
@Test public void testInvariantFeatureOf3() throws TurfException { String json = "{ type: 'Feature', geometry: { type: 'Point', coordinates: [0, 0] }}"; thrown.expect(TurfException.class); thrown.expectMessage(startsWith("Invalid input to myfn: must be a Polygon, given Point")); TurfAssertions.featureOf(Feature.fromJson(json), "Polygon", "myfn"); }
@Test public void testInvariantFeatureOf4() { String json = "{ type: 'Feature', geometry: { type: 'Point', coordinates: [0, 0]}, " + "properties: {}}"; TurfAssertions.featureOf(Feature.fromJson(json), "Point", "myfn"); }