⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 anttest.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* *  Licensed to the Apache Software Foundation (ASF) under one or more *  contributor license agreements.  See the NOTICE file distributed with *  this work for additional information regarding copyright ownership. *  The ASF licenses this file to You under the Apache License, Version 2.0 *  (the "License"); you may not use this file except in compliance with *  the License.  You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * *  Unless required by applicable law or agreed to in writing, software *  distributed under the License is distributed on an "AS IS" BASIS, *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *  See the License for the specific language governing permissions and *  limitations under the License. * */package org.apache.tools.ant.taskdefs;import java.io.File;import junit.framework.AssertionFailedError;import org.apache.tools.ant.BuildEvent;import org.apache.tools.ant.BuildFileTest;import org.apache.tools.ant.BuildListener;import org.apache.tools.ant.input.InputHandler;import org.apache.tools.ant.input.PropertyFileInputHandler;import org.apache.tools.ant.types.Path;/** */public class AntTest extends BuildFileTest {    public AntTest(String name) {        super(name);    }    public void setUp() {        configureProject("src/etc/testcases/taskdefs/ant.xml");    }    public void tearDown() {        executeTarget("cleanup");    }    public void test1() {        expectBuildException("test1", "recursive call");    }    // target must be specified    public void test2() {        expectBuildException("test2", "required argument not specified");    }    // Should fail since a recursion will occur...    public void test3() {        expectBuildException("test1", "recursive call");    }    public void test4() {        expectBuildException("test4", "target attribute must not be empty");    }    public void test4b() {        expectBuildException("test4b", "target doesn't exist");    }    public void test5() {        executeTarget("test5");    }    public void test6() {        executeTarget("test6");    }    public void testExplicitBasedir1() {        File dir1 = getProjectDir();        File dir2 = project.resolveFile("..");        testBaseDirs("explicitBasedir1",                     new String[] {dir1.getAbsolutePath(),                                   dir2.getAbsolutePath()                     });    }    public void testExplicitBasedir2() {        File dir1 = getProjectDir();        File dir2 = project.resolveFile("..");        testBaseDirs("explicitBasedir2",                     new String[] {dir1.getAbsolutePath(),                                   dir2.getAbsolutePath()                     });    }    public void testInheritBasedir() {        String basedir = getProjectDir().getAbsolutePath();        testBaseDirs("inheritBasedir", new String[] {basedir, basedir});    }    public void testDoNotInheritBasedir() {        File dir1 = getProjectDir();        File dir2 = project.resolveFile("ant");        String basedir = getProjectDir().getAbsolutePath();        testBaseDirs("doNotInheritBasedir",                     new String[] {dir1.getAbsolutePath(),                                   dir2.getAbsolutePath()                     });    }    public void testBasedirTripleCall() {        File dir1 = getProjectDir();        File dir2 = project.resolveFile("ant");        testBaseDirs("tripleCall",                     new String[] {dir1.getAbsolutePath(),                                   dir2.getAbsolutePath(),                                   dir1.getAbsolutePath()                     });    }    protected void testBaseDirs(String target, String[] dirs) {        BasedirChecker bc = new BasedirChecker(dirs);        project.addBuildListener(bc);        executeTarget(target);        AssertionFailedError ae = bc.getError();        if (ae != null) {            throw ae;        }        project.removeBuildListener(bc);    }    public void testReferenceInheritance() {        Path p = Path.systemClasspath;        p.setProject(project);        project.addReference("path", p);        project.addReference("no-override", p);        testReference("testInherit", new String[] {"path", "path"},                      new boolean[] {true, true}, p);        testReference("testInherit",                      new String[] {"no-override", "no-override"},                      new boolean[] {true, false}, p);        testReference("testInherit",                      new String[] {"no-override", "no-override"},                      new boolean[] {false, false}, null);    }    public void testReferenceNoInheritance() {        Path p = Path.systemClasspath;        p.setProject(project);        project.addReference("path", p);        project.addReference("no-override", p);        testReference("testNoInherit", new String[] {"path", "path"},                      new boolean[] {true, false}, p);        testReference("testNoInherit", new String[] {"path", "path"},                      new boolean[] {false, true}, null);        testReference("testInherit",                      new String[] {"no-override", "no-override"},                      new boolean[] {true, false}, p);        testReference("testInherit",                      new String[] {"no-override", "no-override"},                      new boolean[] {false, false}, null);    }    public void testReferenceRename() {        Path p = Path.systemClasspath;        p.setProject(project);        project.addReference("path", p);        testReference("testRename", new String[] {"path", "path"},                      new boolean[] {true, false}, p);        testReference("testRename", new String[] {"path", "path"},                      new boolean[] {false, true}, null);        testReference("testRename", new String[] {"newpath", "newpath"},                      new boolean[] {false, true}, p);    }    public void testInheritPath() {        executeTarget("testInheritPath");    }    protected void testReference(String target, String[] keys,                                 boolean[] expect, Object value) {        ReferenceChecker rc = new ReferenceChecker(keys, expect, value);        project.addBuildListener(rc);        executeTarget(target);        AssertionFailedError ae = rc.getError();        if (ae != null) {            throw ae;        }        project.removeBuildListener(rc);    }    public void testLogfilePlacement() {        File[] logFiles = new File[] {            getProject().resolveFile("test1.log"),            getProject().resolveFile("test2.log"),            getProject().resolveFile("ant/test3.log"),            getProject().resolveFile("ant/test4.log")        };        for (int i=0; i<logFiles.length; i++) {            assertTrue(logFiles[i].getName()+" doesn\'t exist",                       !logFiles[i].exists());        }        executeTarget("testLogfilePlacement");        for (int i=0; i<logFiles.length; i++) {            assertTrue(logFiles[i].getName()+" exists",                       logFiles[i].exists());        }    }    public void testInputHandlerInheritance() {        InputHandler ih = new PropertyFileInputHandler();        getProject().setInputHandler(ih);        InputHandlerChecker ic = new InputHandlerChecker(ih);        getProject().addBuildListener(ic);        executeTarget("tripleCall");        AssertionFailedError ae = ic.getError();        if (ae != null) {            throw ae;        }        getProject().removeBuildListener(ic);    }    public void testRefId() {        Path testPath = new Path(project);        testPath.createPath().setPath(System.getProperty("java.class.path"));        PropertyChecker pc =            new PropertyChecker("testprop",                                new String[] {null,                                              testPath.toString()});        project.addBuildListener(pc);        executeTarget("testRefid");        AssertionFailedError ae = pc.getError();        if (ae != null) {            throw ae;        }        project.removeBuildListener(pc);    }    public void testUserPropertyWinsInheritAll() {        getProject().setUserProperty("test", "7");        expectLogContaining("test-property-override-inheritall-start",                            "The value of test is 7");    }    public void testUserPropertyWinsNoInheritAll() {        getProject().setUserProperty("test", "7");        expectLogContaining("test-property-override-no-inheritall-start",                            "The value of test is 7");    }    public void testOverrideWinsInheritAll() {        expectLogContaining("test-property-override-inheritall-start",                            "The value of test is 4");    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -