FileDocCategorySizeDatePackage
ContainsSelectorTest.javaAPI DocApache Ant 1.703940Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.types.selectors

ContainsSelectorTest

public class ContainsSelectorTest extends BaseSelectorTest
Tests Contains Selectors.

Fields Summary
private org.apache.tools.ant.Project
project
Constructors Summary
public ContainsSelectorTest(String name)

        super(name);
    
Methods Summary
public BaseSelectorgetInstance()
Factory method from base class. This is overriden in child classes to return a specific Selector class.

        return new ContainsSelector();
    
public voidtestSelectionBehaviour()
Tests to make sure that the selector is selecting files correctly.

        ContainsSelector s;
        String results;

        try {
            makeBed();

            s = (ContainsSelector)getInstance();
            s.setText("no such string in test files");
            results = selectionString(s);
            assertEquals("TFFFFFFFFFFT", results);

            s = (ContainsSelector)getInstance();
            s.setText("Apache Ant");
            results = selectionString(s);
            assertEquals("TFFFTFFFFFFT", results);

            s = (ContainsSelector)getInstance();
            s.setText("apache ant");
            s.setCasesensitive(true);
            results = selectionString(s);
            assertEquals("TFFFFFFFFFFT", results);

            s = (ContainsSelector)getInstance();
            s.setText("apache ant");
            s.setCasesensitive(false);
            results = selectionString(s);
            assertEquals("TFFFTFFFFFFT", results);

            s = (ContainsSelector)getInstance();
            s.setText("ApacheAnt");
            s.setIgnorewhitespace(true);
            results = selectionString(s);
            assertEquals("TFFFTFFFFFFT", results);

            s = (ContainsSelector)getInstance();
            s.setText("A p a c h e    A n t");
            s.setIgnorewhitespace(true);
            results = selectionString(s);
            assertEquals("TFFFTFFFFFFT", results);

        }
        finally {
            cleanupBed();
        }

    
public voidtestValidate()
Test the code that validates the selector.

        ContainsSelector s = (ContainsSelector)getInstance();
        try {
            s.isSelected(basedir,filenames[0],files[0]);
            fail("ContainsSelector did not check for required field 'text'");
        } catch (BuildException be1) {
            assertEquals("The text attribute is required", be1.getMessage());
        }

        s = (ContainsSelector)getInstance();
        Parameter param = new Parameter();
        param.setName("garbage in");
        param.setValue("garbage out");
        Parameter[] params = {param};
        s.setParameters(params);
        try {
            s.isSelected(basedir,filenames[0],files[0]);
            fail("ContainsSelector did not check for valid parameter element");
        } catch (BuildException be2) {
            assertEquals("Invalid parameter garbage in", be2.getMessage());
        }