http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/selectors/DependSelectorTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/DependSelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/DependSelectorTest.java index ec95878..078052f 100644 --- a/src/tests/junit/org/apache/tools/ant/types/selectors/DependSelectorTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/selectors/DependSelectorTest.java @@ -1,185 +1,185 @@ -/* - * 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.selectors; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.types.Mapper; -import org.junit.Rule; -import org.junit.Test; - -import java.io.File; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - - -/** - * Tests Depend Selectors - * - */ -public class DependSelectorTest { - - @Rule - public final BaseSelectorRule selectorRule = new BaseSelectorRule(); - - @Test - public void testValidateSingleMapper() { - try { - DependSelector s = new DependSelector(); - s.createMapper(); - s.createMapper(); - fail("DependSelector allowed more than one nested mapper."); - } catch (BuildException be1) { - assertEquals("Cannot define more than one mapper", - be1.getMessage()); - } - } - - - @Test - public void testValidateRequiredFields() { - try { - DependSelector s = new DependSelector(); - s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0], selectorRule.getFiles()[0]); - fail("DependSelector did not check for required fields"); - } catch (BuildException be2) { - assertEquals("The targetdir attribute is required.", - be2.getMessage()); - } - - } - - @Test - public void testNoMapper() { - DependSelector s = new DependSelector(); - s.setTargetdir(selectorRule.getBeddir()); - - String results = selectorRule.selectionString(s); - assertEquals("FFFFFFFFFFFF", results); - } - - @Test - public void testIdentityMapper() { - DependSelector s = new DependSelector(); - s.setTargetdir(selectorRule.getBeddir()); - - Mapper.MapperType identity = new Mapper.MapperType(); - identity.setValue("identity"); - - Mapper m = s.createMapper(); - m.setType(identity); - - String results = selectorRule.selectionString(s); - assertEquals("FFFFFFFFFFFF", results); - } - - @Test - public void testMergeMapper() { - DependSelector s = new DependSelector(); - s.setTargetdir(selectorRule.getBeddir()); - - Mapper.MapperType merge = new Mapper.MapperType(); - merge.setValue("merge"); - - Mapper m = s.createMapper(); - m.setType(merge); - m.setTo("asf-logo.gif.gz"); - - String results = selectorRule.selectionString(s); - assertEquals("TFFFFTTTFFF", results.substring(0,11)); - } - - @Test - public void testMergeMapper2() { - DependSelector s = new DependSelector(); - s.setTargetdir(selectorRule.getBeddir()); - - Mapper.MapperType merge = new Mapper.MapperType(); - merge.setValue("merge"); - - Mapper m = s.createMapper(); - m.setType(merge); - m.setTo("asf-logo.gif.bz2"); - String results = selectorRule.selectionString(s); - assertEquals("TTFTTTTTTTTT", results); - } - - @Test - public void testGlobMapperRelativePath() { - DependSelector s = new DependSelector(); - File subdir = new File("selectortest/tar/bz2"); - s.setTargetdir(subdir); - - Mapper.MapperType glob = new Mapper.MapperType(); - glob.setValue("glob"); - - Mapper m = s.createMapper(); - m.setType(glob); - m.setFrom("*.bz2"); - m.setTo("*.tar.bz2"); - - String results = selectorRule.selectionString(s); - assertEquals("FFTFFFFFFTTF", results); - } - - @Test - public void testRestrictedGlobMapper() { - DependSelector s = new DependSelector(); - File subdir = new File(selectorRule.getBeddir(), "tar/bz2"); - s.setTargetdir(subdir); - - Mapper.MapperType glob = new Mapper.MapperType(); - glob.setValue("glob"); - - Mapper m = s.createMapper(); - m.setType(glob); - m.setFrom("*.bz2"); - m.setTo("*.tar.bz2"); - String results = selectorRule.selectionString(s); - assertEquals("FFFFFFFFFTTF", results); - } - - @Test - public void testSelectionNoMapper() { - DependSelector s = new DependSelector(); - s.setTargetdir(new File(selectorRule.getOutputDir(), "selectortest2")); - String results = selectorRule.selectionString(s); - assertEquals("FFFTTFFFFFFF", results); - } - - - @Test - public void testMirroredSelection() { - DependSelector s = new DependSelector(); - s.setTargetdir(new File(selectorRule.getOutputDir(), "selectortest2/tar/bz2")); - - Mapper.MapperType glob = new Mapper.MapperType(); - glob.setValue("glob"); - - Mapper m = s.createMapper(); - m.setType(glob); - m.setFrom("*.bz2"); - m.setTo("*.tar.bz2"); - String results = selectorRule.mirrorSelectionString(s); - assertEquals("FFFFFFFFFTTF", results); - results = selectorRule.selectionString(s); - assertEquals("FFFFFFFFFTTF", results); - } - -} +/* + * 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.selectors; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.types.Mapper; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + + +/** + * Tests Depend Selectors + * + */ +public class DependSelectorTest { + + @Rule + public final BaseSelectorRule selectorRule = new BaseSelectorRule(); + + @Test + public void testValidateSingleMapper() { + try { + DependSelector s = new DependSelector(); + s.createMapper(); + s.createMapper(); + fail("DependSelector allowed more than one nested mapper."); + } catch (BuildException be1) { + assertEquals("Cannot define more than one mapper", + be1.getMessage()); + } + } + + + @Test + public void testValidateRequiredFields() { + try { + DependSelector s = new DependSelector(); + s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0], selectorRule.getFiles()[0]); + fail("DependSelector did not check for required fields"); + } catch (BuildException be2) { + assertEquals("The targetdir attribute is required.", + be2.getMessage()); + } + + } + + @Test + public void testNoMapper() { + DependSelector s = new DependSelector(); + s.setTargetdir(selectorRule.getBeddir()); + + String results = selectorRule.selectionString(s); + assertEquals("FFFFFFFFFFFF", results); + } + + @Test + public void testIdentityMapper() { + DependSelector s = new DependSelector(); + s.setTargetdir(selectorRule.getBeddir()); + + Mapper.MapperType identity = new Mapper.MapperType(); + identity.setValue("identity"); + + Mapper m = s.createMapper(); + m.setType(identity); + + String results = selectorRule.selectionString(s); + assertEquals("FFFFFFFFFFFF", results); + } + + @Test + public void testMergeMapper() { + DependSelector s = new DependSelector(); + s.setTargetdir(selectorRule.getBeddir()); + + Mapper.MapperType merge = new Mapper.MapperType(); + merge.setValue("merge"); + + Mapper m = s.createMapper(); + m.setType(merge); + m.setTo("asf-logo.gif.gz"); + + String results = selectorRule.selectionString(s); + assertEquals("TFFFFTTTFFF", results.substring(0,11)); + } + + @Test + public void testMergeMapper2() { + DependSelector s = new DependSelector(); + s.setTargetdir(selectorRule.getBeddir()); + + Mapper.MapperType merge = new Mapper.MapperType(); + merge.setValue("merge"); + + Mapper m = s.createMapper(); + m.setType(merge); + m.setTo("asf-logo.gif.bz2"); + String results = selectorRule.selectionString(s); + assertEquals("TTFTTTTTTTTT", results); + } + + @Test + public void testGlobMapperRelativePath() { + DependSelector s = new DependSelector(); + File subdir = new File("selectortest/tar/bz2"); + s.setTargetdir(subdir); + + Mapper.MapperType glob = new Mapper.MapperType(); + glob.setValue("glob"); + + Mapper m = s.createMapper(); + m.setType(glob); + m.setFrom("*.bz2"); + m.setTo("*.tar.bz2"); + + String results = selectorRule.selectionString(s); + assertEquals("FFTFFFFFFTTF", results); + } + + @Test + public void testRestrictedGlobMapper() { + DependSelector s = new DependSelector(); + File subdir = new File(selectorRule.getBeddir(), "tar/bz2"); + s.setTargetdir(subdir); + + Mapper.MapperType glob = new Mapper.MapperType(); + glob.setValue("glob"); + + Mapper m = s.createMapper(); + m.setType(glob); + m.setFrom("*.bz2"); + m.setTo("*.tar.bz2"); + String results = selectorRule.selectionString(s); + assertEquals("FFFFFFFFFTTF", results); + } + + @Test + public void testSelectionNoMapper() { + DependSelector s = new DependSelector(); + s.setTargetdir(new File(selectorRule.getOutputDir(), "selectortest2")); + String results = selectorRule.selectionString(s); + assertEquals("FFFTTFFFFFFF", results); + } + + + @Test + public void testMirroredSelection() { + DependSelector s = new DependSelector(); + s.setTargetdir(new File(selectorRule.getOutputDir(), "selectortest2/tar/bz2")); + + Mapper.MapperType glob = new Mapper.MapperType(); + glob.setValue("glob"); + + Mapper m = s.createMapper(); + m.setType(glob); + m.setFrom("*.bz2"); + m.setTo("*.tar.bz2"); + String results = selectorRule.mirrorSelectionString(s); + assertEquals("FFFFFFFFFTTF", results); + results = selectorRule.selectionString(s); + assertEquals("FFFFFFFFFTTF", results); + } + +}
http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/selectors/DepthSelectorTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/DepthSelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/DepthSelectorTest.java index 391fb27..924995c 100644 --- a/src/tests/junit/org/apache/tools/ant/types/selectors/DepthSelectorTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/selectors/DepthSelectorTest.java @@ -1,147 +1,147 @@ -/* - * 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.selectors; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.types.Parameter; -import org.junit.Rule; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -/** - * Tests Depth Selectors - * - */ -public class DepthSelectorTest { - - @Rule - public final BaseSelectorRule selectorRule = new BaseSelectorRule(); - - - /** - * Test the code that validates the selector. - */ - @Test - public void testValidate() { - DepthSelector s = new DepthSelector(); - try { - s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); - fail("DepthSelector did not check for required fields"); - } catch (BuildException be1) { - assertEquals("You must set at least one of the min or the " + - "max levels.", be1.getMessage()); - } - - s = new DepthSelector(); - s.setMin(5); - s.setMax(2); - try { - s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); - fail("DepthSelector did not check for maximum being higher " - + "than minimum"); - } catch (BuildException be2) { - assertEquals("The maximum depth is lower than the minimum.", - be2.getMessage()); - } - - s = new DepthSelector(); - Parameter param = new Parameter(); - param.setName("garbage in"); - param.setValue("garbage out"); - Parameter[] params = new Parameter[1]; - params[0] = param; - s.setParameters(params); - try { - s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); - fail("DepthSelector did not check for valid parameter element"); - } catch (BuildException be3) { - assertEquals("Invalid parameter garbage in", be3.getMessage()); - } - - s = new DepthSelector(); - param = new Parameter(); - param.setName("min"); - param.setValue("garbage out"); - params[0] = param; - s.setParameters(params); - try { - s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); - fail("DepthSelector accepted bad minimum as parameter"); - } catch (BuildException be4) { - assertEquals("Invalid minimum value garbage out", - be4.getMessage()); - } - - s = new DepthSelector(); - param = new Parameter(); - param.setName("max"); - param.setValue("garbage out"); - params[0] = param; - s.setParameters(params); - try { - s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); - fail("DepthSelector accepted bad maximum as parameter"); - } catch (BuildException be5) { - assertEquals("Invalid maximum value garbage out", - be5.getMessage()); - } - - } - - /** - * Tests to make sure that the selector is selecting files correctly. - */ - @Test - public void testSelectionBehaviour() { - DepthSelector s; - String results; - - s = new DepthSelector(); - s.setMin(20); - s.setMax(25); - results = selectorRule.selectionString(s); - assertEquals("FFFFFFFFFFFF", results); - - s = new DepthSelector(); - s.setMin(0); - results = selectorRule.selectionString(s); - assertEquals("TTTTTTTTTTTT", results); - - s = new DepthSelector(); - s.setMin(1); - results = selectorRule.selectionString(s); - assertEquals("FFFFFTTTTTTT", results); - - s = new DepthSelector(); - s.setMax(0); - results = selectorRule.selectionString(s); - assertEquals("TTTTTFFFFFFF", results); - - s = new DepthSelector(); - s.setMin(1); - s.setMax(1); - results = selectorRule.selectionString(s); - assertEquals("FFFFFTTTFFFT", results); - - - } - -} +/* + * 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.selectors; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.types.Parameter; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * Tests Depth Selectors + * + */ +public class DepthSelectorTest { + + @Rule + public final BaseSelectorRule selectorRule = new BaseSelectorRule(); + + + /** + * Test the code that validates the selector. + */ + @Test + public void testValidate() { + DepthSelector s = new DepthSelector(); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("DepthSelector did not check for required fields"); + } catch (BuildException be1) { + assertEquals("You must set at least one of the min or the " + + "max levels.", be1.getMessage()); + } + + s = new DepthSelector(); + s.setMin(5); + s.setMax(2); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("DepthSelector did not check for maximum being higher " + + "than minimum"); + } catch (BuildException be2) { + assertEquals("The maximum depth is lower than the minimum.", + be2.getMessage()); + } + + s = new DepthSelector(); + Parameter param = new Parameter(); + param.setName("garbage in"); + param.setValue("garbage out"); + Parameter[] params = new Parameter[1]; + params[0] = param; + s.setParameters(params); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("DepthSelector did not check for valid parameter element"); + } catch (BuildException be3) { + assertEquals("Invalid parameter garbage in", be3.getMessage()); + } + + s = new DepthSelector(); + param = new Parameter(); + param.setName("min"); + param.setValue("garbage out"); + params[0] = param; + s.setParameters(params); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("DepthSelector accepted bad minimum as parameter"); + } catch (BuildException be4) { + assertEquals("Invalid minimum value garbage out", + be4.getMessage()); + } + + s = new DepthSelector(); + param = new Parameter(); + param.setName("max"); + param.setValue("garbage out"); + params[0] = param; + s.setParameters(params); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("DepthSelector accepted bad maximum as parameter"); + } catch (BuildException be5) { + assertEquals("Invalid maximum value garbage out", + be5.getMessage()); + } + + } + + /** + * Tests to make sure that the selector is selecting files correctly. + */ + @Test + public void testSelectionBehaviour() { + DepthSelector s; + String results; + + s = new DepthSelector(); + s.setMin(20); + s.setMax(25); + results = selectorRule.selectionString(s); + assertEquals("FFFFFFFFFFFF", results); + + s = new DepthSelector(); + s.setMin(0); + results = selectorRule.selectionString(s); + assertEquals("TTTTTTTTTTTT", results); + + s = new DepthSelector(); + s.setMin(1); + results = selectorRule.selectionString(s); + assertEquals("FFFFFTTTTTTT", results); + + s = new DepthSelector(); + s.setMax(0); + results = selectorRule.selectionString(s); + assertEquals("TTTTTFFFFFFF", results); + + s = new DepthSelector(); + s.setMin(1); + s.setMax(1); + results = selectorRule.selectionString(s); + assertEquals("FFFFFTTTFFFT", results); + + + } + +} http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/selectors/FilenameSelectorTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/FilenameSelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/FilenameSelectorTest.java index ce7729a..121f433 100644 --- a/src/tests/junit/org/apache/tools/ant/types/selectors/FilenameSelectorTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/selectors/FilenameSelectorTest.java @@ -1,115 +1,115 @@ -/* - * 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.selectors; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.types.Parameter; -import org.junit.Rule; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -/** - * Tests Filename Selectors - * - */ -public class FilenameSelectorTest { - - @Rule - public final BaseSelectorRule selectorRule = new BaseSelectorRule(); - - /** - * Test the code that validates the selector. - */ - @Test - public void testValidate() { - FilenameSelector s = new FilenameSelector(); - try { - s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); - fail("FilenameSelector did not check for required fields"); - } catch (BuildException be1) { - assertEquals("The name or regex attribute is required", be1.getMessage()); - } - - s = new FilenameSelector(); - Parameter param = new Parameter(); - param.setName("garbage in"); - param.setValue("garbage out"); - Parameter[] params = {param}; - s.setParameters(params); - try { - s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); - fail("FilenameSelector did not check for valid parameter element"); - } catch (BuildException be2) { - assertEquals("Invalid parameter garbage in", be2.getMessage()); - } - - } - - /** - * Tests to make sure that the selector is selecting files correctly. - */ - @Test - public void testSelectionBehaviour() { - FilenameSelector s; - String results; - - - s = new FilenameSelector(); - s.setName("no match possible"); - results = selectorRule.selectionString(s); - assertEquals("FFFFFFFFFFFF", results); - - s = new FilenameSelector(); - s.setName("*.gz"); - results = selectorRule.selectionString(s); - // This is turned off temporarily. There appears to be a bug - // in SelectorUtils.matchPattern() where it is recursive on - // Windows even if no ** is in pattern. - //assertEquals("FFFTFFFFFFFF", results); // Unix - // vs - //assertEquals("FFFTFFFFTFFF", results); // Windows - - s = new FilenameSelector(); - s.setName("**/*.gz"); - s.setNegate(true); - results = selectorRule.selectionString(s); - assertEquals("TTTFTTTFFTTT", results); - - s = new FilenameSelector(); - s.setName("**/*.GZ"); - s.setCasesensitive(false); - results = selectorRule.selectionString(s); - assertEquals("FFFTFFFTTFFF", results); - - s = new FilenameSelector(); - Parameter param1 = new Parameter(); - param1.setName("name"); - param1.setValue("**/*.bz2"); - Parameter[] params = {param1}; - s.setParameters(params); - results = selectorRule.selectionString(s); - assertEquals("FFTFFFFFFTTF", results); - - - - } - -} +/* + * 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.selectors; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.types.Parameter; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * Tests Filename Selectors + * + */ +public class FilenameSelectorTest { + + @Rule + public final BaseSelectorRule selectorRule = new BaseSelectorRule(); + + /** + * Test the code that validates the selector. + */ + @Test + public void testValidate() { + FilenameSelector s = new FilenameSelector(); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("FilenameSelector did not check for required fields"); + } catch (BuildException be1) { + assertEquals("The name or regex attribute is required", be1.getMessage()); + } + + s = new FilenameSelector(); + Parameter param = new Parameter(); + param.setName("garbage in"); + param.setValue("garbage out"); + Parameter[] params = {param}; + s.setParameters(params); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("FilenameSelector did not check for valid parameter element"); + } catch (BuildException be2) { + assertEquals("Invalid parameter garbage in", be2.getMessage()); + } + + } + + /** + * Tests to make sure that the selector is selecting files correctly. + */ + @Test + public void testSelectionBehaviour() { + FilenameSelector s; + String results; + + + s = new FilenameSelector(); + s.setName("no match possible"); + results = selectorRule.selectionString(s); + assertEquals("FFFFFFFFFFFF", results); + + s = new FilenameSelector(); + s.setName("*.gz"); + results = selectorRule.selectionString(s); + // This is turned off temporarily. There appears to be a bug + // in SelectorUtils.matchPattern() where it is recursive on + // Windows even if no ** is in pattern. + //assertEquals("FFFTFFFFFFFF", results); // Unix + // vs + //assertEquals("FFFTFFFFTFFF", results); // Windows + + s = new FilenameSelector(); + s.setName("**/*.gz"); + s.setNegate(true); + results = selectorRule.selectionString(s); + assertEquals("TTTFTTTFFTTT", results); + + s = new FilenameSelector(); + s.setName("**/*.GZ"); + s.setCasesensitive(false); + results = selectorRule.selectionString(s); + assertEquals("FFFTFFFTTFFF", results); + + s = new FilenameSelector(); + Parameter param1 = new Parameter(); + param1.setName("name"); + param1.setValue("**/*.bz2"); + Parameter[] params = {param1}; + s.setParameters(params); + results = selectorRule.selectionString(s); + assertEquals("FFTFFFFFFTTF", results); + + + + } + +} http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/selectors/MockAlgorithm.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/MockAlgorithm.java b/src/tests/junit/org/apache/tools/ant/types/selectors/MockAlgorithm.java index 458c83f..c741952 100644 --- a/src/tests/junit/org/apache/tools/ant/types/selectors/MockAlgorithm.java +++ b/src/tests/junit/org/apache/tools/ant/types/selectors/MockAlgorithm.java @@ -1,37 +1,37 @@ -/* - * 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.selectors; - - -import java.io.File; -import org.apache.tools.ant.types.selectors.modifiedselector.Algorithm; - -public class MockAlgorithm implements Algorithm { - public boolean isValid() { - return true; - } - - public String getValue(File file) { - return "TEST"; - } - - public String toString() { - return "MockAlgorithm@" + hashCode(); - } -} +/* + * 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.selectors; + + +import java.io.File; +import org.apache.tools.ant.types.selectors.modifiedselector.Algorithm; + +public class MockAlgorithm implements Algorithm { + public boolean isValid() { + return true; + } + + public String getValue(File file) { + return "TEST"; + } + + public String toString() { + return "MockAlgorithm@" + hashCode(); + } +} http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/selectors/MockCache.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/MockCache.java b/src/tests/junit/org/apache/tools/ant/types/selectors/MockCache.java index e501a6b..6fc87f3 100644 --- a/src/tests/junit/org/apache/tools/ant/types/selectors/MockCache.java +++ b/src/tests/junit/org/apache/tools/ant/types/selectors/MockCache.java @@ -1,68 +1,68 @@ -/* - * 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.selectors; - - -import java.util.Iterator; -import org.apache.tools.ant.types.selectors.modifiedselector.Cache; - -public class MockCache implements Cache { - - public boolean debug = false; - public boolean saved = false; - - - public MockCache() { - log("()"); - } - - public boolean isValid() { - log(".isValid()"); - return true; - } - public void delete() { - log(".delete()"); - } - public void load() { - log(".load()"); - } - public void save() { - log(".save()"); - saved = true; - } - public Object get(Object key) { - log(".get("+key+")"); - return key; - } - public void put(Object key, Object value) { - log(".put("+key+", "+value+")"); - saved = false; - } - public Iterator<String> iterator() { - log("iterator()"); - return null; - } - public String toString() { - return "MockCache@" + hashCode(); - } - - private void log(String msg) { - if (debug) System.out.println(this+msg); - } -}//class-MockCache +/* + * 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.selectors; + + +import java.util.Iterator; +import org.apache.tools.ant.types.selectors.modifiedselector.Cache; + +public class MockCache implements Cache { + + public boolean debug = false; + public boolean saved = false; + + + public MockCache() { + log("()"); + } + + public boolean isValid() { + log(".isValid()"); + return true; + } + public void delete() { + log(".delete()"); + } + public void load() { + log(".load()"); + } + public void save() { + log(".save()"); + saved = true; + } + public Object get(Object key) { + log(".get("+key+")"); + return key; + } + public void put(Object key, Object value) { + log(".put("+key+", "+value+")"); + saved = false; + } + public Iterator<String> iterator() { + log("iterator()"); + return null; + } + public String toString() { + return "MockCache@" + hashCode(); + } + + private void log(String msg) { + if (debug) System.out.println(this+msg); + } +}//class-MockCache http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/selectors/MockComparator.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/MockComparator.java b/src/tests/junit/org/apache/tools/ant/types/selectors/MockComparator.java index a7c1553..fdbb75d 100644 --- a/src/tests/junit/org/apache/tools/ant/types/selectors/MockComparator.java +++ b/src/tests/junit/org/apache/tools/ant/types/selectors/MockComparator.java @@ -1,32 +1,32 @@ -/* - * 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.selectors; - -import java.util.Comparator; - -public class MockComparator implements Comparator { - - public int compare(Object o1, Object o2) { - return 0; - } - - public String toString() { - return "MockComparator"; - } -}//class-MockCache +/* + * 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.selectors; + +import java.util.Comparator; + +public class MockComparator implements Comparator { + + public int compare(Object o1, Object o2) { + return 0; + } + + public String toString() { + return "MockComparator"; + } +}//class-MockCache
