FileDocCategorySizeDatePackage
ClassFileSetTest.javaAPI DocApache Ant 1.707088Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.types.optional.depend

ClassFileSetTest

public class ClassFileSetTest extends org.apache.tools.ant.BuildFileTest
Testcase for the Classfileset optional type.

Fields Summary
public static final String
RESULT_FILESET
Constructors Summary
public ClassFileSetTest(String name)


       
        super(name);
    
Methods Summary
public voidsetUp()

        // share the setup for testing the depend task
        configureProject("src/etc/testcases/taskdefs/optional/depend/depend.xml");
    
public voidtearDown()

        executeTarget("clean");
    
public voidtestBasicSet()
Test basic classfileset

        Project p = getProject();
        executeTarget("testbasicset");
        FileSet resultFileSet = (FileSet)p.getReference(RESULT_FILESET);
        DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p);
        String[] scannedFiles = scanner.getIncludedFiles();
        Hashtable files = new Hashtable();
        for (int i = 0; i < scannedFiles.length; ++i) {
            files.put(scannedFiles[i], scannedFiles[i]);
        }
        assertEquals("Classfileset did not pick up expected number of "
            + "class files", 4, files.size());
        assertTrue("Result did not contain A.class",
            files.containsKey("A.class"));
        assertTrue("Result did not contain B.class",
            files.containsKey("B.class"));
        assertTrue("Result did not contain C.class",
            files.containsKey("C.class"));
        assertTrue("Result did not contain D.class",
            files.containsKey("D.class"));
    
public voidtestByReference()
Test that you can pass a classfileset by reference to a fileset.

        executeTarget("testbyreference");
    
public voidtestComboSet()
Test combo classfileset

        Project p = getProject();
        executeTarget("testcomboset");
        FileSet resultFileSet = (FileSet)p.getReference(RESULT_FILESET);
        DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p);
        String[] scannedFiles = scanner.getIncludedFiles();
        Hashtable files = new Hashtable();
        for (int i = 0; i < scannedFiles.length; ++i) {
            files.put(scannedFiles[i], scannedFiles[i]);
        }
        assertEquals("Classfileset did not pick up expected number of "
            + "class files", 1, files.size());
        assertTrue("Result did not contain C.class",
            files.containsKey("C.class"));
    
public voidtestMethodParam()
Test that classes included in a method "System.out.println(MyClass.class)" are included.

        Project p = getProject();
        executeTarget("testmethodparam");
        FileSet resultFileSet = (FileSet)p.getReference(RESULT_FILESET);
        DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p);
        String[] scannedFiles = scanner.getIncludedFiles();
        Hashtable files = new Hashtable();
        for (int i = 0; i < scannedFiles.length; ++i) {
            files.put(scannedFiles[i], scannedFiles[i]);
        }
        assertEquals("Classfileset did not pick up expected number of "
            + "class files", 5, files.size());
        assertTrue("Result did not contain A.class",
            files.containsKey("A.class"));
        assertTrue("Result did not contain B.class",
            files.containsKey("B.class"));
        assertTrue("Result did not contain C.class",
            files.containsKey("C.class"));
        assertTrue("Result did not contain D.class",
            files.containsKey("D.class"));
        assertTrue("Result did not contain E.class",
            files.containsKey("E.class"));
    
public voidtestMethodParamInner()
Test that classes included in a method "System.out.println(Outer.Inner.class)" are included.

        Project p = getProject();
        executeTarget("testmethodparaminner");
        FileSet resultFileSet = (FileSet)p.getReference(RESULT_FILESET);
        DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p);
        String[] scannedFiles = scanner.getIncludedFiles();
        Hashtable files = new Hashtable();
        for (int i = 0; i < scannedFiles.length; ++i) {
            files.put(scannedFiles[i], scannedFiles[i]);
        }
        assertEquals("Classfileset did not pick up expected number of "
            + "class files", 4, files.size());
        assertTrue("Result did not contain test" + File.separator + "Outer$Inner.class",
            files.containsKey("test" + File.separator + "Outer$Inner.class"));
        assertTrue("Result did not contain test" + File.separator + "Outer.class",
            files.containsKey("test" + File.separator + "Outer.class"));
        assertTrue("Result did not contain test" + File.separator + "ContainsOnlyInner.class",
            files.containsKey("test" + File.separator + "ContainsOnlyInner.class"));
        assertTrue("Result did not contain test" + File.separator + "ContainsOnlyInner.class",
            files.containsKey("test" + File.separator + "MethodParam.class"));
    
public voidtestResourceCollection()

        executeTarget("testresourcecollection");
    
public voidtestSmallSet()
Test small classfileset

        Project p = getProject();
        executeTarget("testsmallset");
        FileSet resultFileSet = (FileSet)p.getReference(RESULT_FILESET);
        DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p);
        String[] scannedFiles = scanner.getIncludedFiles();
        Hashtable files = new Hashtable();
        for (int i = 0; i < scannedFiles.length; ++i) {
            files.put(scannedFiles[i], scannedFiles[i]);
        }
        assertEquals("Classfileset did not pick up expected number of "
            + "class files", 2, files.size());
        assertTrue("Result did not contain B.class",
            files.containsKey("B.class"));
        assertTrue("Result did not contain C.class",
            files.containsKey("C.class"));