GeoJsonWriter { private void writeFeatureCollection(@NonNull final JsonWriter writer, @NonNull final FeatureCollection featureCollection) throws IOException { writer.beginObject(); writer.name("type") .value(featureCollection.getType()); writer.name("features"); writer.beginArray(); for (Feature feature : featureCollection.getFeatures()) { writeFeature(writer, feature); } writer.endArray(); writer.endObject(); }  @Nullable String write(@Nullable final Feature feature); void write(@NonNull final Writer out,
                      @NonNull final Feature feature); @Nullable String write(@Nullable final FeatureCollection featureCollection); void write(@NonNull final Writer out,
                      @NonNull final FeatureCollection featureCollection); void writeFeature(@NonNull final JsonWriter writer,
                             @NonNull final Feature feature);  }
@Test public void testWriteFeatureCollection() throws Exception { final Feature feature1 = mock(Feature.class); doReturn("id1").when(feature1) .getId(); doReturn("Feature").when(feature1) .getType(); doReturn(createPoint(gf, 47.2256258d, -1.5545135d)).when(feature1) .getGeometry(); doReturn(new Bundle()).when(feature1) .getProperties(); final Feature feature2 = mock(Feature.class); doReturn("id2").when(feature2) .getId(); doReturn("Feature").when(feature2) .getType(); doReturn(createMultiPoint(gf, createPoint(gf, 47.2256258d, -1.5545135d), createPoint(gf, 47.225136d, -1.553913d))).when(feature2) .getGeometry(); doReturn(new Bundle()).when(feature2) .getProperties(); final Feature feature3 = mock(Feature.class); doReturn("id3").when(feature3) .getId(); doReturn("Feature").when(feature3) .getType(); doReturn(createLineString(gf, createCoordinate(gf, 47.2256258d, -1.5545135d), createCoordinate(gf, 47.225136d, -1.553913d))).when(feature3) .getGeometry(); doReturn(new Bundle()).when(feature3) .getProperties(); final Feature feature4 = mock(Feature.class); doReturn("id4").when(feature4) .getId(); doReturn("Feature").when(feature4) .getType(); doReturn(createMultiLineString(gf, createLineString(gf, createCoordinate(gf, 47.2256258d, -1.5545135d), createCoordinate(gf, 47.225136d, -1.553913d)))).when(feature4) .getGeometry(); doReturn(new Bundle()).when(feature4) .getProperties(); final Feature feature5 = mock(Feature.class); doReturn("id5").when(feature5) .getId(); doReturn("Feature").when(feature5) .getType(); doReturn(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))).when(feature5) .getGeometry(); doReturn(new Bundle()).when(feature5) .getProperties(); final FeatureCollection featureCollection = mock(FeatureCollection.class); doReturn("FeatureCollection").when(featureCollection) .getType(); doReturn(asList(feature1, feature2, feature3, feature4, feature5)).when(featureCollection) .getFeatures(); final StringWriter writer = new StringWriter(); geoJsonWriter.write(writer, featureCollection); assertNotNull(writer.toString()); assertEquals(TestHelper.getFixture("featurecollection.json"), writer.toString()); }