@Test public void testFromJson() { final Severity severity = Severity.MINOR; final PackageId packId = PackageId.fromString("my_pack"); final String description = "some description"; final Violation violation = new Violation() { @Override public Severity getSeverity() { return severity; } @Override public Collection<PackageId> getPackages() { return Collections.singletonList(packId); } @Override public String getDescription() { return description; } }; final JsonObject json = violation.toJson(); final SimpleViolation simpleViolation = SimpleViolation.fromJson(json); assertSame("expect same severity", severity, simpleViolation.getSeverity()); assertEquals("expect equal packageIds", Collections.singletonList(packId), simpleViolation.getPackages()); assertEquals("expect equal description", description, simpleViolation.getDescription()); }
public static SimpleViolation fromJson(final JsonObject jsonViolation) { String vSeverity = jsonViolation.getString(ApiConstants.violationKeys().severity(), Severity.MINOR.name()); Severity severity = Severity.valueOf(vSeverity); String description = jsonViolation.getString(ApiConstants.violationKeys().description(), ""); List<PackageId> packages = optArray(jsonViolation, ApiConstants.violationKeys().packages()) .map(array -> mapArrayOfStrings(array, PackageId::fromString, true)) .orElseGet(Collections::emptyList); return new SimpleViolation(severity, description, packages); }
SimpleViolation implements Violation { public static SimpleViolation fromJson(final JsonObject jsonViolation) { String vSeverity = jsonViolation.getString(ApiConstants.violationKeys().severity(), Severity.MINOR.name()); Severity severity = Severity.valueOf(vSeverity); String description = jsonViolation.getString(ApiConstants.violationKeys().description(), ""); List<PackageId> packages = optArray(jsonViolation, ApiConstants.violationKeys().packages()) .map(array -> mapArrayOfStrings(array, PackageId::fromString, true)) .orElseGet(Collections::emptyList); return new SimpleViolation(severity, description, packages); } }
SimpleViolation implements Violation { public static SimpleViolation fromJson(final JsonObject jsonViolation) { String vSeverity = jsonViolation.getString(ApiConstants.violationKeys().severity(), Severity.MINOR.name()); Severity severity = Severity.valueOf(vSeverity); String description = jsonViolation.getString(ApiConstants.violationKeys().description(), ""); List<PackageId> packages = optArray(jsonViolation, ApiConstants.violationKeys().packages()) .map(array -> mapArrayOfStrings(array, PackageId::fromString, true)) .orElseGet(Collections::emptyList); return new SimpleViolation(severity, description, packages); } SimpleViolation(final Severity severity, final String description, final PackageId... packages);  SimpleViolation(final Severity severity, final String description, final List<PackageId> packages); }
SimpleViolation implements Violation { public static SimpleViolation fromJson(final JsonObject jsonViolation) { String vSeverity = jsonViolation.getString(ApiConstants.violationKeys().severity(), Severity.MINOR.name()); Severity severity = Severity.valueOf(vSeverity); String description = jsonViolation.getString(ApiConstants.violationKeys().description(), ""); List<PackageId> packages = optArray(jsonViolation, ApiConstants.violationKeys().packages()) .map(array -> mapArrayOfStrings(array, PackageId::fromString, true)) .orElseGet(Collections::emptyList); return new SimpleViolation(severity, description, packages); } SimpleViolation(final Severity severity, final String description, final PackageId... packages);  SimpleViolation(final Severity severity, final String description, final List<PackageId> packages); static Builder builder(); static Builder builder(final ResourceBundle resourceBundle); @Override Severity getSeverity(); @Override Collection<PackageId> getPackages(); @Override String getDescription(); static SimpleViolation fromReported(final Violation violation); static SimpleViolation fromJson(final JsonObject jsonViolation); @Override String toString(); @Override boolean equals(final Object o); @Override int hashCode(); }
SimpleViolation implements Violation { public static SimpleViolation fromJson(final JsonObject jsonViolation) { String vSeverity = jsonViolation.getString(ApiConstants.violationKeys().severity(), Severity.MINOR.name()); Severity severity = Severity.valueOf(vSeverity); String description = jsonViolation.getString(ApiConstants.violationKeys().description(), ""); List<PackageId> packages = optArray(jsonViolation, ApiConstants.violationKeys().packages()) .map(array -> mapArrayOfStrings(array, PackageId::fromString, true)) .orElseGet(Collections::emptyList); return new SimpleViolation(severity, description, packages); } SimpleViolation(final Severity severity, final String description, final PackageId... packages);  SimpleViolation(final Severity severity, final String description, final List<PackageId> packages); static Builder builder(); static Builder builder(final ResourceBundle resourceBundle); @Override Severity getSeverity(); @Override Collection<PackageId> getPackages(); @Override String getDescription(); static SimpleViolation fromReported(final Violation violation); static SimpleViolation fromJson(final JsonObject jsonViolation); @Override String toString(); @Override boolean equals(final Object o); @Override int hashCode();  }