use of org.osjava.jardiff.JarDiff in project semantic-versioning by jeluard.
the class ClassInheritanceTest method shouldInheritedMethodMatchImplementedMethod.
@Test
public void shouldInheritedMethodMatchImplementedMethod() throws Exception {
/**
* The situation we are testing is as follows:
* Abstract class InheritanceRoot is initially implemented directly by ClassA.
* ClassA is later modified to extend another implementation of InheritanceRoot
* and the methods required by InheritanceRoot are now removed from ClassA directly,
* and instead inherited from the new parent, DirectDescendant. For the purposes of
* this test, this new ClassA is represented by ClassB (as we can't have the same
* class declared twice in a test -- in real life, this would both be ClassA's,
* in different jars).
*/
Map<String, ClassInfo> oldClassInfoMap = new HashMap<String, ClassInfo>();
Map<String, ClassInfo> newClassInfoMap = new HashMap<String, ClassInfo>();
JarDiff jd = new JarDiff();
addClassInfo(oldClassInfoMap, ClassA.class, jd);
addClassInfo(oldClassInfoMap, DirectDescendant.class, jd);
addClassInfo(oldClassInfoMap, InheritanceRoot.class, jd);
addClassInfo(newClassInfoMap, ClassB.class, jd);
addClassInfo(newClassInfoMap, DirectDescendant.class, jd);
addClassInfo(newClassInfoMap, InheritanceRoot.class, jd);
// Make B look like A
ClassInfo a = oldClassInfoMap.get("org/semver/jardiff/ClassInheritanceTest$ClassA");
ClassInfo b = newClassInfoMap.get("org/semver/jardiff/ClassInheritanceTest$ClassB");
newClassInfoMap.put(a.getName(), new ClassInfo(b.getVersion(), b.getAccess(), a.getName(), b.getSignature(), b.getSupername(), b.getInterfaces(), b.getMethodMap(), b.getFieldMap()));
newClassInfoMap.remove(b.getName());
DifferenceAccumulatingHandler handler = new DifferenceAccumulatingHandler();
jd.diff(handler, new SimpleDiffCriteria(), "0.1.0", "0.2.0", oldClassInfoMap, newClassInfoMap);
for (Delta.Difference d : handler.getDelta().getDifferences()) {
System.err.println(d.getClassName() + " : " + d.getClass().getName() + " : " + d.getInfo().getName() + " : " + d.getInfo().getAccessType());
if (d instanceof Change) {
System.err.println(" : " + ((Change) d).getModifiedInfo().getName());
}
}
Assert.assertEquals("differences found", 1, handler.getDelta().getDifferences().size());
}
use of org.osjava.jardiff.JarDiff in project semantic-versioning by jeluard.
the class DeprecateDetectionTest method shouldInheritedMethodMatchImplementedMethod.
@Test
public void shouldInheritedMethodMatchImplementedMethod() throws Exception {
/**
* The situation we are testing is as follows:
* Abstract class InheritanceRoot is initially implemented directly by ClassA.
* ClassA is later modified to extend another implementation of InheritanceRoot
* and the methods required by InheritanceRoot are now removed from ClassA directly,
* and instead inherited from the new parent, DirectDescendant. For the purposes of
* this test, this new ClassA is represented by ClassB (as we can't have the same
* class declared twice in a test -- in real life, this would both be ClassA's,
* in different jars).
*/
Map<String, ClassInfo> oldClassInfoMap = new HashMap<String, ClassInfo>();
Map<String, ClassInfo> newClassInfoMap = new HashMap<String, ClassInfo>();
JarDiff jd = new JarDiff();
addClassInfo(oldClassInfoMap, ClassA.class, jd);
addClassInfo(oldClassInfoMap, DirectDescendant.class, jd);
addClassInfo(oldClassInfoMap, InheritanceRoot.class, jd);
addClassInfo(newClassInfoMap, ClassB.class, jd);
addClassInfo(newClassInfoMap, DirectDescendant.class, jd);
addClassInfo(newClassInfoMap, InheritanceRoot.class, jd);
// Make B look like A
newClassInfoMap.put("org/semver/jardiff/DeprecateDetectionTest$ClassA", newClassInfoMap.get("org/semver/jardiff/DeprecateDetectionTest$ClassB"));
newClassInfoMap.remove("org/semver/jardiff/DeprecateDetectionTest$ClassB");
DifferenceAccumulatingHandler handler = new DifferenceAccumulatingHandler();
jd.diff(handler, new SimpleDiffCriteria(), "0.1.0", "0.2.0", oldClassInfoMap, newClassInfoMap);
Dumper.dump(handler.getDelta());
Set<Difference> differences = handler.getDelta().getDifferences();
Assert.assertEquals("differences found", 3, differences.size());
// Naive search for Deprecate.
boolean hasDeprecate = false;
for (Difference d : differences) {
if (d instanceof Deprecate)
hasDeprecate = true;
}
Assert.assertTrue("No Delta.Deprecate found", hasDeprecate);
}
use of org.osjava.jardiff.JarDiff in project semantic-versioning by jeluard.
the class Comparer method diff.
/**
* @return all {@link Difference} between both JARs
* @throws IOException
*/
public final Delta diff() throws IOException {
try {
final JarDiff jarDiff = new JarDiff();
jarDiff.loadOldClasses(this.previousJAR);
jarDiff.loadNewClasses(this.currentJAR);
final DifferenceAccumulatingHandler handler = new DifferenceAccumulatingHandler(this.includes, this.includesAreRegExp, this.excludes, this.excludesAreRegExp);
jarDiff.diff(handler, diffCriteria);
return handler.getDelta();
} catch (DiffException e) {
throw new RuntimeException(e);
}
}
Aggregations