Search in sources :

Example 6 with Difference

use of org.revapi.Difference in project revapi by revapi.

the class IgnoreDifferenceTransformTest method testAttachmentMatch.

@Test
public void testAttachmentMatch() throws Exception {
    DummyElement oldE = new DummyElement("a");
    DummyElement newE = new DummyElement("b");
    Difference difference = Difference.builder().withCode("c").addAttachment("kachna", "nedobra").build();
    Difference anotherDiff = Difference.builder().withCode("d").build();
    Difference matchingDiff = Difference.builder().withCode("c").addAttachment("kachna", "dobra").build();
    try (IgnoreDifferenceTransform t = new IgnoreDifferenceTransform()) {
        AnalysisContext config = getAnalysisContextFromFullConfig(IgnoreDifferenceTransform.class, "[{\"extension\": \"revapi.ignore\", \"configuration\": [{\"code\":\"c\", \"kachna\": \"dobra\", \"justification\" : \"because\"}]}]");
        t.initialize(config);
        difference = t.transform(oldE, newE, difference);
        Assert.assertNotNull(difference);
        anotherDiff = t.transform(oldE, newE, anotherDiff);
        Assert.assertNotNull(anotherDiff);
        matchingDiff = t.transform(oldE, newE, matchingDiff);
        Assert.assertNull(matchingDiff);
    }
}
Also used : Difference(org.revapi.Difference) AnalysisContext(org.revapi.AnalysisContext) Test(org.junit.Test)

Example 7 with Difference

use of org.revapi.Difference in project revapi by revapi.

the class IgnoreDifferenceTransformTest method testSimpleTextMatch.

@Test
public void testSimpleTextMatch() throws Exception {
    DummyElement oldE = new DummyElement("a");
    DummyElement newE = new DummyElement("b");
    Difference difference = Difference.builder().withCode("c").build();
    try (IgnoreDifferenceTransform t = new IgnoreDifferenceTransform()) {
        AnalysisContext config = getAnalysisContextFromFullConfig(IgnoreDifferenceTransform.class, "[{\"extension\": \"revapi.ignore\", \"configuration\": [{\"code\":\"c\", \"justification\" : \"because\"}]}]");
        t.initialize(config);
        difference = t.transform(oldE, newE, difference);
        Assert.assertNull(difference);
    }
}
Also used : Difference(org.revapi.Difference) AnalysisContext(org.revapi.AnalysisContext) Test(org.junit.Test)

Example 8 with Difference

use of org.revapi.Difference in project revapi by revapi.

the class IgnoreDifferenceTransformTest method testAttachmentRegexMatch.

@Test
public void testAttachmentRegexMatch() throws Exception {
    DummyElement oldE = new DummyElement("a");
    DummyElement newE = new DummyElement("b");
    Difference difference = Difference.builder().withCode("c").addAttachment("kachna", "nedobra").build();
    Difference anotherDiff = Difference.builder().withCode("d").build();
    try (IgnoreDifferenceTransform t = new IgnoreDifferenceTransform()) {
        AnalysisContext config = getAnalysisContextFromFullConfig(IgnoreDifferenceTransform.class, "[{\"extension\": \"revapi.ignore\", \"configuration\": [{\"regex\": true, \"code\":\".*\", \"kachna\": \".*dobra$\", \"justification\" : \"because\"}]}]");
        t.initialize(config);
        difference = t.transform(oldE, newE, difference);
        Assert.assertNull(difference);
        anotherDiff = t.transform(oldE, newE, anotherDiff);
        Assert.assertNotNull(anotherDiff);
    }
}
Also used : Difference(org.revapi.Difference) AnalysisContext(org.revapi.AnalysisContext) Test(org.junit.Test)

Example 9 with Difference

use of org.revapi.Difference in project revapi by revapi.

the class MissingClassReportingTest method testReportsMissingClasses.

@Test
public void testReportsMissingClasses() throws Exception {
    AnalysisContext ctx = AnalysisContext.builder(revapi).withOldAPI(API.of(new ShrinkwrapArchive(apiV1)).build()).withNewAPI(API.of(new ShrinkwrapArchive(apiV2)).build()).withConfigurationFromJSON("{\"revapi\" : { \"java\" : { \"missing-classes\" : {\"behavior\" : \"report\" }}}}").build();
    revapi.validateConfiguration(ctx);
    List<Report> allReports = revapi.analyze(ctx).getExtensions().getFirstExtension(CollectingReporter.class, null).getReports();
    Assert.assertEquals(3, allReports.size());
    Assert.assertTrue(containsDifference(allReports, "missing-class B.T$2", "missing-class B.T$2", Code.MISSING_IN_NEW_API.code()));
    Assert.assertTrue(containsDifference(allReports, "missing-class B.T$2", "missing-class B.T$2", Code.MISSING_IN_OLD_API.code()));
    Assert.assertTrue(containsDifference(allReports, null, "missing-class B.T$3", Code.MISSING_IN_NEW_API.code()));
    Assert.assertTrue(containsDifference(allReports, null, "field A.f3", Code.FIELD_ADDED.code()));
    boolean containsMissingOld = false;
    boolean containsMissingNew = false;
    for (Difference d : allReports.get(0).getDifferences()) {
        if (d.code.equals(Code.MISSING_IN_NEW_API.code())) {
            containsMissingNew = true;
        }
        if (d.code.equals(Code.MISSING_IN_OLD_API.code())) {
            containsMissingOld = true;
        }
    }
    Assert.assertTrue(containsMissingOld);
    Assert.assertTrue(containsMissingNew);
}
Also used : Report(org.revapi.Report) AnalysisContext(org.revapi.AnalysisContext) Difference(org.revapi.Difference) Test(org.junit.Test)

Example 10 with Difference

use of org.revapi.Difference in project revapi by revapi.

the class DefaultValueChanged method doEnd.

@Override
protected List<Difference> doEnd() {
    ActiveElements<JavaMethodElement> methods = popIfActive();
    if (methods == null) {
        return null;
    }
    AnnotationValue oldValue = methods.oldElement.getDeclaringElement().getDefaultValue();
    AnnotationValue newValue = methods.newElement.getDeclaringElement().getDefaultValue();
    String attribute = methods.oldElement.getDeclaringElement().getSimpleName().toString();
    String annotationType = ((TypeElement) methods.oldElement.getDeclaringElement().getEnclosingElement()).getQualifiedName().toString();
    String ov = oldValue == null ? null : Util.toHumanReadableString(oldValue);
    String nv = newValue == null ? null : Util.toHumanReadableString(newValue);
    Difference difference;
    if (ov == null) {
        difference = createDifference(Code.METHOD_DEFAULT_VALUE_ADDED, Code.attachmentsFor(methods.oldElement, methods.newElement, "value", nv));
    } else if (nv == null) {
        difference = createDifference(Code.METHOD_DEFAULT_VALUE_REMOVED, Code.attachmentsFor(methods.oldElement, methods.newElement, "value", ov));
    } else {
        difference = createDifferenceWithExplicitParams(Code.METHOD_DEFAULT_VALUE_CHANGED, Code.attachmentsFor(methods.oldElement, methods.newElement, "oldValue", ov, "newValue", nv), attribute, annotationType, ov, nv);
    }
    return Collections.singletonList(difference);
}
Also used : JavaMethodElement(org.revapi.java.spi.JavaMethodElement) AnnotationValue(javax.lang.model.element.AnnotationValue) Difference(org.revapi.Difference)

Aggregations

Difference (org.revapi.Difference)22 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)6 AnalysisContext (org.revapi.AnalysisContext)6 JavaTypeElement (org.revapi.java.spi.JavaTypeElement)6 TypeElement (javax.lang.model.element.TypeElement)5 Map (java.util.Map)4 TypeMirror (javax.lang.model.type.TypeMirror)4 Report (org.revapi.Report)4 List (java.util.List)3 JavaMethodElement (org.revapi.java.spi.JavaMethodElement)3 Nullable (javax.annotation.Nullable)2 AnnotationValue (javax.lang.model.element.AnnotationValue)2 ExecutableElement (javax.lang.model.element.ExecutableElement)2 CoIterator (org.revapi.CoIterator)2 DifferenceSeverity (org.revapi.DifferenceSeverity)2 Element (org.revapi.Element)2 Util (org.revapi.java.spi.Util)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1