use of org.revapi.simple.SimpleElement in project revapi by revapi.
the class BuildTimeReporterTest method testJSONEscapedInIgnoreHint.
@Test
public void testJSONEscapedInIgnoreHint() {
BuildTimeReporter reporter = new BuildTimeReporter();
API oldApi = API.builder().build();
API newApi = API.builder().build();
AnalysisContext ctx = AnalysisContext.builder().withOldAPI(oldApi).withNewAPI(newApi).withData(BuildTimeReporter.BREAKING_SEVERITY_KEY, DifferenceSeverity.EQUIVALENT).build();
reporter.initialize(ctx);
Element oldEl = new SimpleElement() {
@Nonnull
@Override
public API getApi() {
return oldApi;
}
@Nullable
@Override
public Archive getArchive() {
return null;
}
@Override
public int compareTo(Element o) {
return 0;
}
@Override
public String toString() {
return "old element";
}
};
Element newEl = new SimpleElement() {
@Nonnull
@Override
public API getApi() {
return newApi;
}
@Nullable
@Override
public Archive getArchive() {
return null;
}
@Override
public int compareTo(Element o) {
return 0;
}
@Override
public String toString() {
return "new element";
}
};
Report report = Report.builder().withNew(newEl).withOld(oldEl).addProblem().withCode("diffs\\myDiff").withDescription("the problem").addClassification(CompatibilityType.BINARY, DifferenceSeverity.BREAKING).addAttachment("shouldBeEscaped", "{\"a\", \"b\"}").done().build();
reporter.report(report);
String resultMessage = reporter.getAllProblemsMessage();
Assert.assertNotNull(resultMessage);
int start = resultMessage.indexOf('{');
int end = resultMessage.lastIndexOf('}');
String json = resultMessage.substring(start, end + 1);
json = json.replace("<<<<< ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE >>>>>", "\"\"");
ModelNode parsed = ModelNode.fromJSONString(json);
Assert.assertEquals("diffs\\myDiff", parsed.get("code").asString());
Assert.assertEquals("{\"a\", \"b\"}", parsed.get("shouldBeEscaped").asString());
}
Aggregations