Search in sources :

Example 1 with SimpleElement

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());
}
Also used : SimpleElement(org.revapi.simple.SimpleElement) Report(org.revapi.Report) Element(org.revapi.Element) SimpleElement(org.revapi.simple.SimpleElement) API(org.revapi.API) AnalysisContext(org.revapi.AnalysisContext) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Aggregations

ModelNode (org.jboss.dmr.ModelNode)1 Test (org.junit.Test)1 API (org.revapi.API)1 AnalysisContext (org.revapi.AnalysisContext)1 Element (org.revapi.Element)1 Report (org.revapi.Report)1 SimpleElement (org.revapi.simple.SimpleElement)1