From 98d509c6f8d7774190e9c8579510f34df1c4ac2a Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 3 Apr 2002 11:38:33 +0000 Subject: [PATCH] reimplement DirSetTest as subclass of FileSetTest git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272183 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/types/DirSet.java | 11 +- .../apache/tools/ant/types/DirSetTest.java | 200 ++---------------- .../apache/tools/ant/types/FileSetTest.java | 30 ++- 3 files changed, 33 insertions(+), 208 deletions(-) diff --git a/src/main/org/apache/tools/ant/types/DirSet.java b/src/main/org/apache/tools/ant/types/DirSet.java index c70c8710f..21a55e0e9 100644 --- a/src/main/org/apache/tools/ant/types/DirSet.java +++ b/src/main/org/apache/tools/ant/types/DirSet.java @@ -54,18 +54,11 @@ package org.apache.tools.ant.types; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.FileScanner; -import org.apache.tools.ant.DirectoryScanner; -import org.apache.tools.ant.Project; - -import java.io.File; -import java.util.Stack; -import java.util.Vector; - /** * Subclass as hint for supporting tasks that the included directories * instead of files should be used. + * + * @since Ant 1.5 */ public class DirSet extends FileSet { diff --git a/src/testcases/org/apache/tools/ant/types/DirSetTest.java b/src/testcases/org/apache/tools/ant/types/DirSetTest.java index a0979b810..0893170c2 100644 --- a/src/testcases/org/apache/tools/ant/types/DirSetTest.java +++ b/src/testcases/org/apache/tools/ant/types/DirSetTest.java @@ -55,218 +55,42 @@ package org.apache.tools.ant.types; import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; - -import junit.framework.TestCase; -import junit.framework.AssertionFailedError; - -import java.io.File; /** * JUnit 3 testcases for org.apache.tools.ant.types.DirSet. * - *

This doesn't actually test much, mainly reference handling. - * * @author Stefan Bodewig */ - -public class DirSetTest extends TestCase { - - private Project project; +public class DirSetTest extends FileSetTest { public DirSetTest(String name) { super(name); } - public void setUp() { - project = new Project(); - project.setBasedir("."); - } - - public void testEmptyElementIfIsReference() { - DirSet f = new DirSet(); - f.setIncludes("**/*.java"); - try { - f.setRefid(new Reference("dummyref")); - fail("Can add reference to DirSet with elements from setIncludes"); - } catch (BuildException be) { - assertEquals("You must not specify more than one attribute when using refid", - be.getMessage()); - } - - f = new DirSet(); - f.createPatternSet(); - try { - f.setRefid(new Reference("dummyref")); - fail("Can add reference to DirSet with nested patternset element."); - } catch (BuildException be) { - assertEquals("You must not specify nested elements when using refid", - be.getMessage()); - } - - f = new DirSet(); - f.createInclude(); - try { - f.setRefid(new Reference("dummyref")); - fail("Can add reference to DirSet with nested include element."); - } catch (BuildException be) { - assertEquals("You must not specify more than one attribute when using refid", - be.getMessage()); - } - - f = new DirSet(); - f.setRefid(new Reference("dummyref")); - try { - f.setIncludes("**/*.java"); - fail("Can set includes in DirSet that is a reference."); - } catch (BuildException be) { - assertEquals("You must not specify more than one attribute when using refid", - be.getMessage()); - } - try { - f.setIncludesfile(new File("/a")); - fail("Can set includesfile in DirSet that is a reference."); - } catch (BuildException be) { - assertEquals("You must not specify more than one attribute when using refid", - be.getMessage()); - } - try { - f.setExcludes("**/*.java"); - fail("Can set excludes in DirSet that is a reference."); - } catch (BuildException be) { - assertEquals("You must not specify more than one attribute when using refid", - be.getMessage()); - } - try { - f.setExcludesfile(new File("/a")); - fail("Can set excludesfile in DirSet that is a reference."); - } catch (BuildException be) { - assertEquals("You must not specify more than one attribute when using refid", - be.getMessage()); - } - try { - f.setDir(project.resolveFile(".")); - fail("Can set dir in DirSet that is a reference."); - } catch (BuildException be) { - assertEquals("You must not specify more than one attribute when using refid", - be.getMessage()); - } - try { - f.createInclude(); - fail("Can add nested include in DirSet that is a reference."); - } catch (BuildException be) { - assertEquals("You must not specify nested elements when using refid", - be.getMessage()); - } - try { - f.createExclude(); - fail("Can add nested exclude in DirSet that is a reference."); - } catch (BuildException be) { - assertEquals("You must not specify nested elements when using refid", - be.getMessage()); - } - try { - f.createIncludesFile(); - fail("Can add nested includesfile in DirSet that is a reference."); - } catch (BuildException be) { - assertEquals("You must not specify nested elements when using refid", - be.getMessage()); - } - try { - f.createExcludesFile(); - fail("Can add nested excludesfile in DirSet that is a reference."); - } catch (BuildException be) { - assertEquals("You must not specify nested elements when using refid", - be.getMessage()); - } - try { - f.createPatternSet(); - fail("Can add nested patternset in DirSet that is a reference."); - } catch (BuildException be) { - assertEquals("You must not specify nested elements when using refid", - be.getMessage()); - } - } - - public void testCircularReferenceCheck() { - DirSet f = new DirSet(); - project.addReference("dummy", f); - f.setRefid(new Reference("dummy")); - try { - f.getDir(project); - fail("Can make DirSet a Reference to itself."); - } catch (BuildException be) { - assertEquals("This data type contains a circular reference.", - be.getMessage()); - } - try { - f.getDirectoryScanner(project); - fail("Can make DirSet a Reference to itself."); - } catch (BuildException be) { - assertEquals("This data type contains a circular reference.", - be.getMessage()); - } - - // dummy1 --> dummy2 --> dummy3 --> dummy1 - DirSet f1 = new DirSet(); - project.addReference("dummy1", f1); - f1.setRefid(new Reference("dummy2")); - DirSet f2 = new DirSet(); - project.addReference("dummy2", f2); - f2.setRefid(new Reference("dummy3")); - DirSet f3 = new DirSet(); - project.addReference("dummy3", f3); - f3.setRefid(new Reference("dummy1")); - try { - f1.getDir(project); - fail("Can make circular reference."); - } catch (BuildException be) { - assertEquals("This data type contains a circular reference.", - be.getMessage()); - } - try { - f1.getDirectoryScanner(project); - fail("Can make circular reference."); - } catch (BuildException be) { - assertEquals("This data type contains a circular reference.", - be.getMessage()); - } - - // dummy1 --> dummy2 --> dummy3 - // (which has the Project's basedir as root). - f1 = new DirSet(); - project.addReference("dummy1", f1); - f1.setRefid(new Reference("dummy2")); - f2 = new DirSet(); - project.addReference("dummy2", f2); - f2.setRefid(new Reference("dummy3")); - f3 = new DirSet(); - project.addReference("dummy3", f3); - f3.setDir(project.resolveFile(".")); - File dir = f1.getDir(project); - assertEquals("Dir is basedir", dir, project.getBaseDir()); + protected FileSet getInstance() { + return new DirSet(); } public void testFileSetIsNoDirSet() { - DirSet ds = new DirSet(); - ds.setProject(project); + DirSet ds = (DirSet) getInstance(); + ds.setProject(getProject()); FileSet fs = new FileSet(); - fs.setProject(project); - project.addReference("dummy", fs); + fs.setProject(getProject()); + getProject().addReference("dummy", fs); ds.setRefid(new Reference("dummy")); try { - ds.getDir(project); + ds.getDir(getProject()); fail("DirSet created from FileSet reference"); } catch (BuildException e) { assertEquals("dummy doesn\'t denote a dirset", e.getMessage()); } - ds = new DirSet(); - ds.setProject(project); - project.addReference("dummy2", ds); + ds = (DirSet) getInstance(); + ds.setProject(getProject()); + getProject().addReference("dummy2", ds); fs.setRefid(new Reference("dummy2")); try { - fs.getDir(project); + fs.getDir(getProject()); fail("FileSet created from DirSet reference"); } catch (BuildException e) { assertEquals("dummy2 doesn\'t denote a fileset", e.getMessage()); diff --git a/src/testcases/org/apache/tools/ant/types/FileSetTest.java b/src/testcases/org/apache/tools/ant/types/FileSetTest.java index 9d5a1d24f..f874aad23 100644 --- a/src/testcases/org/apache/tools/ant/types/FileSetTest.java +++ b/src/testcases/org/apache/tools/ant/types/FileSetTest.java @@ -83,8 +83,16 @@ public class FileSetTest extends TestCase { project.setBasedir("."); } + protected FileSet getInstance() { + return new FileSet(); + } + + protected Project getProject() { + return project; + } + public void testEmptyElementIfIsReference() { - FileSet f = new FileSet(); + FileSet f = getInstance(); f.setIncludes("**/*.java"); try { f.setRefid(new Reference("dummyref")); @@ -94,7 +102,7 @@ public class FileSetTest extends TestCase { be.getMessage()); } - f = new FileSet(); + f = getInstance(); f.createPatternSet(); try { f.setRefid(new Reference("dummyref")); @@ -104,7 +112,7 @@ public class FileSetTest extends TestCase { be.getMessage()); } - f = new FileSet(); + f = getInstance(); f.createInclude(); try { f.setRefid(new Reference("dummyref")); @@ -114,7 +122,7 @@ public class FileSetTest extends TestCase { be.getMessage()); } - f = new FileSet(); + f = getInstance(); f.setRefid(new Reference("dummyref")); try { f.setIncludes("**/*.java"); @@ -189,7 +197,7 @@ public class FileSetTest extends TestCase { } public void testCircularReferenceCheck() { - FileSet f = new FileSet(); + FileSet f = getInstance(); project.addReference("dummy", f); f.setRefid(new Reference("dummy")); try { @@ -208,13 +216,13 @@ public class FileSetTest extends TestCase { } // dummy1 --> dummy2 --> dummy3 --> dummy1 - FileSet f1 = new FileSet(); + FileSet f1 = getInstance(); project.addReference("dummy1", f1); f1.setRefid(new Reference("dummy2")); - FileSet f2 = new FileSet(); + FileSet f2 = getInstance(); project.addReference("dummy2", f2); f2.setRefid(new Reference("dummy3")); - FileSet f3 = new FileSet(); + FileSet f3 = getInstance(); project.addReference("dummy3", f3); f3.setRefid(new Reference("dummy1")); try { @@ -234,13 +242,13 @@ public class FileSetTest extends TestCase { // dummy1 --> dummy2 --> dummy3 // (which has the Project's basedir as root). - f1 = new FileSet(); + f1 = getInstance(); project.addReference("dummy1", f1); f1.setRefid(new Reference("dummy2")); - f2 = new FileSet(); + f2 = getInstance(); project.addReference("dummy2", f2); f2.setRefid(new Reference("dummy3")); - f3 = new FileSet(); + f3 = getInstance(); project.addReference("dummy3", f3); f3.setDir(project.resolveFile(".")); File dir = f1.getDir(project);