ImmutablePolicyEntry implements PolicyEntry { public static PolicyEntry fromJson(final CharSequence label, final JsonObject jsonObject) { checkNotNull(jsonObject, "JSON object"); final Label lbl = Label.of(label); try { final JsonObject subjectsJsonObject = jsonObject.getValueOrThrow(JsonFields.SUBJECTS); final Subjects subjectsFromJson = PoliciesModelFactory.newSubjects(subjectsJsonObject); final JsonObject resourcesJsonObject = jsonObject.getValueOrThrow(JsonFields.RESOURCES); final Resources resourcesFromJson = PoliciesModelFactory.newResources(resourcesJsonObject); return of(lbl, subjectsFromJson, resourcesFromJson); } catch (final JsonMissingFieldException e) { throw new DittoJsonException(e); } } private  ImmutablePolicyEntry(final Label theLabel, final Subjects theSubjects, final Resources theResources); static PolicyEntry of(final Label label, final Subjects subjects, final Resources resources); static PolicyEntry fromJson(final CharSequence label, final JsonObject jsonObject); @Override Label getLabel(); @Override Subjects getSubjects(); @Override Resources getResources(); @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 testFromJsonWithNullLabel() { ImmutablePolicyEntry.fromJson(null, JsonFactory.newObjectBuilder().build()); }
@Test(expected = DittoJsonException.class) public void testFromJsonEmptyWithLabel() { final JsonObject jsonObject = JsonFactory.newObjectBuilder().build(); ImmutablePolicyEntry.fromJson(LABEL_END_USER, jsonObject); }
@Test(expected = DittoJsonException.class) public void testFromJsonOnlySchemaVersion() { final JsonObject jsonObject = JsonFactory.newObjectBuilder() .set(JsonSchemaVersion.getJsonKey(), JsonSchemaVersion.V_2.toInt()) .build(); ImmutablePolicyEntry.fromJson("EndUser", jsonObject); }