I want to test in junit via jdepend whether my package tree
is on a package cycle (i.e. has a direct cyclic dependency). Currently, it isn't (see output below, and jdepend's Eclipse plugin does not find a cycle for tree
). But the assertion below, suggested in jdepend's manual, fails:
// setup....
JavaPackage p = jdepend.getPackage("tree");
System.out.println(p.getName() + "'s efferent packages: ");
for (Object jp : p.getEfferents()) {
System.out.println(((JavaPackage) jp).getName());
}
assertThat(p.containsCycle(), is(false));
The output is:
tree's efferent packages:
java.util
java.lang
java.lang.reflect
java.util.logging
java.io
org.hamcrest
The reason that the assertion fails is that containsCycle()
recursively calls getEfferents(), puts the resulting packages in a list and returns true
if some package is already in it. So containsCycle()
checks whether there is a reachable package cycle (i.e. whether tree has an indirect cyclic dependency).
But how can I test only direct cyclic dependencies, i.e. whether tree is on a package cycle (and not, that it leads to some other package cycle, e.g. in org.hamcrest)?