TurfAssertions { public static void collectionOf(FeatureCollection featureCollection, String type, String name) { if (name == null || name.length() == 0) { throw new TurfException("collectionOf() requires a name"); } if (featureCollection == null || !featureCollection.type().equals("FeatureCollection") || featureCollection.features() == null) { throw new TurfException(String.format( "Invalid input to %s, FeatureCollection required", name)); } for (Feature feature : featureCollection.features()) { 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 testInvariantCollectionOf1() throws TurfException { String json = "{type: 'FeatureCollection', features: [{ type: 'Feature', geometry: { " + "type: 'Point', coordinates: [0, 0]}, properties: {}}]}"; thrown.expect(TurfException.class); thrown.expectMessage(startsWith("Invalid input to myfn: must be a Polygon, given Point")); TurfAssertions.collectionOf(FeatureCollection.fromJson(json), "Polygon", "myfn"); }
@Test public void testInvariantCollectionOf2() throws TurfException { String json = "{type: 'FeatureCollection'}"; thrown.expect(TurfException.class); thrown.expectMessage(startsWith("collectionOf() requires a name")); TurfAssertions.collectionOf(FeatureCollection.fromJson(json), "Polygon", null); }
@Test public void testInvariantCollectionOf3() throws TurfException { String json = "{type: 'FeatureCollection'}"; thrown.expect(TurfException.class); thrown.expectMessage(startsWith("Invalid input to foo, FeatureCollection required")); TurfAssertions.collectionOf(FeatureCollection.fromJson(json), "Polygon", "foo"); }
@Test public void testInvariantCollectionOf4() { String json = "{type: 'FeatureCollection', features: [{ type: 'Feature', geometry: { " + "type: 'Point', coordinates: [0, 0]}, properties: {}}]}"; TurfAssertions.collectionOf(FeatureCollection.fromJson(json), "Point", "myfn"); }