Package jdepend.framework
Class DependencyConstraint
- java.lang.Object
-
- jdepend.framework.DependencyConstraint
-
public class DependencyConstraint extends java.lang.ObjectTheDependencyConstraintclass is a constraint that tests whether two package-dependency graphs are equivalent.This class is useful for writing package dependency assertions (e.g. JUnit). For example, the following JUnit test will ensure that the 'ejb' and 'web' packages only depend upon the 'util' package, and no others:
public void testDependencyConstraint() { JDepend jdepend = new JDepend(); jdepend.addDirectory("/path/to/classes"); Collection analyzedPackages = jdepend.analyze(); DependencyConstraint constraint = new DependencyConstraint(); JavaPackage ejb = constraint.addPackage("com.xyz.ejb"); JavaPackage web = constraint.addPackage("com.xyz.web"); JavaPackage util = constraint.addPackage("com.xyz.util"); ejb.dependsUpon(util); web.dependsUpon(util); assertEquals("Dependency mismatch", true, constraint .match(analyzedPackages)); }- Author:
- Mike Clark, Clarkware Consulting, Inc.
-
-
Constructor Summary
Constructors Constructor Description DependencyConstraint()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JavaPackageaddPackage(java.lang.String packageName)voidaddPackage(JavaPackage jPackage)java.util.CollectiongetPackages()booleanmatch(java.util.Collection expectedPackages)Indicates whether the specified packages match the packages in this constraint.
-
-
-
Method Detail
-
addPackage
public JavaPackage addPackage(java.lang.String packageName)
-
addPackage
public void addPackage(JavaPackage jPackage)
-
getPackages
public java.util.Collection getPackages()
-
match
public boolean match(java.util.Collection expectedPackages)
Indicates whether the specified packages match the packages in this constraint.- Returns:
trueif the packages match this constraint
-
-