http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java b/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java index e7b14c1..9b7f4b4 100644 --- a/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java @@ -1,118 +1,118 @@ -/* - * 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.types; - -import java.io.File; - -import org.apache.tools.ant.BuildException; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * JUnit 3 testcases for org.apache.tools.ant.types.ZipFileSet. - * - * <p>This doesn't actually test much, mainly reference handling. - * - */ - -public class ZipFileSetTest extends AbstractFileSetTest { - - protected AbstractFileSet getInstance() { - return new ZipFileSet(); - } - - @Test - public final void testAttributes() { - ZipFileSet f = (ZipFileSet)getInstance(); - //check that dir and src are incompatible - f.setSrc(new File("example.zip")); - try { - f.setDir(new File("examples")); - fail("can add dir to " - + f.getDataTypeName() - + " when a src is already present"); - } catch (BuildException be) { - assertEquals("Cannot set both dir and src attributes",be.getMessage()); - } - f = (ZipFileSet)getInstance(); - //check that dir and src are incompatible - f.setDir(new File("examples")); - try { - f.setSrc(new File("example.zip")); - fail("can add src to " - + f.getDataTypeName() - + " when a dir is already present"); - } catch (BuildException be) { - assertEquals("Cannot set both dir and src attributes",be.getMessage()); - } - //check that fullpath and prefix are incompatible - f = (ZipFileSet)getInstance(); - f.setSrc(new File("example.zip")); - f.setPrefix("/examples"); - try { - f.setFullpath("/doc/manual/index.html"); - fail("Can add fullpath to " - + f.getDataTypeName() - + " when a prefix is already present"); - } catch (BuildException be) { - assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage()); - } - f = (ZipFileSet)getInstance(); - f.setSrc(new File("example.zip")); - f.setFullpath("/doc/manual/index.html"); - try { - f.setPrefix("/examples"); - fail("Can add prefix to " - + f.getDataTypeName() - + " when a fullpath is already present"); - } catch (BuildException be) { - assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage()); - } - // check that reference zipfilesets cannot have specific attributes - f = (ZipFileSet)getInstance(); - f.setRefid(new Reference(getProject(), "test")); - try { - f.setSrc(new File("example.zip")); - fail("Can add src to " - + f.getDataTypeName() - + " when a refid is already present"); - } catch (BuildException be) { - assertEquals("You must not specify more than one " - + "attribute when using refid", be.getMessage()); - } - // check that a reference zipfileset gets the same attributes as the original - f = (ZipFileSet)getInstance(); - f.setSrc(new File("example.zip")); - f.setPrefix("/examples"); - f.setFileMode("600"); - f.setDirMode("530"); - getProject().addReference("test",f); - ZipFileSet zid=(ZipFileSet)getInstance(); - zid.setRefid(new Reference(getProject(), "test")); - assertTrue("src attribute copied by copy constructor",zid.getSrc(getProject()).equals(f.getSrc(getProject()))); - assertTrue("prefix attribute copied by copy constructor",f.getPrefix(getProject()).equals(zid.getPrefix(getProject()))); - assertTrue("file mode attribute copied by copy constructor",f.getFileMode(getProject())==zid.getFileMode(getProject())); - assertTrue("dir mode attribute copied by copy constructor",f.getDirMode(getProject())==zid.getDirMode(getProject())); - } - - -} +/* + * 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.types; + +import java.io.File; + +import org.apache.tools.ant.BuildException; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * JUnit 3 testcases for org.apache.tools.ant.types.ZipFileSet. + * + * <p>This doesn't actually test much, mainly reference handling. + * + */ + +public class ZipFileSetTest extends AbstractFileSetTest { + + protected AbstractFileSet getInstance() { + return new ZipFileSet(); + } + + @Test + public final void testAttributes() { + ZipFileSet f = (ZipFileSet)getInstance(); + //check that dir and src are incompatible + f.setSrc(new File("example.zip")); + try { + f.setDir(new File("examples")); + fail("can add dir to " + + f.getDataTypeName() + + " when a src is already present"); + } catch (BuildException be) { + assertEquals("Cannot set both dir and src attributes",be.getMessage()); + } + f = (ZipFileSet)getInstance(); + //check that dir and src are incompatible + f.setDir(new File("examples")); + try { + f.setSrc(new File("example.zip")); + fail("can add src to " + + f.getDataTypeName() + + " when a dir is already present"); + } catch (BuildException be) { + assertEquals("Cannot set both dir and src attributes",be.getMessage()); + } + //check that fullpath and prefix are incompatible + f = (ZipFileSet)getInstance(); + f.setSrc(new File("example.zip")); + f.setPrefix("/examples"); + try { + f.setFullpath("/doc/manual/index.html"); + fail("Can add fullpath to " + + f.getDataTypeName() + + " when a prefix is already present"); + } catch (BuildException be) { + assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage()); + } + f = (ZipFileSet)getInstance(); + f.setSrc(new File("example.zip")); + f.setFullpath("/doc/manual/index.html"); + try { + f.setPrefix("/examples"); + fail("Can add prefix to " + + f.getDataTypeName() + + " when a fullpath is already present"); + } catch (BuildException be) { + assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage()); + } + // check that reference zipfilesets cannot have specific attributes + f = (ZipFileSet)getInstance(); + f.setRefid(new Reference(getProject(), "test")); + try { + f.setSrc(new File("example.zip")); + fail("Can add src to " + + f.getDataTypeName() + + " when a refid is already present"); + } catch (BuildException be) { + assertEquals("You must not specify more than one " + + "attribute when using refid", be.getMessage()); + } + // check that a reference zipfileset gets the same attributes as the original + f = (ZipFileSet)getInstance(); + f.setSrc(new File("example.zip")); + f.setPrefix("/examples"); + f.setFileMode("600"); + f.setDirMode("530"); + getProject().addReference("test",f); + ZipFileSet zid=(ZipFileSet)getInstance(); + zid.setRefid(new Reference(getProject(), "test")); + assertTrue("src attribute copied by copy constructor",zid.getSrc(getProject()).equals(f.getSrc(getProject()))); + assertTrue("prefix attribute copied by copy constructor",f.getPrefix(getProject()).equals(zid.getPrefix(getProject()))); + assertTrue("file mode attribute copied by copy constructor",f.getFileMode(getProject())==zid.getFileMode(getProject())); + assertTrue("dir mode attribute copied by copy constructor",f.getDirMode(getProject())==zid.getDirMode(getProject())); + } + + +}
http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/mappers/GlobMapperTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/mappers/GlobMapperTest.java b/src/tests/junit/org/apache/tools/ant/types/mappers/GlobMapperTest.java index 310fb5e..479efb7 100644 --- a/src/tests/junit/org/apache/tools/ant/types/mappers/GlobMapperTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/mappers/GlobMapperTest.java @@ -1,49 +1,49 @@ -/* - * 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.types.mappers; - -import org.apache.tools.ant.BuildFileRule; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; - -/** - * Testcase for the <globmapper> mapper. - * - */ -public class GlobMapperTest { - - @Rule - public BuildFileRule buildRule = new BuildFileRule(); - - @Before - public void setUp() { - buildRule.configureProject("src/etc/testcases/types/mappers/globmapper.xml"); - } - - @Test - public void testIgnoreCase() { - buildRule.executeTarget("ignore.case"); - } - public void testHandleDirSep() { - buildRule.executeTarget("handle.dirsep"); - } -} - - +/* + * 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.types.mappers; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Testcase for the <globmapper> mapper. + * + */ +public class GlobMapperTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/types/mappers/globmapper.xml"); + } + + @Test + public void testIgnoreCase() { + buildRule.executeTarget("ignore.case"); + } + public void testHandleDirSep() { + buildRule.executeTarget("handle.dirsep"); + } +} + + http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/mappers/MapperResult.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/mappers/MapperResult.java b/src/tests/junit/org/apache/tools/ant/types/mappers/MapperResult.java index 43a7b29..207ed59 100644 --- a/src/tests/junit/org/apache/tools/ant/types/mappers/MapperResult.java +++ b/src/tests/junit/org/apache/tools/ant/types/mappers/MapperResult.java @@ -1,103 +1,103 @@ -/* - * 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.types.mappers; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.types.Mapper; -import org.apache.tools.ant.util.FileNameMapper; - -/** - * This is a test task to show the result of a mapper - * on a specific input. - * (Test is not in the name of the class, to make sure that - * it is not treated as a unit test. - */ - -public class MapperResult extends Task { - - private String failMessage = ""; - private String input; - private String output; - private FileNameMapper fileNameMapper; - - /** - * The output on an empty string array - */ - private static final String NULL_MAPPER_RESULT = "<NULL>"; - - public void setFailMessage(String failMessage) { - this.failMessage = failMessage; - } - - public void setInput(String input) { - this.input = input; - } - - public void setOutput(String output) { - this.output = output; - } - - public void addConfiguredMapper(Mapper mapper) { - add(mapper.getImplementation()); - } - - public void add(FileNameMapper fileNameMapper) { - if (this.fileNameMapper != null) { - throw new BuildException("Only one mapper type nested element allowed"); - } - this.fileNameMapper = fileNameMapper; - } - - public void execute() { - if (input == null) { - throw new BuildException("Missing attribute 'input'"); - } - if (output == null) { - throw new BuildException("Missing attribute 'output'"); - } - if (fileNameMapper == null) { - throw new BuildException("Missing a nested file name mapper type element"); - } - String[] result = fileNameMapper.mapFileName(input); - String flattened; - if (result == null) { - flattened = NULL_MAPPER_RESULT; - } else { - StringBuffer b = new StringBuffer(); - for (int i = 0; i < result.length; ++i) { - if (i != 0) { - b.append("|"); - } - b.append(result[i]); - } - flattened = b.toString(); - } - if (!flattened.equals(output)) { - throw new BuildException( - failMessage - + " " - + "got " - + flattened - + " " - + "expected " - + output); - } - } -} +/* + * 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.types.mappers; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.types.Mapper; +import org.apache.tools.ant.util.FileNameMapper; + +/** + * This is a test task to show the result of a mapper + * on a specific input. + * (Test is not in the name of the class, to make sure that + * it is not treated as a unit test. + */ + +public class MapperResult extends Task { + + private String failMessage = ""; + private String input; + private String output; + private FileNameMapper fileNameMapper; + + /** + * The output on an empty string array + */ + private static final String NULL_MAPPER_RESULT = "<NULL>"; + + public void setFailMessage(String failMessage) { + this.failMessage = failMessage; + } + + public void setInput(String input) { + this.input = input; + } + + public void setOutput(String output) { + this.output = output; + } + + public void addConfiguredMapper(Mapper mapper) { + add(mapper.getImplementation()); + } + + public void add(FileNameMapper fileNameMapper) { + if (this.fileNameMapper != null) { + throw new BuildException("Only one mapper type nested element allowed"); + } + this.fileNameMapper = fileNameMapper; + } + + public void execute() { + if (input == null) { + throw new BuildException("Missing attribute 'input'"); + } + if (output == null) { + throw new BuildException("Missing attribute 'output'"); + } + if (fileNameMapper == null) { + throw new BuildException("Missing a nested file name mapper type element"); + } + String[] result = fileNameMapper.mapFileName(input); + String flattened; + if (result == null) { + flattened = NULL_MAPPER_RESULT; + } else { + StringBuffer b = new StringBuffer(); + for (int i = 0; i < result.length; ++i) { + if (i != 0) { + b.append("|"); + } + b.append(result[i]); + } + flattened = b.toString(); + } + if (!flattened.equals(output)) { + throw new BuildException( + failMessage + + " " + + "got " + + flattened + + " " + + "expected " + + output); + } + } +} http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/mappers/RegexpPatternMapperTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/mappers/RegexpPatternMapperTest.java b/src/tests/junit/org/apache/tools/ant/types/mappers/RegexpPatternMapperTest.java index d01593b..5fa28e0 100644 --- a/src/tests/junit/org/apache/tools/ant/types/mappers/RegexpPatternMapperTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/mappers/RegexpPatternMapperTest.java @@ -1,51 +1,51 @@ -/* - * 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.types.mappers; - -import org.apache.tools.ant.BuildFileRule; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; - -/** - * Testcase for the <regexpmapper> mapper. - * - */ -public class RegexpPatternMapperTest { - - @Rule - public BuildFileRule buildRule = new BuildFileRule(); - - @Before - public void setUp() { - buildRule.configureProject("src/etc/testcases/types/mappers/regexpmapper.xml"); - } - - @Test - public void testIgnoreCase() { - buildRule.executeTarget("ignore.case"); - } - - @Test - public void testHandleDirSep() { - buildRule.executeTarget("handle.dirsep"); - } -} - - +/* + * 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.types.mappers; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Testcase for the <regexpmapper> mapper. + * + */ +public class RegexpPatternMapperTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/types/mappers/regexpmapper.xml"); + } + + @Test + public void testIgnoreCase() { + buildRule.executeTarget("ignore.case"); + } + + @Test + public void testHandleDirSep() { + buildRule.executeTarget("handle.dirsep"); + } +} + + http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/optional/ScriptMapperTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/optional/ScriptMapperTest.java b/src/tests/junit/org/apache/tools/ant/types/optional/ScriptMapperTest.java index bf727db..8bed46c 100644 --- a/src/tests/junit/org/apache/tools/ant/types/optional/ScriptMapperTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/optional/ScriptMapperTest.java @@ -1,53 +1,53 @@ -/* - * 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.types.optional; - -import org.apache.tools.ant.BuildFileRule; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; - -/** - * Test our script mapping - */ -public class ScriptMapperTest { - - @Rule - public BuildFileRule buildRule = new BuildFileRule(); - - @Before - public void setUp() { - buildRule.configureProject("src/etc/testcases/types/mappers/scriptmapper.xml"); - } - - @Test - public void testClear() { - buildRule.executeTarget("testClear"); - } - - @Test - public void testSetMultiple() { - buildRule.executeTarget("testSetMultiple"); - } - - @Test - public void testPassthrough() { - buildRule.executeTarget("testPassthrough"); - } -} +/* + * 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.types.optional; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Test our script mapping + */ +public class ScriptMapperTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/types/mappers/scriptmapper.xml"); + } + + @Test + public void testClear() { + buildRule.executeTarget("testClear"); + } + + @Test + public void testSetMultiple() { + buildRule.executeTarget("testSetMultiple"); + } + + @Test + public void testPassthrough() { + buildRule.executeTarget("testPassthrough"); + } +} http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/optional/ScriptSelectorTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/optional/ScriptSelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/optional/ScriptSelectorTest.java index 304d6d0..c9cc655 100644 --- a/src/tests/junit/org/apache/tools/ant/types/optional/ScriptSelectorTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/optional/ScriptSelectorTest.java @@ -1,83 +1,83 @@ -/* - * 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.types.optional; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.BuildFileRule; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; - -import static org.apache.tools.ant.AntAssert.assertContains; -import static org.junit.Assert.fail; - -/** - * Test that scripting selection works. Needs scripting support to work - */ -public class ScriptSelectorTest { - - @Rule - public BuildFileRule buildRule = new BuildFileRule(); - - @Before - public void setUp() { - buildRule.configureProject("src/etc/testcases/types/selectors/scriptselector.xml"); - } - - @Test - public void testNolanguage() { - try { - buildRule.executeTarget("testNolanguage"); - fail("Absence of language attribute not detected"); - } catch(BuildException ex) { - assertContains("script language must be specified", ex.getMessage()); - - } - } - - @Test - public void testSelectionSetByDefault() { - buildRule.executeTarget("testSelectionSetByDefault"); - } - - @Test - public void testSelectionSetWorks() { - buildRule.executeTarget("testSelectionSetWorks"); - } - - @Test - public void testSelectionClearWorks() { - buildRule.executeTarget("testSelectionClearWorks"); - } - - @Test - public void testFilenameAttribute() { - buildRule.executeTarget("testFilenameAttribute"); - } - - @Test - public void testFileAttribute() { - buildRule.executeTarget("testFileAttribute"); - } - - @Test - public void testBasedirAttribute() { - buildRule.executeTarget("testBasedirAttribute"); - } - -} +/* + * 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.types.optional; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.fail; + +/** + * Test that scripting selection works. Needs scripting support to work + */ +public class ScriptSelectorTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/types/selectors/scriptselector.xml"); + } + + @Test + public void testNolanguage() { + try { + buildRule.executeTarget("testNolanguage"); + fail("Absence of language attribute not detected"); + } catch(BuildException ex) { + assertContains("script language must be specified", ex.getMessage()); + + } + } + + @Test + public void testSelectionSetByDefault() { + buildRule.executeTarget("testSelectionSetByDefault"); + } + + @Test + public void testSelectionSetWorks() { + buildRule.executeTarget("testSelectionSetWorks"); + } + + @Test + public void testSelectionClearWorks() { + buildRule.executeTarget("testSelectionClearWorks"); + } + + @Test + public void testFilenameAttribute() { + buildRule.executeTarget("testFilenameAttribute"); + } + + @Test + public void testFileAttribute() { + buildRule.executeTarget("testFileAttribute"); + } + + @Test + public void testBasedirAttribute() { + buildRule.executeTarget("testBasedirAttribute"); + } + +} http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/optional/depend/ClassFileSetTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/optional/depend/ClassFileSetTest.java b/src/tests/junit/org/apache/tools/ant/types/optional/depend/ClassFileSetTest.java index 392667c..598d100 100644 --- a/src/tests/junit/org/apache/tools/ant/types/optional/depend/ClassFileSetTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/optional/depend/ClassFileSetTest.java @@ -1,186 +1,186 @@ -/* - * 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.types.optional.depend; - -import java.io.File; -import java.util.Hashtable; - -import org.apache.tools.ant.BuildFileRule; -import org.apache.tools.ant.DirectoryScanner; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.types.FileSet; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -/** - * Testcase for the Classfileset optional type. - * - */ -public class ClassFileSetTest { - public static final String RESULT_FILESET = "result"; - - @Rule - public BuildFileRule buildRule = new BuildFileRule(); - - @Before - public void setUp() { - // share the setup for testing the depend task - buildRule.configureProject("src/etc/testcases/taskdefs/optional/depend/depend.xml"); - } - - /** - * Test basic classfileset - */ - @Test - public void testBasicSet() { - Project p = buildRule.getProject(); - buildRule.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")); - } - - /** - * Test small classfileset - */ - @Test - public void testSmallSet() { - Project p = buildRule.getProject(); - buildRule.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")); - } - - /** - * Test combo classfileset - */ - @Test - public void testComboSet() { - Project p = buildRule.getProject(); - buildRule.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")); - } - - /** - * Test that you can pass a classfileset by reference to a fileset. - */ - @Test - public void testByReference() { - buildRule.executeTarget("testbyreference"); - } - - /** - * Test that classes included in a method "System.out.println(MyClass.class)" are included. - */ - @Test - public void testMethodParam() { - Project p = buildRule.getProject(); - buildRule.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")); - } - - /** - * Test that classes included in a method "System.out.println(Outer.Inner.class)" are included. - */ - @Test - public void testMethodParamInner() { - Project p = buildRule.getProject(); - buildRule.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")); - } - - @Test - public void testResourceCollection() { - buildRule.executeTarget("testresourcecollection"); - } - -} +/* + * 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.types.optional.depend; + +import java.io.File; +import java.util.Hashtable; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.FileSet; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Testcase for the Classfileset optional type. + * + */ +public class ClassFileSetTest { + public static final String RESULT_FILESET = "result"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + // share the setup for testing the depend task + buildRule.configureProject("src/etc/testcases/taskdefs/optional/depend/depend.xml"); + } + + /** + * Test basic classfileset + */ + @Test + public void testBasicSet() { + Project p = buildRule.getProject(); + buildRule.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")); + } + + /** + * Test small classfileset + */ + @Test + public void testSmallSet() { + Project p = buildRule.getProject(); + buildRule.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")); + } + + /** + * Test combo classfileset + */ + @Test + public void testComboSet() { + Project p = buildRule.getProject(); + buildRule.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")); + } + + /** + * Test that you can pass a classfileset by reference to a fileset. + */ + @Test + public void testByReference() { + buildRule.executeTarget("testbyreference"); + } + + /** + * Test that classes included in a method "System.out.println(MyClass.class)" are included. + */ + @Test + public void testMethodParam() { + Project p = buildRule.getProject(); + buildRule.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")); + } + + /** + * Test that classes included in a method "System.out.println(Outer.Inner.class)" are included. + */ + @Test + public void testMethodParamInner() { + Project p = buildRule.getProject(); + buildRule.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")); + } + + @Test + public void testResourceCollection() { + buildRule.executeTarget("testresourcecollection"); + } + +} http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java b/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java index 71efc65..ae592c8 100644 --- a/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java @@ -1,122 +1,122 @@ -/* - * 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.types.resources; - -import java.io.File; - -import org.apache.tools.ant.Project; - -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * Test Java API of {@link FileResource}. - */ -public class FileResourceTest { - - private File root; - - @Before - public void setUp() { - root = new File(System.getProperty("root")); - } - - @Test - public void testAttributes() { - FileResource f = new FileResource(); - f.setBaseDir(root); - f.setName("foo"); - assertEquals(new File(root, "foo"), f.getFile()); - assertEquals(root, f.getBaseDir()); - assertEquals("foo", f.getName()); - } - - @Test - public void testNonImmediateBasedir() { - FileResource f = new FileResource(); - f.setBaseDir(root); - f.setName("foo/bar"); - assertEquals(new File(root, "foo/bar"), f.getFile()); - assertEquals(root, f.getBaseDir()); - assertEquals("foo/bar", f.getName().replace(File.separatorChar, '/')); - } - - @Test - public void testFile() { - FileResource f = new FileResource(new File(root, "foo")); - assertEquals(new File(root, "foo"), f.getFile()); - assertEquals(root, f.getBaseDir()); - assertEquals("foo", f.getName()); - } - - @Test - public void testBasedirAndName() { - FileResource f = new FileResource(root, "foo"); - assertEquals(new File(root, "foo"), f.getFile()); - assertEquals(root, f.getBaseDir()); - assertEquals("foo", f.getName()); - } - - @Test - public void testNonImmediateBasedirAndName() { - FileResource f = new FileResource(root, "foo/bar"); - assertEquals(new File(root, "foo/bar"), f.getFile()); - assertEquals(root, f.getBaseDir()); - assertEquals("foo/bar", f.getName().replace(File.separatorChar, '/')); - } - - @Test - public void testProjectAndFilename() { - Project p = new Project(); - p.setBaseDir(root); - FileResource f = new FileResource(p, "foo"); - assertEquals(new File(root, "foo"), f.getFile()); - assertEquals(root, f.getBaseDir()); - assertEquals("foo", f.getName()); - } - - @Test - public void testRelativeFactoryResource() { - FileResource f = new FileResource(root, "foo"); - FileResource relative = f.getResource("bar").as(FileResource.class); - assertEquals(new File(root, "foo/bar"), relative.getFile()); - assertEquals("foo/bar", relative.getName().replace(File.separatorChar, '/')); - assertEquals(root, relative.getBaseDir()); - } - - @Test - public void testAbsoluteFactoryResource() { - FileResource f = new FileResource(new File(root, "foo/a")); - assertEquals(new File(root, "foo"), f.getBaseDir()); - File bar = new File(root, "bar"); - FileResource fromFactory = f.getResource(bar.getAbsolutePath()).as(FileResource.class); - assertEquals(bar, fromFactory.getFile()); - assertEquals(root, fromFactory.getBaseDir()); - } - - @Test - public void testParentSiblingFactoryResource() { - FileResource f = new FileResource(new File(root, "foo/a")); - assertEquals(new File(root, "foo"), f.getBaseDir()); - FileResource parentSibling = f.getResource("../../bar").as(FileResource.class); - assertEquals(root, parentSibling.getBaseDir()); - assertEquals("bar", parentSibling.getName()); - } -} +/* + * 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.types.resources; + +import java.io.File; + +import org.apache.tools.ant.Project; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Test Java API of {@link FileResource}. + */ +public class FileResourceTest { + + private File root; + + @Before + public void setUp() { + root = new File(System.getProperty("root")); + } + + @Test + public void testAttributes() { + FileResource f = new FileResource(); + f.setBaseDir(root); + f.setName("foo"); + assertEquals(new File(root, "foo"), f.getFile()); + assertEquals(root, f.getBaseDir()); + assertEquals("foo", f.getName()); + } + + @Test + public void testNonImmediateBasedir() { + FileResource f = new FileResource(); + f.setBaseDir(root); + f.setName("foo/bar"); + assertEquals(new File(root, "foo/bar"), f.getFile()); + assertEquals(root, f.getBaseDir()); + assertEquals("foo/bar", f.getName().replace(File.separatorChar, '/')); + } + + @Test + public void testFile() { + FileResource f = new FileResource(new File(root, "foo")); + assertEquals(new File(root, "foo"), f.getFile()); + assertEquals(root, f.getBaseDir()); + assertEquals("foo", f.getName()); + } + + @Test + public void testBasedirAndName() { + FileResource f = new FileResource(root, "foo"); + assertEquals(new File(root, "foo"), f.getFile()); + assertEquals(root, f.getBaseDir()); + assertEquals("foo", f.getName()); + } + + @Test + public void testNonImmediateBasedirAndName() { + FileResource f = new FileResource(root, "foo/bar"); + assertEquals(new File(root, "foo/bar"), f.getFile()); + assertEquals(root, f.getBaseDir()); + assertEquals("foo/bar", f.getName().replace(File.separatorChar, '/')); + } + + @Test + public void testProjectAndFilename() { + Project p = new Project(); + p.setBaseDir(root); + FileResource f = new FileResource(p, "foo"); + assertEquals(new File(root, "foo"), f.getFile()); + assertEquals(root, f.getBaseDir()); + assertEquals("foo", f.getName()); + } + + @Test + public void testRelativeFactoryResource() { + FileResource f = new FileResource(root, "foo"); + FileResource relative = f.getResource("bar").as(FileResource.class); + assertEquals(new File(root, "foo/bar"), relative.getFile()); + assertEquals("foo/bar", relative.getName().replace(File.separatorChar, '/')); + assertEquals(root, relative.getBaseDir()); + } + + @Test + public void testAbsoluteFactoryResource() { + FileResource f = new FileResource(new File(root, "foo/a")); + assertEquals(new File(root, "foo"), f.getBaseDir()); + File bar = new File(root, "bar"); + FileResource fromFactory = f.getResource(bar.getAbsolutePath()).as(FileResource.class); + assertEquals(bar, fromFactory.getFile()); + assertEquals(root, fromFactory.getBaseDir()); + } + + @Test + public void testParentSiblingFactoryResource() { + FileResource f = new FileResource(new File(root, "foo/a")); + assertEquals(new File(root, "foo"), f.getBaseDir()); + FileResource parentSibling = f.getResource("../../bar").as(FileResource.class); + assertEquals(root, parentSibling.getBaseDir()); + assertEquals("bar", parentSibling.getName()); + } +} http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/resources/JavaResourceTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/resources/JavaResourceTest.java b/src/tests/junit/org/apache/tools/ant/types/resources/JavaResourceTest.java index a67db39..f68e9e6 100644 --- a/src/tests/junit/org/apache/tools/ant/types/resources/JavaResourceTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/resources/JavaResourceTest.java @@ -1,62 +1,62 @@ -/* - * 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.types.resources; - -import org.apache.tools.ant.BuildFileRule; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -public class JavaResourceTest { - - @Rule - public BuildFileRule buildRule = new BuildFileRule(); - - @Before - public void setUp() { - buildRule.configureProject("src/etc/testcases/types/resources/javaresource.xml"); - } - - @Test - public void testLoadManifest() { - buildRule.executeTarget("loadManifest"); - assertNotNull(buildRule.getProject().getProperty("manifest")); - - // this actually relies on the first manifest being found on - // the classpath (probably rt.jar's) being valid - assertTrue(buildRule.getProject().getProperty("manifest") - .startsWith("Manifest-Version:")); - } - - @Test - public void testIsURLProvider() { - JavaResource r = new JavaResource(); - assertSame(r, r.as(URLProvider.class)); - } - - @Test - public void testGetURLOfManifest() { - JavaResource r = new JavaResource(); - r.setName("META-INF/MANIFEST.MF"); - assertNotNull(r.getURL()); - } -} +/* + * 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.types.resources; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +public class JavaResourceTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/types/resources/javaresource.xml"); + } + + @Test + public void testLoadManifest() { + buildRule.executeTarget("loadManifest"); + assertNotNull(buildRule.getProject().getProperty("manifest")); + + // this actually relies on the first manifest being found on + // the classpath (probably rt.jar's) being valid + assertTrue(buildRule.getProject().getProperty("manifest") + .startsWith("Manifest-Version:")); + } + + @Test + public void testIsURLProvider() { + JavaResource r = new JavaResource(); + assertSame(r, r.as(URLProvider.class)); + } + + @Test + public void testGetURLOfManifest() { + JavaResource r = new JavaResource(); + r.setName("META-INF/MANIFEST.MF"); + assertNotNull(r.getURL()); + } +} http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java b/src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java index f91077a..bb85d81 100644 --- a/src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java @@ -1,186 +1,186 @@ -/* - * 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.types.resources; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.NoSuchElementException; - - -import org.apache.tools.ant.types.Resource; -import org.apache.tools.ant.types.ResourceCollection; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -public class LazyResourceCollectionTest { - - private class StringResourceCollection implements ResourceCollection { - List resources = Arrays.<Resource>asList(); - - List createdIterators = new ArrayList(); - - public int size() { - return resources.size(); - } - - public Iterator<Resource> iterator() { - StringResourceIterator it = new StringResourceIterator(); - createdIterators.add(it); - return it; - } - - public boolean isFilesystemOnly() { - return false; - } - } - - private class StringResourceIterator implements Iterator { - int cursor = 0; - - public void remove() { - throw new UnsupportedOperationException(); - } - - public Object next() { - if (cursor < 3) { - cursor++; - return new StringResource("r" + cursor); - } - return null; - } - - public boolean hasNext() { - return cursor < 3; - } - } - - @Test - public void testLazyLoading() throws Exception { - StringResourceCollection collectionTest = new StringResourceCollection(); - LazyResourceCollectionWrapper lazyCollection = new LazyResourceCollectionWrapper(); - lazyCollection.add(collectionTest); - - Iterator<Resource> it = lazyCollection.iterator(); - assertOneCreatedIterator(collectionTest); - StringResourceIterator stringResourceIterator = (StringResourceIterator) collectionTest.createdIterators - .get(0); - assertEquals("A resource was loaded without iterating", 1, - stringResourceIterator.cursor); - - StringResource r = (StringResource) it.next(); - assertOneCreatedIterator(collectionTest); - assertEquals("r1", r.getValue()); - assertEquals("Iterating once load more than 1 resource", 2, - stringResourceIterator.cursor); - - r = (StringResource) it.next(); - assertOneCreatedIterator(collectionTest); - assertEquals("r2", r.getValue()); - assertEquals("Iterating twice load more than 2 resources", 3, - stringResourceIterator.cursor); - - r = (StringResource) it.next(); - assertOneCreatedIterator(collectionTest); - assertEquals("r3", r.getValue()); - assertEquals("Iterating 3 times load more than 3 resources", 3, - stringResourceIterator.cursor); - - try { - it.next(); - fail("NoSuchElementException should have been raised"); - } catch (NoSuchElementException e) { - // ok - } - } - - private void assertOneCreatedIterator( - StringResourceCollection testCollection) { - assertEquals("More than one iterator has been created", 1, - testCollection.createdIterators.size()); - } - - @Test - public void testCaching() throws Exception { - StringResourceCollection collectionTest = new StringResourceCollection(); - LazyResourceCollectionWrapper lazyCollection = new LazyResourceCollectionWrapper(); - lazyCollection.add(collectionTest); - - assertTrue(lazyCollection.isCache()); - Iterator<Resource> it1 = lazyCollection.iterator(); - assertOneCreatedIterator(collectionTest); - Iterator<Resource> it2 = lazyCollection.iterator(); - assertOneCreatedIterator(collectionTest); - - StringResourceIterator stringResourceIterator = (StringResourceIterator) collectionTest.createdIterators - .get(0); - assertEquals("A resource was loaded without iterating", 1, - stringResourceIterator.cursor); - - StringResource r = (StringResource) it1.next(); - assertEquals("r1", r.getValue()); - assertEquals("Iterating once load more than 1 resource", 2, - stringResourceIterator.cursor); - - r = (StringResource) it2.next(); - assertEquals("r1", r.getValue()); - assertEquals( - "The second iterator did not lookup in the cache for a resource", - 2, stringResourceIterator.cursor); - - r = (StringResource) it2.next(); - assertEquals("r2", r.getValue()); - assertEquals("Iterating twice load more than 2 resources", 3, - stringResourceIterator.cursor); - - r = (StringResource) it1.next(); - assertEquals("r2", r.getValue()); - assertEquals( - "The first iterator did not lookup in the cache for a resource", - 3, stringResourceIterator.cursor); - - r = (StringResource) it2.next(); - assertEquals("r3", r.getValue()); - assertEquals("Iterating 3 times load more than 3 resources", 3, - stringResourceIterator.cursor); - - r = (StringResource) it1.next(); - assertEquals("r3", r.getValue()); - assertEquals( - "The first iterator did not lookup in the cache for a resource", - 3, stringResourceIterator.cursor); - - try { - it1.next(); - fail("NoSuchElementException should have been raised"); - } catch (NoSuchElementException e) { - // ok - } - - try { - it2.next(); - fail("NoSuchElementException should have been raised"); - } catch (NoSuchElementException e) { - // ok - } - } -} +/* + * 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.types.resources; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; + + +import org.apache.tools.ant.types.Resource; +import org.apache.tools.ant.types.ResourceCollection; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class LazyResourceCollectionTest { + + private class StringResourceCollection implements ResourceCollection { + List resources = Arrays.<Resource>asList(); + + List createdIterators = new ArrayList(); + + public int size() { + return resources.size(); + } + + public Iterator<Resource> iterator() { + StringResourceIterator it = new StringResourceIterator(); + createdIterators.add(it); + return it; + } + + public boolean isFilesystemOnly() { + return false; + } + } + + private class StringResourceIterator implements Iterator { + int cursor = 0; + + public void remove() { + throw new UnsupportedOperationException(); + } + + public Object next() { + if (cursor < 3) { + cursor++; + return new StringResource("r" + cursor); + } + return null; + } + + public boolean hasNext() { + return cursor < 3; + } + } + + @Test + public void testLazyLoading() throws Exception { + StringResourceCollection collectionTest = new StringResourceCollection(); + LazyResourceCollectionWrapper lazyCollection = new LazyResourceCollectionWrapper(); + lazyCollection.add(collectionTest); + + Iterator<Resource> it = lazyCollection.iterator(); + assertOneCreatedIterator(collectionTest); + StringResourceIterator stringResourceIterator = (StringResourceIterator) collectionTest.createdIterators + .get(0); + assertEquals("A resource was loaded without iterating", 1, + stringResourceIterator.cursor); + + StringResource r = (StringResource) it.next(); + assertOneCreatedIterator(collectionTest); + assertEquals("r1", r.getValue()); + assertEquals("Iterating once load more than 1 resource", 2, + stringResourceIterator.cursor); + + r = (StringResource) it.next(); + assertOneCreatedIterator(collectionTest); + assertEquals("r2", r.getValue()); + assertEquals("Iterating twice load more than 2 resources", 3, + stringResourceIterator.cursor); + + r = (StringResource) it.next(); + assertOneCreatedIterator(collectionTest); + assertEquals("r3", r.getValue()); + assertEquals("Iterating 3 times load more than 3 resources", 3, + stringResourceIterator.cursor); + + try { + it.next(); + fail("NoSuchElementException should have been raised"); + } catch (NoSuchElementException e) { + // ok + } + } + + private void assertOneCreatedIterator( + StringResourceCollection testCollection) { + assertEquals("More than one iterator has been created", 1, + testCollection.createdIterators.size()); + } + + @Test + public void testCaching() throws Exception { + StringResourceCollection collectionTest = new StringResourceCollection(); + LazyResourceCollectionWrapper lazyCollection = new LazyResourceCollectionWrapper(); + lazyCollection.add(collectionTest); + + assertTrue(lazyCollection.isCache()); + Iterator<Resource> it1 = lazyCollection.iterator(); + assertOneCreatedIterator(collectionTest); + Iterator<Resource> it2 = lazyCollection.iterator(); + assertOneCreatedIterator(collectionTest); + + StringResourceIterator stringResourceIterator = (StringResourceIterator) collectionTest.createdIterators + .get(0); + assertEquals("A resource was loaded without iterating", 1, + stringResourceIterator.cursor); + + StringResource r = (StringResource) it1.next(); + assertEquals("r1", r.getValue()); + assertEquals("Iterating once load more than 1 resource", 2, + stringResourceIterator.cursor); + + r = (StringResource) it2.next(); + assertEquals("r1", r.getValue()); + assertEquals( + "The second iterator did not lookup in the cache for a resource", + 2, stringResourceIterator.cursor); + + r = (StringResource) it2.next(); + assertEquals("r2", r.getValue()); + assertEquals("Iterating twice load more than 2 resources", 3, + stringResourceIterator.cursor); + + r = (StringResource) it1.next(); + assertEquals("r2", r.getValue()); + assertEquals( + "The first iterator did not lookup in the cache for a resource", + 3, stringResourceIterator.cursor); + + r = (StringResource) it2.next(); + assertEquals("r3", r.getValue()); + assertEquals("Iterating 3 times load more than 3 resources", 3, + stringResourceIterator.cursor); + + r = (StringResource) it1.next(); + assertEquals("r3", r.getValue()); + assertEquals( + "The first iterator did not lookup in the cache for a resource", + 3, stringResourceIterator.cursor); + + try { + it1.next(); + fail("NoSuchElementException should have been raised"); + } catch (NoSuchElementException e) { + // ok + } + + try { + it2.next(); + fail("NoSuchElementException should have been raised"); + } catch (NoSuchElementException e) { + // ok + } + } +}
