ImmutableResource implements Resource { public static Resource of(final ResourceKey resourceKey, final JsonValue jsonValue) { checkNotNull(jsonValue, "JSON value"); final EffectedPermissions effectedPermissions = Optional.of(jsonValue) .filter(JsonValue::isObject) .map(JsonValue::asObject) .map(object -> wrapJsonRuntimeException(() -> ImmutableEffectedPermissions.fromJson(object))) .orElseThrow(() -> new DittoJsonException(JsonParseException.newBuilder() .message("The JSON object for the 'permissions' (grant/revoke) of the 'resource' '" + resourceKey + "' is missing or not an object.") .build())); return of(resourceKey, effectedPermissions); } private  ImmutableResource(final ResourceKey theResourceKey, final EffectedPermissions theEffectedPermissions); static Resource of(final ResourceKey resourceKey, final JsonValue jsonValue); static Resource of(final ResourceKey resourceKey, final EffectedPermissions effectedPermissions); static Resource fromJson(final JsonObject jsonObject); @Override ResourceKey getResourceKey(); @Override String getType(); @Override JsonPointer getPath(); @Override String getFullQualifiedPath(); @Override EffectedPermissions getEffectedPermissions(); @Override JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }
@Test(expected = NullPointerException.class) public void createResourceWithJsonValueNull() { ImmutableResource.of(RESOURCE_KEY, (JsonValue) null); }
@Test(expected = NullPointerException.class) public void createResourceWithEffectedPermissionsNull() { ImmutableResource.of(RESOURCE_KEY, (EffectedPermissions) null); }
@Test(expected = DittoJsonException.class) public void createResourceWithJsonValueInvalidType() { ImmutableResource.of(RESOURCE_KEY, JsonFactory.newValue(true)); }
@Test(expected = DittoJsonException.class) public void createResourceWithJsonValueMissingFields() { ImmutableResource.of(RESOURCE_KEY, JsonFactory.newObjectBuilder() .set(Resource.JsonFields.SCHEMA_VERSION, JsonSchemaVersion.V_2.toInt()) .build()); }