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);
}
}
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);
}
}
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);
}
}
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);
}
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);
}
Aggregations