GeoJsonReader { @Nullable public FeatureCollection readFeatureCollection(@Nullable final String json) { if (TextUtils.isEmpty(json)) { return null; } try { return readFeatureCollection(new StringReader(json)); } catch (IOException ioe) { Log.w(TAG, ioe.getMessage()); } return null; } GeoJsonReader(); @Nullable Feature readFeature(@Nullable final String json); @NonNull Feature readFeature(@NonNull final Reader in); @Nullable FeatureCollection readFeatureCollection(@Nullable final String json); @NonNull FeatureCollection readFeatureCollection(@NonNull final Reader in); @Nullable Geometry readGeometry(@Nullable final String json); @NonNull Geometry readGeometry(@NonNull final Reader in); @NonNull Feature readFeature(@NonNull final JsonReader reader);  }
@Test public void testReadFeatureCollectionFromJsonString() throws Exception { final String json = TestHelper.getFixture("featurecollection.json"); final FeatureCollection featureCollection = geoJsonReader.readFeatureCollection(json); assertNotNull(featureCollection); assertEquals("FeatureCollection", featureCollection.getType()); assertFalse(featureCollection.isEmpty()); assertTrue(featureCollection.hasFeature("id1")); assertTrue(featureCollection.hasFeature("id2")); assertTrue(featureCollection.hasFeature("id3")); assertTrue(featureCollection.hasFeature("id4")); assertTrue(featureCollection.hasFeature("id5")); }
@Test public void testReadFeatureCollectionFromInvalidJsonString() throws Exception { final FeatureCollection featureCollection = geoJsonReader.readFeatureCollection(""); assertNull(featureCollection); }
@Test public void testReadEmptyFeatureCollection() throws Exception { final StringReader reader = new StringReader(TestHelper.getFixture("featurecollection_empty.json")); final FeatureCollection featureCollection = geoJsonReader.readFeatureCollection(reader); assertNotNull(featureCollection); assertEquals("FeatureCollection", featureCollection.getType()); assertTrue(featureCollection.isEmpty()); }
@Test public void testReadFeatureCollection() throws Exception { final StringReader reader = new StringReader(TestHelper.getFixture("featurecollection.json")); final FeatureCollection featureCollection = geoJsonReader.readFeatureCollection(reader); assertNotNull(featureCollection); assertEquals("FeatureCollection", featureCollection.getType()); assertFalse(featureCollection.isEmpty()); assertTrue(featureCollection.hasFeature("id1")); assertTrue(featureCollection.hasFeature("id2")); assertTrue(featureCollection.hasFeature("id3")); assertTrue(featureCollection.hasFeature("id4")); assertTrue(featureCollection.hasFeature("id5")); assertFalse(featureCollection.hasFeature("no_such_feature")); final Feature feature1 = featureCollection.getFeature("id1"); assertNotNull(feature1); assertEquals("id1", feature1.getId()); assertEquals("Feature", feature1.getType()); assertNotNull(feature1.getGeometry()); assertEquals(createPoint(gf, 47.2256258d, -1.5545135d), feature1.getGeometry()); final Feature feature2 = featureCollection.getFeature("id2"); assertNotNull(feature2); assertEquals("id2", feature2.getId()); assertEquals("Feature", feature2.getType()); assertNotNull(feature2.getGeometry()); assertEquals(createMultiPoint(gf, createPoint(gf, 47.2256258d, -1.5545135d), createPoint(gf, 47.225136d, -1.553913d)), feature2.getGeometry()); final Feature feature3 = featureCollection.getFeature("id3"); assertNotNull(feature3); assertEquals("id3", feature3.getId()); assertEquals("Feature", feature3.getType()); assertNotNull(feature3.getGeometry()); assertEquals(createLineString(gf, createCoordinate(gf, 47.2256258d, -1.5545135d), createCoordinate(gf, 47.225136d, -1.553913d)), feature3.getGeometry()); final Feature feature4 = featureCollection.getFeature("id4"); assertNotNull(feature4); assertEquals("id4", feature4.getId()); assertEquals("Feature", feature4.getType()); assertNotNull(feature4.getGeometry()); assertEquals(createMultiLineString(gf, createLineString(gf, createCoordinate(gf, 47.2256258d, -1.5545135d), createCoordinate(gf, 47.225136d, -1.553913d))), feature4.getGeometry()); final Feature feature5 = featureCollection.getFeature("id5"); assertNotNull(feature5); assertEquals("id5", feature5.getId()); assertEquals("Feature", feature5.getType()); assertNotNull(feature5.getGeometry()); assertEquals(createPolygon(gf, createCoordinate(gf, 47.226219d, -1.554430d), createCoordinate(gf, 47.226237d, -1.554261d), createCoordinate(gf, 47.226122d, -1.554245d), createCoordinate(gf, 47.226106d, -1.554411d), createCoordinate(gf, 47.226219d, -1.554430d)), feature5.getGeometry()); }