FileDocCategorySizeDatePackage
FailTest.javaAPI DocApache Ant 1.705218Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs

FailTest

public class FailTest extends org.apache.tools.ant.BuildFileTest

Fields Summary
Constructors Summary
public FailTest(String name)

        super(name);
    
Methods Summary
public voidsetUp()

        configureProject("src/etc/testcases/taskdefs/fail.xml");
    
public voidtest1()

        expectBuildExceptionContaining("test1",
                "it is required to fail :-)",
                "No message");
    
public voidtest2()

        expectSpecificBuildException("test2",
            "it is required to fail :-)",
            "test2");
    
public voidtestIf()

        try {
            executeTarget("testIf");
        } catch (BuildException be) {
            fail("foo has not been defined, testIf must not fail");
        }
        project.setProperty("foo", "");
        expectBuildException("testIf", "testIf must fail if foo has been set");
    
public voidtestIfAndUnless()
see that the different combinations work, and that the autogenerated text contains information about which condition was not met

        //neither
        executeTarget("testIfAndUnless");
        project.setProperty("if", "");
        expectBuildExceptionContaining("testIfAndUnless",
                "expect fail on defined(if)",
                "if=if and unless=unless");
        project.setProperty("unless", "");
        //this call should succeed as unless overrides if
        executeTarget("testIfAndUnless");
    
public voidtestIfAndUnless2()
see that the different combinations work, and that the autogenerated text contains information about which condition was not met

        project.setProperty("unless", "");
        try {
            executeTarget("testIfAndUnless");
        } catch (BuildException be) {
            fail("defined(if) && !defined(unless); testIfAndUnless must not fail");
        }
    
public voidtestNested1()

        expectSpecificBuildException("testNested1",
            "it is required to fail :-)",
            "condition satisfied");
    
public voidtestNested2()

        try {
            executeTarget("testNested2");
        } catch (BuildException be) {
            fail("condition not satisfied; testNested2 must not fail");
        }
    
public voidtestNested3()

        expectSpecificBuildException("testNested3",
            "it is required to fail :-)",
            "testNested3");
    
public voidtestNested4()

        String specificMessage = "Nested conditions "
          + "not permitted in conjunction with if/unless attributes";

        char[] c = {'a", 'b", 'c"};
        StringBuffer target = new StringBuffer("testNested4x");

        for (int i = 0; i < c.length; i++) {
            target.setCharAt(target.length() - 1, c[i]);
            expectSpecificBuildException(target.toString(),
                "it is required to fail :-)", specificMessage);
        }
    
public voidtestNested5()

        expectSpecificBuildException("testNested5",
            "it is required to fail :-)",
            "Only one nested condition is allowed.");
    
public voidtestNested6()

        expectSpecificBuildException("testNested6",
            "it is required to fail :-)",
            "testNested6\ntestNested6\ntestNested6");
    
public voidtestNested7()

        String specificMessage = "A single nested condition is required.";

        char[] c = {'a", 'b"};
        StringBuffer target = new StringBuffer("testNested7x");

        for (int i = 0; i < c.length; i++) {
            target.setCharAt(target.length() - 1, c[i]);
            expectSpecificBuildException(target.toString(),
                "it is required to fail :-)", specificMessage);
        }
    
public voidtestText()

        expectSpecificBuildException("testText",
            "it is required to fail :-)",
            "testText");
    
public voidtestUnless()

        expectBuildException("testUnless",
                             "testUnless must fail unless foo has been set");
        project.setProperty("foo", "");
        try {
            executeTarget("testUnless");
        } catch (BuildException be) {
            fail("foo has been defined, testUnless must not fail");
        }