ImmutableFeatures implements Features { @Override public JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate) { final Predicate<JsonField> predicate = schemaVersion.and(thePredicate); final JsonObjectBuilder jsonObjectBuilder = JsonFactory.newObjectBuilder(); jsonObjectBuilder.set(JSON_SCHEMA_VERSION, schemaVersion.toInt(), predicate); features.values() .forEach(feature -> { final JsonKey key = JsonFactory.newKey(feature.getId()); final JsonValue value = feature.toJson(schemaVersion, thePredicate); final JsonFieldDefinition<JsonObject> fieldDefinition = JsonFactory.newJsonObjectFieldDefinition(key, FieldType.REGULAR, JsonSchemaVersion.V_1, JsonSchemaVersion.V_2); final JsonField field = JsonFactory.newField(key, value, fieldDefinition); jsonObjectBuilder.set(field, predicate); }); return jsonObjectBuilder.build(); } private  ImmutableFeatures(final Map<String, Feature> features); static ImmutableFeatures empty(); static ImmutableFeatures of(final Iterable<Feature> features); static ImmutableFeatures of(final Feature feature, final Feature... additionalFeatures); @Override Optional<Feature> getFeature(final String featureId); @Override Features setFeature(final Feature feature); @Override Features removeFeature(final String featureId); @Override Features setDefinition(final String featureId, final FeatureDefinition definition); @Override Features removeDefinition(final String featureId); @Override Features setProperties(final String featureId, final FeatureProperties properties); @Override Features removeProperties(final String featureId); @Override Features setProperty(final String featureId, final JsonPointer propertyPath, final JsonValue propertyValue); @Override Features removeProperty(final String featureId, final JsonPointer propertyPath); @Override int getSize(); @Override boolean isEmpty(); @Override Stream<Feature> stream(); @Override Iterator<Feature> iterator(); @Override JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }
@Test public void toJsonReturnsExpected() { final JsonObject expectedJson = JsonFactory.newObjectBuilder() .set(FLUX_CAPACITOR_ID, FLUX_CAPACITOR.toJson()) .build(); assertThat(underTest.toJson()).isEqualTo(expectedJson); }