FileDocCategorySizeDatePackage
DependTest.javaAPI DocApache Ant 1.704982Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.taskdefs.optional.depend

DependTest

public class DependTest extends org.apache.tools.ant.BuildFileTest
Testcase for the Depend optional task.

Fields Summary
public static final String
RESULT_FILESET
public static final String
TEST_BUILD_FILE
Constructors Summary
public DependTest(String name)


       
        super(name);
    
Methods Summary
private java.util.HashtablegetResultFiles()
Read the result fileset into a Hashtable

return
a Hashtable containing the names of the files in the result fileset

        FileSet resultFileSet = (FileSet) project.getReference(RESULT_FILESET);
        DirectoryScanner scanner = resultFileSet.getDirectoryScanner(project);
        String[] scannedFiles = scanner.getIncludedFiles();
        Hashtable files = new Hashtable();
        for (int i = 0; i < scannedFiles.length; ++i) {
            files.put(scannedFiles[i], scannedFiles[i]);
        }
        return files;
    
public voidsetUp()

        configureProject(TEST_BUILD_FILE);
    
public voidtearDown()

        executeTarget("clean");
    
public voidtestCache()
Test the operation of the cache

        executeTarget("testcache");
    
public voidtestClosure()
Test dependency traversal (closure)

        executeTarget("testclosure");
        Hashtable files = getResultFiles();
        assertTrue("Depend did not leave correct number of files", 
            files.size() <= 2);
        assertTrue("Result did not contain D.class",
            files.containsKey("D.class"));
    
public voidtestDirect()
Test direct dependency removal

        executeTarget("testdirect");
        Hashtable files = getResultFiles();
        assertEquals("Depend did not leave correct number of files", 3,
            files.size());
        assertTrue("Result did not contain A.class",
            files.containsKey("A.class"));
        assertTrue("Result did not contain D.class",
            files.containsKey("D.class"));
    
public voidtestEmptySource()
Test that an exception is thrown when the source attribute is empty

        expectBuildExceptionContaining("testemptysource",
            "No source specified", "srcdir attribute must be non-empty");
    
public voidtestInner()
Test that inner class dependencies trigger deletion of the outer class

        executeTarget("testinner");
        assertEquals("Depend did not leave correct number of files", 0,
            getResultFiles().size());
    
public voidtestInnerClosure()
Test mutual dependency between inner and outer do not cause both to be deleted

        executeTarget("testinnerclosure");
        assertEquals("Depend did not leave correct number of files", 4,
            getResultFiles().size());
    
public voidtestInnerInner()
Test that multi-leve inner class dependencies trigger deletion of the outer class

        executeTarget("testinnerinner");
        assertEquals("Depend did not leave correct number of files", 0,
            getResultFiles().size());
    
public voidtestNoSource()
Test that an exception is thrown when there is no source

        expectBuildExceptionContaining("testnosource",
            "No source specified", "srcdir attribute must be set");
    
public voidtestNonPublic()
Test the detection and warning of non public classes

        executeTarget("testnonpublic");
        String log = getLog();
        assertTrue("Expected warning about APrivate",
            log.indexOf("The class APrivate in file") != -1);
        assertTrue("but has not been deleted because its source file "
            + "could not be determined",
            log.indexOf("The class APrivate in file") != -1);