Repository: ant
Updated Branches:
  refs/heads/master cc8563cdf -> 160894d47


Refactor FileSet tests (extract fixtures)

Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/160894d4
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/160894d4
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/160894d4

Branch: refs/heads/master
Commit: 160894d478c504995000f94f7f30b9bcdbeae78b
Parents: cc8563c
Author: Gintas Grigelionis <[email protected]>
Authored: Fri Apr 20 21:08:46 2018 +0200
Committer: Gintas Grigelionis <[email protected]>
Committed: Fri Apr 20 21:11:51 2018 +0200

----------------------------------------------------------------------
 .../tools/ant/types/AbstractFileSetTest.java    | 344 +++++++++----------
 .../org/apache/tools/ant/types/DirSetTest.java  |  50 +--
 .../apache/tools/ant/types/TarFileSetTest.java  | 137 ++++----
 .../apache/tools/ant/types/ZipFileSetTest.java  | 149 ++++----
 .../types/resources/MultiRootFileSetTest.java   | 130 ++++---
 5 files changed, 398 insertions(+), 412 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/160894d4/src/tests/junit/org/apache/tools/ant/types/AbstractFileSetTest.java
----------------------------------------------------------------------
diff --git 
a/src/tests/junit/org/apache/tools/ant/types/AbstractFileSetTest.java 
b/src/tests/junit/org/apache/tools/ant/types/AbstractFileSetTest.java
index a025b2b..4c529c6 100644
--- a/src/tests/junit/org/apache/tools/ant/types/AbstractFileSetTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/AbstractFileSetTest.java
@@ -23,10 +23,11 @@ import java.io.File;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
 
 /**
  * Base class for FileSetTest and DirSetTest.
@@ -39,10 +40,16 @@ public abstract class AbstractFileSetTest {
 
     private Project project;
 
+    private AbstractFileSet f;
+
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
+
     @Before
     public void setUp() {
         project = new Project();
         project.setBasedir(".");
+        f = getInstance();
     }
 
     protected abstract AbstractFileSet getInstance();
@@ -52,216 +59,187 @@ public abstract class AbstractFileSetTest {
     }
 
     @Test
-    public final void testEmptyElementIfIsReference() {
-        AbstractFileSet f = getInstance();
+    public final void testCannotSetIncludesThenRefid() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify more than one attribute 
when using refid");
         f.setIncludes("**/*.java");
-        try {
-            f.setRefid(new Reference(getProject(), "dummyref"));
-            fail("Can add reference to "
-                 + f.getDataTypeName()
-                 + " with elements from setIncludes");
-        } catch (BuildException be) {
-            assertEquals("You must not specify more than one attribute "
-                         + "when using refid", be.getMessage());
-        }
+        f.setRefid(new Reference(getProject(), "dummyref"));
+    }
 
-        f = getInstance();
+    @Test
+    public final void testCannotAddPatternSetThenRefid() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify nested elements when using 
refid");
         f.createPatternSet();
-        try {
-            f.setRefid(new Reference(getProject(), "dummyref"));
-            fail("Can add reference to "
-                 + f.getDataTypeName()
-                 + " with nested patternset element.");
-        } catch (BuildException be) {
-            assertEquals("You must not specify nested elements when "
-                         + "using refid", be.getMessage());
-        }
+        f.setRefid(new Reference(getProject(), "dummyref"));
+    }
 
-        f = getInstance();
+    @Test
+    public final void testCannotAddIncludeThenRefid() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify more than one attribute 
when using refid");
         f.createInclude();
-        try {
-            f.setRefid(new Reference(getProject(), "dummyref"));
-            fail("Can add reference to "
-                 + f.getDataTypeName()
-                 + " with nested include element.");
-        } catch (BuildException be) {
-            assertEquals("You must not specify more than one attribute "
-                         + "when using refid", be.getMessage());
-        }
+        f.setRefid(new Reference(getProject(), "dummyref"));
+    }
 
-        f = getInstance();
+    @Test
+    public final void testCannotSetRefidThenIncludes() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify more than one attribute 
when using refid");
+        f.setRefid(new Reference(getProject(), "dummyref"));
+        f.setIncludes("**/*.java");
+    }
+
+    @Test
+    public final void testCannotSetRefidThenIncludesfile() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify more than one attribute 
when using refid");
         f.setRefid(new Reference(getProject(), "dummyref"));
-        try {
-            f.setIncludes("**/*.java");
-            fail("Can set includes in "
-                 + f.getDataTypeName()
-                 + " 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 "
-                 + f.getDataTypeName()
-                 + " 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 "
-                 + f.getDataTypeName()
-                 + " 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 "
-                 + f.getDataTypeName()
-                 + " 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 "
-                 + f.getDataTypeName()
-                 + " 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 "
-                 + f.getDataTypeName()
-                 + " 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 "
-                 + f.getDataTypeName()
-                 + " 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 "
-                 + f.getDataTypeName()
-                 + " 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 "
-                 + f.getDataTypeName()
-                 + " 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 "
-                 + f.getDataTypeName()
-                 + " that is a reference.");
-        } catch (BuildException be) {
-            assertEquals("You must not specify nested elements when using "
-                         + "refid", be.getMessage());
-        }
+        f.setIncludesfile(new File("/a"));
     }
 
     @Test
-    public void testCircularReferenceCheck() {
-        AbstractFileSet f = getInstance();
+    public final void testCannotSetRefidThenExcludes() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify more than one attribute 
when using refid");
+        f.setRefid(new Reference(getProject(), "dummyref"));
+        f.setExcludes("**/*.java");
+    }
+
+    @Test
+    public final void testCannotSetRefidThenExcludesfile() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify more than one attribute 
when using refid");
+        f.setRefid(new Reference(getProject(), "dummyref"));
+        f.setExcludesfile(new File("/a"));
+    }
+
+    @Test
+    public final void testCannotSetRefidThenDir() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify more than one attribute 
when using refid");
+        f.setRefid(new Reference(getProject(), "dummyref"));
+        f.setDir(project.resolveFile("."));
+    }
+
+    @Test
+    public final void testCannotSetRefidThenAddInclude() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify nested elements when using 
refid");
+        f.setRefid(new Reference(getProject(), "dummyref"));
+        f.createInclude();
+    }
+
+    @Test
+    public final void testCannotSetRefidThenAddExclude() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify nested elements when using 
refid");
+        f.setRefid(new Reference(getProject(), "dummyref"));
+        f.createExclude();
+    }
+
+    @Test
+    public final void testCannotSetRefidThenAddIncludesfile() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify nested elements when using 
refid");
+        f.setRefid(new Reference(getProject(), "dummyref"));
+        f.createIncludesFile();
+    }
+
+    @Test
+    public final void testCannotSetRefidThenAddExcludesFile() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify nested elements when using 
refid");
+        f.setRefid(new Reference(getProject(), "dummyref"));
+        f.createExcludesFile();
+    }
+
+    @Test
+    public final void testCannotSetRefidThenAddPatternset() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify nested elements when using 
refid");
+        f.setRefid(new Reference(getProject(), "dummyref"));
+        f.createPatternSet();
+    }
+
+    @Test
+    public void testCircularReferenceCheckGetDir() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("This data type contains a circular reference.");
+        project.addReference("dummy", f);
+        f.setRefid(new Reference(getProject(), "dummy"));
+        f.getDir(project);
+    }
+
+    @Test
+    public void testCircularReferenceCheckGetDirScanner() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("This data type contains a circular reference.");
         project.addReference("dummy", f);
         f.setRefid(new Reference(getProject(), "dummy"));
-        try {
-            f.getDir(project);
-            fail("Can make " + f.getDataTypeName()
-                 + " a Reference to itself.");
-        } catch (BuildException be) {
-            assertEquals("This data type contains a circular reference.",
-                         be.getMessage());
-        }
-        try {
-            f.getDirectoryScanner(project);
-            fail("Can make " + f.getDataTypeName()
-                 + " a Reference to itself.");
-        } catch (BuildException be) {
-            assertEquals("This data type contains a circular reference.",
-                         be.getMessage());
-        }
+        f.getDirectoryScanner(project);
+    }
+
+    @Test
+    public void testLoopReferenceCheckGetDir() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("This data type contains a circular reference.");
+        // dummy1 --> dummy2 --> dummy3 --> dummy1
+        project.addReference("dummy1", f);
+        f.setRefid(new Reference(getProject(), "dummy2"));
+        AbstractFileSet fa = getInstance();
+        project.addReference("dummy2", fa);
+        fa.setRefid(new Reference(getProject(), "dummy3"));
+        AbstractFileSet fb = getInstance();
+        project.addReference("dummy3", fb);
+        fb.setRefid(new Reference(getProject(), "dummy1"));
+        f.getDir(project);
+    }
 
+    @Test
+    public void testLoopReferenceCheckGetDirScanner() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("This data type contains a circular reference.");
         // dummy1 --> dummy2 --> dummy3 --> dummy1
-        AbstractFileSet f1 = getInstance();
-        project.addReference("dummy1", f1);
-        f1.setRefid(new Reference(getProject(), "dummy2"));
-        AbstractFileSet f2 = getInstance();
-        project.addReference("dummy2", f2);
-        f2.setRefid(new Reference(getProject(), "dummy3"));
-        AbstractFileSet f3 = getInstance();
-        project.addReference("dummy3", f3);
-        f3.setRefid(new Reference(getProject(), "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());
-        }
+        project.addReference("dummy1", f);
+        f.setRefid(new Reference(getProject(), "dummy2"));
+        AbstractFileSet fa = getInstance();
+        project.addReference("dummy2", fa);
+        fa.setRefid(new Reference(getProject(), "dummy3"));
+        AbstractFileSet fb = getInstance();
+        project.addReference("dummy3", fb);
+        fb.setRefid(new Reference(getProject(), "dummy1"));
+        f.getDirectoryScanner(project);
+    }
 
+    @Test
+    public void testLoopReferenceCheck() {
         // dummy1 --> dummy2 --> dummy3
         // (which has the Project's basedir as root).
-        f1 = getInstance();
-        project.addReference("dummy1", f1);
-        f1.setRefid(new Reference(getProject(), "dummy2"));
-        f2 = getInstance();
-        project.addReference("dummy2", f2);
-        f2.setRefid(new Reference(getProject(), "dummy3"));
-        f3 = getInstance();
-        project.addReference("dummy3", f3);
-        f3.setDir(project.resolveFile("."));
-        File dir = f1.getDir(project);
+        project.addReference("dummy1", f);
+        f.setRefid(new Reference(getProject(), "dummy2"));
+        AbstractFileSet fa = getInstance();
+        project.addReference("dummy2", fa);
+        fa.setRefid(new Reference(getProject(), "dummy3"));
+        AbstractFileSet fb = getInstance();
+        project.addReference("dummy3", fb);
+        fb.setDir(project.resolveFile("."));
+        File dir = f.getDir(project);
         assertEquals("Dir is basedir", dir, project.getBaseDir());
     }
 
     @Test
     public void canCallSetFileTwiceWithSameArgument() {
-        AbstractFileSet f = getInstance();
         f.setFile(new File("/a"));
         f.setFile(new File("/a"));
         // really only asserts no exception is thrown
     }
 
     @Test
-    public void cantCallSetFileTwiceWithDifferentArguments() {
-        AbstractFileSet f = getInstance();
+    public void cannotCallSetFileTwiceWithDifferentArguments() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("setFile cannot be called twice with different 
arguments");
         f.setFile(new File("/a"));
-        try {
-            f.setFile(new File("/b"));
-            fail("expected an exception");
-        } catch (BuildException ex) {
-            assertEquals("setFile cannot be called twice with different 
arguments", ex.getMessage());
-        }
+        f.setFile(new File("/b"));
     }
 }

http://git-wip-us.apache.org/repos/asf/ant/blob/160894d4/src/tests/junit/org/apache/tools/ant/types/DirSetTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/types/DirSetTest.java 
b/src/tests/junit/org/apache/tools/ant/types/DirSetTest.java
index e9162f1..6248c21 100644
--- a/src/tests/junit/org/apache/tools/ant/types/DirSetTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/DirSetTest.java
@@ -22,47 +22,53 @@ import java.io.File;
 import java.io.FileOutputStream;
 
 import org.apache.tools.ant.BuildException;
+import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
 
 /**
  * JUnit 4 testcases for org.apache.tools.ant.types.DirSet.
  */
 public class DirSetTest extends AbstractFileSetTest {
 
+    private DirSet ds;
+
+    private FileSet fs;
+
+    @Before
+    public void setUp() {
+        super.setUp();
+        ds = (DirSet) getInstance();
+        ds.setProject(getProject());
+        fs = new FileSet();
+    }
+
     protected AbstractFileSet getInstance() {
         return new DirSet();
     }
 
     @Test
-    public void testFileSetIsNoDirSet() {
-        DirSet ds = (DirSet) getInstance();
-        ds.setProject(getProject());
-        FileSet fs = new FileSet();
+    public void testDirSetFromFileSet() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("dummy doesn\'t denote a DirSet");
         fs.setProject(getProject());
         getProject().addReference("dummy", fs);
         ds.setRefid(new Reference(getProject(), "dummy"));
-        try {
-            ds.getDir(getProject());
-            fail("DirSet created from FileSet reference");
-        } catch (BuildException e) {
-            assertEquals("dummy doesn\'t denote a DirSet", e.getMessage());
-        }
+        ds.getDir(getProject());
+    }
 
-        ds = (DirSet) getInstance();
-        ds.setProject(getProject());
-        getProject().addReference("dummy2", ds);
-        fs.setRefid(new Reference(getProject(), "dummy2"));
-        try {
-            fs.getDir(getProject());
-            fail("FileSet created from DirSet reference");
-        } catch (BuildException e) {
-            assertEquals("dummy2 doesn\'t denote a FileSet", e.getMessage());
-        }
+    @Test
+    public void testFileSetFromDirSet() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("dummy doesn\'t denote a FileSet");
+        getProject().addReference("dummy", ds);
+        fs.setRefid(new Reference(getProject(), "dummy"));
+        fs.getDir(getProject());
     }
 
+    @Test
     public void testToString() throws Exception {
         File tmp = File.createTempFile("DirSetTest", "");
         try {
@@ -75,8 +81,6 @@ public class DirSetTest extends AbstractFileSetTest {
             new FileOutputStream(new File(a, "x")).close();
             new FileOutputStream(new File(b, "x")).close();
             new FileOutputStream(new File(bc, "x")).close();
-            DirSet ds = new DirSet();
-            ds.setProject(getProject());
             ds.setDir(tmp);
             ds.setIncludes("b/");
             assertEquals("b;b" + File.separator + "c", ds.toString());

http://git-wip-us.apache.org/repos/asf/ant/blob/160894d4/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java 
b/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java
index 7d002e5..abe610a 100644
--- a/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java
@@ -21,10 +21,10 @@ package org.apache.tools.ant.types;
 import java.io.File;
 
 import org.apache.tools.ant.BuildException;
+import org.junit.Before;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
 
 /**
  * JUnit 4 testcases for org.apache.tools.ant.types.TarFileSet.
@@ -33,83 +33,82 @@ import static org.junit.Assert.fail;
  */
 public class TarFileSetTest extends AbstractFileSetTest {
 
+    private TarFileSet tfs;
 
     protected AbstractFileSet getInstance() {
         return new TarFileSet();
     }
 
+    @Before
+    public void setUp() {
+        super.setUp();
+        tfs = (TarFileSet) getInstance();
+    }
+
+    //check that dir and src are incompatible
+    @Test
+    public final void testSrcDirAttributes() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("Cannot set both dir and src attributes");
+        tfs.setSrc(new File("example.tar"));
+        tfs.setDir(new File("examples"));
+    }
+
+    //check that dir and src are incompatible
+    @Test
+    public final void testDirSrcAttributes() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("Cannot set both dir and src attributes");
+        tfs.setDir(new File("examples"));
+        tfs.setSrc(new File("example.tar"));
+    }
+
+    //check that fullpath and prefix are incompatible
+    @Test
+    public final void testPrefixFullpathAttributes() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("Cannot set both fullpath and prefix attributes");
+        tfs.setSrc(new File("example.tar"));
+        tfs.setPrefix("/examples");
+        tfs.setFullpath("/doc/manual/index.html");
+    }
+
+    @Test
+    public final void testFullpathPrefixAttributes() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("Cannot set both fullpath and prefix attributes");
+        tfs.setSrc(new File("example.tar"));
+        tfs.setFullpath("/doc/manual/index.html");
+        tfs.setPrefix("/examples");
+    }
+
+    // check that reference tarfilesets cannot have specific attributes
+    @Test
+    public final void testRefidSrcAttributes() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify more than one attribute 
when using refid");
+        tfs.setRefid(new Reference(getProject(), "test"));
+        tfs.setSrc(new File("example.tar"));
+    }
+
+    // check that a reference tarfileset gets the same attributes as the 
original
     @Test
     public final void testAttributes() {
-        TarFileSet f = (TarFileSet) getInstance();
-        //check that dir and src are incompatible
-        f.setSrc(new File("example.tar"));
-        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 = (TarFileSet) getInstance();
-        //check that dir and src are incompatible
-        f.setDir(new File("examples"));
-        try {
-            f.setSrc(new File("example.tar"));
-            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 = (TarFileSet) getInstance();
-        f.setSrc(new File("example.tar"));
-        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 = (TarFileSet) getInstance();
-        f.setSrc(new File("example.tar"));
-        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 tarfilesets cannot have specific attributes
-        f = (TarFileSet) getInstance();
-        f.setRefid(new Reference(getProject(), "test"));
-        try {
-            f.setSrc(new File("example.tar"));
-            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 tarfileset gets the same attributes as the 
original
-        f = (TarFileSet) getInstance();
-        f.setSrc(new File("example.tar"));
-        f.setPrefix("/examples");
-        f.setFileMode("600");
-        f.setDirMode("530");
-        getProject().addReference("test", f);
+        tfs.setSrc(new File("example.tar"));
+        tfs.setPrefix("/examples");
+        tfs.setFileMode("600");
+        tfs.setDirMode("530");
+        getProject().addReference("test", tfs);
         TarFileSet zid = (TarFileSet) getInstance();
         zid.setRefid(new Reference(getProject(), "test"));
-        assertEquals("src attribute copied by copy constructor", 
zid.getSrc(getProject()), f.getSrc(getProject()));
-        assertEquals("prefix attribute copied by copy constructor", 
f.getPrefix(getProject()), zid.getPrefix(getProject()));
-        assertEquals("file mode attribute copied by copy constructor", 
f.getFileMode(getProject()), zid.getFileMode(getProject()));
-        assertEquals("dir mode attribute copied by copy constructor", 
f.getDirMode(getProject()), zid.getDirMode(getProject()));
+        assertEquals("src attribute copied by copy constructor",
+                tfs.getSrc(getProject()), zid.getSrc(getProject()));
+        assertEquals("prefix attribute copied by copy constructor",
+                tfs.getPrefix(getProject()), zid.getPrefix(getProject()));
+        assertEquals("file mode attribute copied by copy constructor",
+                tfs.getFileMode(getProject()), zid.getFileMode(getProject()));
+        assertEquals("dir mode attribute copied by copy constructor",
+                tfs.getDirMode(getProject()), zid.getDirMode(getProject()));
       }
 
 }

http://git-wip-us.apache.org/repos/asf/ant/blob/160894d4/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 b4637da..ad8f63f 100644
--- a/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java
@@ -21,10 +21,10 @@ package org.apache.tools.ant.types;
 import java.io.File;
 
 import org.apache.tools.ant.BuildException;
+import org.junit.Before;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
 
 /**
  * JUnit 4 testcases for org.apache.tools.ant.types.ZipFileSet.
@@ -33,84 +33,95 @@ import static org.junit.Assert.fail;
  */
 public class ZipFileSetTest extends AbstractFileSetTest {
 
+    private ZipFileSet zfs;
+
     protected AbstractFileSet getInstance() {
         return new ZipFileSet();
     }
 
+    @Before
+    public void setUp() {
+        super.setUp();
+        zfs = (ZipFileSet) getInstance();
+    }
+
+    /**
+     * check that dir and src are incompatible
+     */
+    @Test
+    public final void testSrcDirAttributes() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("Cannot set both dir and src attributes");
+        zfs.setSrc(new File("example.zip"));
+        zfs.setDir(new File("examples"));
+    }
+
+    /**
+     * check that dir and src are incompatible
+     */
+    @Test
+    public final void testDirSrcAttributes() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("Cannot set both dir and src attributes");
+        zfs.setDir(new File("examples"));
+        zfs.setSrc(new File("example.zip"));
+    }
+
+    /**
+     * check that fullpath and prefix are incompatible
+     */
+    @Test
+    public final void testPrefixFullpathAttributes() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("Cannot set both fullpath and prefix attributes");
+        zfs.setSrc(new File("example.zip"));
+        zfs.setPrefix("/examples");
+        zfs.setFullpath("/doc/manual/index.html");
+    }
+
+    /**
+     * check that fullpath and prefix are incompatible
+     */
+    @Test
+    public final void testFullpathPrefixAttributes() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("Cannot set both fullpath and prefix attributes");
+        zfs.setSrc(new File("example.zip"));
+        zfs.setFullpath("/doc/manual/index.html");
+        zfs.setPrefix("/examples");
+    }
+
+    /**
+     * check that reference zipfilesets cannot have specific attributes
+     */
+    @Test
+    public final void testRefidSrcAttributes() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify more than one attribute 
when using refid");
+        zfs.setRefid(new Reference(getProject(), "test"));
+        zfs.setSrc(new File("example.zip"));
+    }
+
+    /**
+     * check that a reference zipfileset gets the same attributes as the 
original
+     */
     @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);
+        zfs.setSrc(new File("example.zip"));
+        zfs.setPrefix("/examples");
+        zfs.setFileMode("600");
+        zfs.setDirMode("530");
+        getProject().addReference("test", zfs);
         ZipFileSet zid = (ZipFileSet) getInstance();
         zid.setRefid(new Reference(getProject(), "test"));
-        assertEquals("src attribute copied by copy constructor", 
zid.getSrc(getProject()), f.getSrc(getProject()));
-        assertEquals("prefix attribute copied by copy constructor", 
f.getPrefix(getProject()), zid.getPrefix(getProject()));
+        assertEquals("src attribute copied by copy constructor",
+                zfs.getSrc(getProject()), zid.getSrc(getProject()));
+        assertEquals("prefix attribute copied by copy constructor",
+                zfs.getPrefix(getProject()), zid.getPrefix(getProject()));
         assertEquals("file mode attribute copied by copy constructor",
-                f.getFileMode(getProject()), zid.getFileMode(getProject()));
+                zfs.getFileMode(getProject()), zid.getFileMode(getProject()));
         assertEquals("dir mode attribute copied by copy constructor",
-                f.getDirMode(getProject()), zid.getDirMode(getProject()));
+                zfs.getDirMode(getProject()), zid.getDirMode(getProject()));
       }
 
 }

http://git-wip-us.apache.org/repos/asf/ant/blob/160894d4/src/tests/junit/org/apache/tools/ant/types/resources/MultiRootFileSetTest.java
----------------------------------------------------------------------
diff --git 
a/src/tests/junit/org/apache/tools/ant/types/resources/MultiRootFileSetTest.java
 
b/src/tests/junit/org/apache/tools/ant/types/resources/MultiRootFileSetTest.java
index 2676632..de5a5a3 100644
--- 
a/src/tests/junit/org/apache/tools/ant/types/resources/MultiRootFileSetTest.java
+++ 
b/src/tests/junit/org/apache/tools/ant/types/resources/MultiRootFileSetTest.java
@@ -25,17 +25,26 @@ import org.apache.tools.ant.Project;
 import org.apache.tools.ant.types.AbstractFileSet;
 import org.apache.tools.ant.types.AbstractFileSetTest;
 import org.apache.tools.ant.types.Reference;
+import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.hamcrest.Matchers.endsWith;
 
 /**
  * This doesn't actually test much, mainly reference handling.
  */
 public class MultiRootFileSetTest extends AbstractFileSetTest {
 
+    private MultiRootFileSet multiRootFileSet;
+
+    @Before
+    public void setUp() {
+        super.setUp();
+        multiRootFileSet = new MultiRootFileSet();
+    }
+
     protected AbstractFileSet getInstance() {
         return new MultiRootFileSet() {
             // overriding so set/getDir works as expected by the base test 
class
@@ -58,73 +67,58 @@ public class MultiRootFileSetTest extends 
AbstractFileSetTest {
     }
 
     @Test
-    public void testEmptyElementIfIsReferenceAdditionalAttributes() {
-        MultiRootFileSet f = new MultiRootFileSet();
-        f.setProject(getProject());
-        f.setBaseDirs("a");
-        try {
-            f.setRefid(new Reference(getProject(), "dummyref"));
-            fail("Can add reference to multirootfileset "
-                 + " with elements from setBasedirs");
-        } catch (BuildException be) {
-            assertEquals("You must not specify more than one attribute "
-                         + "when using refid", be.getMessage());
-        }
-        f = new MultiRootFileSet();
-        f.addConfiguredBaseDir(new FileResource(new File(".")));
-        try {
-            f.setRefid(new Reference(getProject(), "dummyref"));
-            fail("Can add reference to multirootfileset"
-                 + " with elements from addConfiguredBaseDir");
-        } catch (BuildException be) {
-            assertEquals("You must not specify more than one attribute "
-                         + "when using refid", be.getMessage());
-        }
-
-        f = new MultiRootFileSet();
-        f.setRefid(new Reference(getProject(), "dummyref"));
-        try {
-            f.setBaseDirs("a");
-            fail("Can set basedirs in multirootfileset"
-                 + " that is a reference.");
-        } catch (BuildException be) {
-            assertEquals("You must not specify more than one attribute "
-                         + "when using refid", be.getMessage());
-        }
-        try {
-            f.setCache(true);
-            fail("Can set cache in multirootfileset"
-                 + " that is a reference.");
-        } catch (BuildException be) {
-            assertEquals("You must not specify more than one attribute "
-                         + "when using refid", be.getMessage());
-        }
-        try {
-            f.setType(MultiRootFileSet.SetType.file);
-            fail("Can set type in multirootfileset"
-                 + " that is a reference.");
-        } catch (BuildException be) {
-            assertEquals("You must not specify more than one attribute "
-                         + "when using refid", be.getMessage());
-        }
-        try {
-            f.addConfiguredBaseDir(new FileResource(new File(".")));
-            fail("Can add nested basedir in multirootfileset "
-                 + " that is a reference.");
-        } catch (BuildException be) {
-            assertEquals("You must not specify nested elements when using "
-                         + "refid", be.getMessage());
-        }
+    public void testCannotSetBaseDirsThenRefid() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify more than one attribute 
when using refid");
+        multiRootFileSet.setProject(getProject());
+        multiRootFileSet.setBaseDirs("a");
+        multiRootFileSet.setRefid(new Reference(getProject(), "dummyref"));
+    }
+
+    @Test
+    public void testCannotSetConfiguredBaseDirThenRefid() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify more than one attribute 
when using refid");
+        multiRootFileSet.addConfiguredBaseDir(new FileResource(new File(".")));
+        multiRootFileSet.setRefid(new Reference(getProject(), "dummyref"));
+    }
+
+    @Test
+    public void testCannotSetRefidThenBaseDirs() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify more than one attribute 
when using refid");
+        multiRootFileSet.setRefid(new Reference(getProject(), "dummyref"));
+        multiRootFileSet.setBaseDirs("a");
+    }
+
+    @Test
+    public void testCannotSetRefidThenCache() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify more than one attribute 
when using refid");
+        multiRootFileSet.setRefid(new Reference(getProject(), "dummyref"));
+        multiRootFileSet.setCache(true);
+    }
+
+    @Test
+    public void testCannotSetRefidThenType() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify more than one attribute 
when using refid");
+        multiRootFileSet.setRefid(new Reference(getProject(), "dummyref"));
+        multiRootFileSet.setType(MultiRootFileSet.SetType.file);
+    }
+
+    @Test
+    public void testCannotSetRefidThenConfiguredBaseDir() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify nested elements when using 
refid");
+        multiRootFileSet.setRefid(new Reference(getProject(), "dummyref"));
+        multiRootFileSet.addConfiguredBaseDir(new FileResource(new File(".")));
     }
 
     @Test
-    public void testDirCannotBeSet() {
-        try {
-            new MultiRootFileSet().setDir(new File("."));
-            fail("Can set dir in a multirootfileset");
-        } catch (BuildException e) {
-            assertTrue(e.getMessage()
-                       .endsWith(" doesn't support the dir attribute"));
-        }
+    public void testCannotSetDir() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage(endsWith(" doesn't support the dir attribute"));
+        multiRootFileSet.setDir(new File("."));
     }
 }

Reply via email to