⇒ Index (Frames) |  ⇒ Index (No Frames) |  ⇒ Package |  ⇒ Package Tree |  ⇒ Full Tree 
jdepend.framework

Class DependencyConstraint

java.lang.Object
|
+--jdepend.framework.DependencyConstraint


public class DependencyConstraint
extends java.lang.Object

The DependencyConstraint class 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));
Authors:
(mike@clarkware.com)
Clarkware Consulting, Inc.

Constructor Summary

DependencyConstraint()

Constructs a DependencyConstraint instance.

Method Summary

JavaPackage

addPackage(java.lang.String packageName)

Adds the specified Java package to the constraint, creating it if necessary.

void

addPackage(JavaPackage jPackage)

Adds the specified Java package to the constraint.

java.util.Collection

getPackages()

Returns the constraint packages.

boolean

match(java.util.Collection expectedPackages)

Indicates whether the specified packages match the packages in this constraint.

Constructor Details

DependencyConstraint

public DependencyConstraint()

Constructs a DependencyConstraint instance.

Method Details

addPackage

public JavaPackage addPackage(java.lang.String packageName)

Adds the specified Java package to the constraint, creating it if necessary.

Parameters:
packageName - Java package name.
Returns:
Java package.

addPackage

public void addPackage(JavaPackage jPackage)

Adds the specified Java package to the constraint.

Parameters:
jPackage - Java package.

getPackages

public Collection getPackages()

Returns the constraint packages.

Returns:
Packages.

match

public boolean match(java.util.Collection expectedPackages)

Indicates whether the specified packages match the packages in this constraint.

Parameters:
expectedPackages
Returns:
true if the packages match this constraint