You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by mc...@apache.org on 2014/04/18 23:00:43 UTC

svn commit: r1588563 [14/16] - in /ant/core/trunk: ./ manual/ manual/Types/ src/etc/testcases/taskdefs/ src/etc/testcases/taskdefs/optional/ src/etc/testcases/taskdefs/optional/antlr/ src/etc/testcases/taskdefs/optional/depend/ src/etc/testcases/taskde...

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java Fri Apr 18 21:00:38 2014
@@ -19,24 +19,33 @@
 package org.apache.tools.ant.types;
 
 import java.io.File;
+import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 
 import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
 import javax.xml.transform.sax.SAXSource;
 
-import junit.framework.TestCase;
-
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.util.JAXPUtils;
+import org.junit.Before;
+import org.junit.Test;
 import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertNotNull;
 
 /**
  * JUnit testcases for org.apache.tools.ant.types.XMLCatalog
  *
  */
-public class XMLCatalogTest extends TestCase {
+public class XMLCatalogTest {
 
     private Project project;
     private XMLCatalog catalog;
@@ -47,14 +56,11 @@ public class XMLCatalogTest extends Test
         return cat;
     }
 
-    private String toURLString(File file) throws MalformedURLException {
+    private static String toURLString(File file) throws MalformedURLException {
         return JAXPUtils.getSystemId(file);
     }
 
-    public XMLCatalogTest(String name) {
-        super(name);
-    }
-
+    @Before
     public void setUp() {
         project = new Project();
         project.setBasedir(System.getProperty("root"));
@@ -71,11 +77,7 @@ public class XMLCatalogTest extends Test
         catalog = newCatalog();
     }
 
-    public void tearDown() {
-        project = null;
-        catalog = null;
-    }
-
+    @Test
     public void testEmptyCatalog() {
         try {
             InputSource result = catalog.resolveEntity("PUBLIC ID ONE",
@@ -116,34 +118,28 @@ public class XMLCatalogTest extends Test
         return resultStr;
     }
 
-    public void testNonExistentEntry() {
+    @Test
+    public void testNonExistentEntry() throws IOException, SAXException, TransformerException {
 
         ResourceLocation dtd = new ResourceLocation();
         dtd.setPublicId("PUBLIC ID ONE");
         dtd.setLocation("i/dont/exist.dtd");
 
-        try {
-            InputSource result = catalog.resolveEntity("PUBLIC ID ONE",
-                                                       "i/dont/exist.dtd");
-            assertNull("Nonexistent Catalog entry should not be returned", result);
-        } catch (Exception e) {
-            fail("resolveEntity() failed!" + e.toString());
-        }
-
-        try {
-            Source result = catalog.resolve("i/dont/exist.dtd", null);
-            String expected = toURLString(new File(project.getBaseDir().toURL() +
-                                                   "/i/dont/exist.dtd"));
-            String resultStr =
-                fileURLPartWithoutLeadingSlashes((SAXSource)result);
-            assertTrue("Nonexistent Catalog entry return input with a system ID like "
-                       + expected + " but was " + resultStr,
-                       expected.endsWith(resultStr));
-        } catch (Exception e) {
-            fail("resolve() failed!" + e.toString());
-        }
+        InputSource isResult = catalog.resolveEntity("PUBLIC ID ONE",
+                                                   "i/dont/exist.dtd");
+        assertNull("Nonexistent Catalog entry should not be returned", isResult);
+
+        Source result = catalog.resolve("i/dont/exist.dtd", null);
+        String expected = toURLString(new File(project.getBaseDir().toURL() +
+                                               "/i/dont/exist.dtd"));
+        String resultStr =
+            fileURLPartWithoutLeadingSlashes((SAXSource)result);
+        assertTrue("Nonexistent Catalog entry return input with a system ID like "
+                   + expected + " but was " + resultStr,
+                   expected.endsWith(resultStr));
     }
 
+    @Test
     public void testEmptyElementIfIsReference() {
         ResourceLocation dtd = new ResourceLocation();
         dtd.setPublicId("PUBLIC ID ONE");
@@ -171,7 +167,8 @@ public class XMLCatalogTest extends Test
         }
     }
 
-    public void testCircularReferenceCheck() {
+    @Test
+    public void testCircularReferenceCheck() throws IOException, SAXException {
 
         // catalog <--> catalog
         project.addReference("catalog", catalog);
@@ -201,20 +198,19 @@ public class XMLCatalogTest extends Test
         catalog1.setRefid(new Reference(project, "catalog2"));
 
         try {
-            InputSource result = catalog1.resolveEntity("PUBLIC ID ONE",
+            catalog1.resolveEntity("PUBLIC ID ONE",
                                                         "i/dont/exist.dtd");
             fail("Can make circular reference");
         } catch (BuildException be) {
             assertEquals("This data type contains a circular reference.",
-                         be.getMessage());
-        } catch (Exception e) {
-            fail("resolveEntity() failed!" + e.toString());
+                    be.getMessage());
         }
     }
     // inspired by Bugzilla Report 23913
     // a problem used to happen under Windows when the location of the DTD was given as an absolute path
     // possibly with a mixture of file separators
-    public void testAbsolutePath() {
+    @Test
+    public void testAbsolutePath() throws IOException, SAXException {
         ResourceLocation dtd = new ResourceLocation();
         dtd.setPublicId("-//stevo//DTD doc 1.0//EN");
 
@@ -223,19 +219,17 @@ public class XMLCatalogTest extends Test
         catalog.addDTD(dtd);
         File dtdFile = project.resolveFile(sysid);
 
-        try {
-            InputSource result = catalog.resolveEntity("-//stevo//DTD doc 1.0//EN",
-                                                       "nap:chemical+brothers");
-            assertNotNull(result);
-            assertEquals(toURLString(dtdFile),
-                         result.getSystemId());
-        } catch (Exception e) {
-            fail("resolveEntity() failed!" + e.toString());
-        }
+        InputSource result = catalog.resolveEntity("-//stevo//DTD doc 1.0//EN",
+                                                   "nap:chemical+brothers");
+        assertNotNull(result);
+        assertEquals(toURLString(dtdFile),
+                     result.getSystemId());
+
 
     }
 
-    public void testSimpleEntry() {
+    @Test
+    public void testSimpleEntry() throws IOException, SAXException {
 
         ResourceLocation dtd = new ResourceLocation();
         dtd.setPublicId("-//stevo//DTD doc 1.0//EN");
@@ -244,18 +238,16 @@ public class XMLCatalogTest extends Test
         catalog.addDTD(dtd);
         File dtdFile = project.resolveFile(sysid);
 
-        try {
-            InputSource result = catalog.resolveEntity("-//stevo//DTD doc 1.0//EN",
-                                                       "nap:chemical+brothers");
-            assertNotNull(result);
-            assertEquals(toURLString(dtdFile),
-                         result.getSystemId());
-        } catch (Exception e) {
-            fail("resolveEntity() failed!" + e.toString());
-        }
+        InputSource result = catalog.resolveEntity("-//stevo//DTD doc 1.0//EN",
+                                                   "nap:chemical+brothers");
+        assertNotNull(result);
+        assertEquals(toURLString(dtdFile),
+                     result.getSystemId());
+
     }
 
-    public void testEntryReference() {
+    @Test
+    public void testEntryReference() throws IOException, SAXException, TransformerException {
 
         String publicId = "-//stevo//DTD doc 1.0//EN";
         String sysid = "src/etc/testcases/taskdefs/optional/xml/doc.dtd";
@@ -286,28 +278,22 @@ public class XMLCatalogTest extends Test
         catalog1.setRefid(new Reference(project, "catalog"));
         catalog2.setRefid(new Reference(project, "catalog1"));
 
-        try {
-            InputSource result = catalog2.resolveEntity(publicId,
-                                                        "nap:chemical+brothers");
+        InputSource isResult = catalog2.resolveEntity(publicId,
+                                                    "nap:chemical+brothers");
+
+        assertNotNull(isResult);
+        assertEquals(toURLString(dtdFile),
+                     isResult.getSystemId());
 
-            assertNotNull(result);
-            assertEquals(toURLString(dtdFile),
-                         result.getSystemId());
-        } catch (Exception e) {
-            fail("resolveEntity() failed!" + e.toString());
-        }
 
-        try {
             Source result = catalog.resolve(uri, null);
             assertNotNull(result);
             assertEquals(toURLString(xmlFile),
                          result.getSystemId());
-        } catch (Exception e) {
-            fail("resolve() failed!" + e.toString());
-        }
     }
 
-    public void testNestedCatalog() {
+    @Test
+    public void testNestedCatalog() throws IOException, SAXException, TransformerException {
 
         String publicId = "-//stevo//DTD doc 1.0//EN";
         String dtdLoc = "src/etc/testcases/taskdefs/optional/xml/doc.dtd";
@@ -330,37 +316,25 @@ public class XMLCatalogTest extends Test
         XMLCatalog catalog1 = newCatalog();
         catalog1.addConfiguredXMLCatalog(catalog);
 
-        try {
-            InputSource result = catalog1.resolveEntity(publicId,
-                                                        "nap:chemical+brothers");
-            assertNotNull(result);
-            assertEquals(toURLString(dtdFile),
-                         result.getSystemId());
-        } catch (Exception e) {
-            fail("resolveEntity() failed!" + e.toString());
-        }
+        InputSource isResult = catalog1.resolveEntity(publicId,
+                                                    "nap:chemical+brothers");
+        assertNotNull(isResult);
+        assertEquals(toURLString(dtdFile),
+                     isResult.getSystemId());
 
-        try {
-            Source result = catalog.resolve(uri, null);
-            assertNotNull(result);
-            assertEquals(toURLString(xmlFile),
-                         result.getSystemId());
-        } catch (Exception e) {
-            fail("resolve() failed!" + e.toString());
-        }
+        Source result = catalog.resolve(uri, null);
+        assertNotNull(result);
+        assertEquals(toURLString(xmlFile),
+                     result.getSystemId());
 
     }
 
-    public void testResolverBase() {
+    @Test
+    public void testResolverBase() throws MalformedURLException, TransformerException {
 
         String uri = "http://foo.com/bar/blah.xml";
         String uriLoc = "etc/testcases/taskdefs/optional/xml/about.xml";
-        String base = null;
-        try {
-            base = toURLString(project.getBaseDir()) + "/src/";
-        } catch (MalformedURLException ex) {
-            fail (ex.toString());
-        }
+        String base = toURLString(project.getBaseDir()) + "/src/";
 
         ResourceLocation entity = new ResourceLocation();
         entity.setPublicId(uri);
@@ -368,17 +342,15 @@ public class XMLCatalogTest extends Test
         catalog.addEntity(entity);
         File xmlFile = project.resolveFile("src/" + uriLoc);
 
-        try {
-            Source result = catalog.resolve(uri, base);
-            assertNotNull(result);
-            assertEquals(toURLString(xmlFile),
-                         result.getSystemId());
-        } catch (Exception e) {
-            fail("resolve() failed!" + e.toString());
-        }
+        Source result = catalog.resolve(uri, base);
+        assertNotNull(result);
+        assertEquals(toURLString(xmlFile),
+                     result.getSystemId());
+
     }
 
-    public void testClasspath() {
+    @Test
+    public void testClasspath() throws IOException, TransformerException, SAXException {
 
 
         String publicId = "-//stevo//DTD doc 1.0//EN";
@@ -405,23 +377,16 @@ public class XMLCatalogTest extends Test
         aPath.append(new Path(project, path2));
         catalog.setClasspath(aPath);
 
-        try {
-            InputSource result = catalog.resolveEntity(publicId,
-                                                       "nap:chemical+brothers");
-            assertNotNull(result);
-            String resultStr = new URL(result.getSystemId()).getFile();
-            assertTrue(toURLString(dtdFile).endsWith(resultStr));
-        } catch (Exception e) {
-            fail("resolveEntity() failed!" + e.toString());
-        }
+        InputSource isResult = catalog.resolveEntity(publicId,
+                                                   "nap:chemical+brothers");
+        assertNotNull(isResult);
+        String resultStr1 = new URL(isResult.getSystemId()).getFile();
+        assertTrue(toURLString(dtdFile).endsWith(resultStr1));
+
+        Source result = catalog.resolve(uri, null);
+        assertNotNull(result);
+        String resultStr = new URL(result.getSystemId()).getFile();
+        assertTrue(toURLString(xmlFile).endsWith(resultStr));
 
-        try {
-            Source result = catalog.resolve(uri, null);
-            assertNotNull(result);
-            String resultStr = new URL(result.getSystemId()).getFile();
-            assertTrue(toURLString(xmlFile).endsWith(resultStr));
-        } catch (Exception e) {
-            fail("resolve() failed!" + e.toString());
-        }
     }
 }

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java Fri Apr 18 21:00:38 2014
@@ -21,6 +21,11 @@ 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.
@@ -31,13 +36,11 @@ import org.apache.tools.ant.BuildExcepti
 
 public class ZipFileSetTest extends AbstractFileSetTest {
 
-    public ZipFileSetTest(String name) {
-        super(name);
-    }
-
     protected AbstractFileSet getInstance() {
         return new ZipFileSet();
     }
+
+    @Test
     public final void testAttributes() {
         ZipFileSet f = (ZipFileSet)getInstance();
         //check that dir and src are incompatible

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/mappers/GlobMapperTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/mappers/GlobMapperTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/mappers/GlobMapperTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/mappers/GlobMapperTest.java Fri Apr 18 21:00:38 2014
@@ -18,25 +18,31 @@
 
 package org.apache.tools.ant.types.mappers;
 
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
 
 /**
  * Testcase for the &lt;globmapper&gt; mapper.
  *
  */
-public class GlobMapperTest extends BuildFileTest {
-    public GlobMapperTest(String name) {
-        super(name);
-    }
+public class GlobMapperTest {
+
+    @Rule
+    public BuildFileRule buildRule = new BuildFileRule();
+
+    @Before
     public void setUp() {
-        configureProject("src/etc/testcases/types/mappers/globmapper.xml");
+        buildRule.configureProject("src/etc/testcases/types/mappers/globmapper.xml");
     }
 
+    @Test
     public void testIgnoreCase() {
-        executeTarget("ignore.case");
+        buildRule.executeTarget("ignore.case");
     }
     public void testHandleDirSep() {
-        executeTarget("handle.dirsep");
+        buildRule.executeTarget("handle.dirsep");
     }
 }
 

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/mappers/RegexpPatternMapperTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/mappers/RegexpPatternMapperTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/mappers/RegexpPatternMapperTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/mappers/RegexpPatternMapperTest.java Fri Apr 18 21:00:38 2014
@@ -18,25 +18,33 @@
 
 package org.apache.tools.ant.types.mappers;
 
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
 
 /**
  * Testcase for the &lt;regexpmapper&gt; mapper.
  *
  */
-public class RegexpPatternMapperTest extends BuildFileTest {
-    public RegexpPatternMapperTest(String name) {
-        super(name);
-    }
+public class RegexpPatternMapperTest {
+
+    @Rule
+    public BuildFileRule buildRule = new BuildFileRule();
+
+    @Before
     public void setUp() {
-        configureProject("src/etc/testcases/types/mappers/regexpmapper.xml");
+        buildRule.configureProject("src/etc/testcases/types/mappers/regexpmapper.xml");
     }
 
+    @Test
     public void testIgnoreCase() {
-        executeTarget("ignore.case");
+        buildRule.executeTarget("ignore.case");
     }
+
+    @Test
     public void testHandleDirSep() {
-        executeTarget("handle.dirsep");
+        buildRule.executeTarget("handle.dirsep");
     }
 }
 

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/optional/ScriptMapperTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/optional/ScriptMapperTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/optional/ScriptMapperTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/optional/ScriptMapperTest.java Fri Apr 18 21:00:38 2014
@@ -18,27 +18,36 @@
 
 package org.apache.tools.ant.types.optional;
 
-import org.apache.tools.ant.BuildFileTest;
+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 extends BuildFileTest {
-    public ScriptMapperTest(String name) {
-        super(name);
-    }
+public class ScriptMapperTest {
+
+    @Rule
+    public BuildFileRule buildRule = new BuildFileRule();
 
+    @Before
     public void setUp() {
-        configureProject("src/etc/testcases/types/mappers/scriptmapper.xml");
+        buildRule.configureProject("src/etc/testcases/types/mappers/scriptmapper.xml");
     }
 
+    @Test
     public void testClear() {
-        executeTarget("testClear");
+        buildRule.executeTarget("testClear");
     }
+
+    @Test
     public void testSetMultiple() {
-        executeTarget("testSetMultiple");
+        buildRule.executeTarget("testSetMultiple");
     }
+
+    @Test
     public void testPassthrough() {
-        executeTarget("testPassthrough");
+        buildRule.executeTarget("testPassthrough");
     }
 }

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/optional/ScriptSelectorTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/optional/ScriptSelectorTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/optional/ScriptSelectorTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/optional/ScriptSelectorTest.java Fri Apr 18 21:00:38 2014
@@ -17,45 +17,67 @@
  */
 package org.apache.tools.ant.types.optional;
 
-import org.apache.tools.ant.BuildFileTest;
+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 extends BuildFileTest {
-
+public class ScriptSelectorTest {
 
-    public ScriptSelectorTest(String name) {
-        super(name);
-    }
+    @Rule
+    public BuildFileRule buildRule = new BuildFileRule();
 
+    @Before
     public void setUp() {
-        configureProject("src/etc/testcases/types/selectors/scriptselector.xml");
+        buildRule.configureProject("src/etc/testcases/types/selectors/scriptselector.xml");
     }
 
+    @Test
     public void testNolanguage() {
-        expectBuildExceptionContaining("testNolanguage",
-                "Absence of language attribute not detected",
-                "script language must be specified");
+        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() {
-        executeTarget("testSelectionSetByDefault");
+        buildRule.executeTarget("testSelectionSetByDefault");
     }
+
+    @Test
     public void testSelectionSetWorks() {
-        executeTarget("testSelectionSetWorks");
+        buildRule.executeTarget("testSelectionSetWorks");
     }
+
+    @Test
     public void testSelectionClearWorks() {
-        executeTarget("testSelectionClearWorks");
+        buildRule.executeTarget("testSelectionClearWorks");
     }
+
+    @Test
     public void testFilenameAttribute() {
-        executeTarget("testFilenameAttribute");
+        buildRule.executeTarget("testFilenameAttribute");
     }
+
+    @Test
     public void testFileAttribute() {
-        executeTarget("testFileAttribute");
+        buildRule.executeTarget("testFileAttribute");
     }
+
+    @Test
     public void testBasedirAttribute() {
-        executeTarget("testBasedirAttribute");
+        buildRule.executeTarget("testBasedirAttribute");
     }
 
 }

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/optional/depend/ClassFileSetTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/optional/depend/ClassFileSetTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/optional/depend/ClassFileSetTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/optional/depend/ClassFileSetTest.java Fri Apr 18 21:00:38 2014
@@ -21,33 +21,40 @@ package org.apache.tools.ant.types.optio
 import java.io.File;
 import java.util.Hashtable;
 
-import org.apache.tools.ant.BuildFileTest;
+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 extends BuildFileTest {
+public class ClassFileSetTest {
     public static final String RESULT_FILESET = "result";
 
-    public ClassFileSetTest(String name) {
-        super(name);
-    }
+    @Rule
+    public BuildFileRule buildRule = new BuildFileRule();
 
+    @Before
     public void setUp() {
         // share the setup for testing the depend task
-        configureProject("src/etc/testcases/taskdefs/optional/depend/depend.xml");
+        buildRule.configureProject("src/etc/testcases/taskdefs/optional/depend/depend.xml");
     }
 
     /**
      * Test basic classfileset
      */
+    @Test
     public void testBasicSet() {
-        Project p = getProject();
-        executeTarget("testbasicset");
+        Project p = buildRule.getProject();
+        buildRule.executeTarget("testbasicset");
         FileSet resultFileSet = (FileSet)p.getReference(RESULT_FILESET);
         DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p);
         String[] scannedFiles = scanner.getIncludedFiles();
@@ -70,9 +77,10 @@ public class ClassFileSetTest extends Bu
     /**
      * Test small classfileset
      */
+    @Test
     public void testSmallSet() {
-        Project p = getProject();
-        executeTarget("testsmallset");
+        Project p = buildRule.getProject();
+        buildRule.executeTarget("testsmallset");
         FileSet resultFileSet = (FileSet)p.getReference(RESULT_FILESET);
         DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p);
         String[] scannedFiles = scanner.getIncludedFiles();
@@ -91,9 +99,10 @@ public class ClassFileSetTest extends Bu
     /**
      * Test combo classfileset
      */
+    @Test
     public void testComboSet() {
-        Project p = getProject();
-        executeTarget("testcomboset");
+        Project p = buildRule.getProject();
+        buildRule.executeTarget("testcomboset");
         FileSet resultFileSet = (FileSet)p.getReference(RESULT_FILESET);
         DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p);
         String[] scannedFiles = scanner.getIncludedFiles();
@@ -110,16 +119,18 @@ public class ClassFileSetTest extends Bu
     /**
      * Test that you can pass a classfileset by reference to a fileset.
      */
+    @Test
     public void testByReference() {
-        executeTarget("testbyreference");
+        buildRule.executeTarget("testbyreference");
     }
 
     /**
      * Test that classes included in a method "System.out.println(MyClass.class)" are included.
      */
+    @Test
     public void testMethodParam() {
-        Project p = getProject();
-        executeTarget("testmethodparam");
+        Project p = buildRule.getProject();
+        buildRule.executeTarget("testmethodparam");
         FileSet resultFileSet = (FileSet)p.getReference(RESULT_FILESET);
         DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p);
         String[] scannedFiles = scanner.getIncludedFiles();
@@ -144,9 +155,10 @@ public class ClassFileSetTest extends Bu
     /**
      * Test that classes included in a method "System.out.println(Outer.Inner.class)" are included.
      */
+    @Test
     public void testMethodParamInner() {
-        Project p = getProject();
-        executeTarget("testmethodparaminner");
+        Project p = buildRule.getProject();
+        buildRule.executeTarget("testmethodparaminner");
         FileSet resultFileSet = (FileSet)p.getReference(RESULT_FILESET);
         DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p);
         String[] scannedFiles = scanner.getIncludedFiles();
@@ -166,8 +178,9 @@ public class ClassFileSetTest extends Bu
             files.containsKey("test" + File.separator + "MethodParam.class"));
     }
 
+    @Test
     public void testResourceCollection() {
-        executeTarget("testresourcecollection");
+        buildRule.executeTarget("testresourcecollection");
     }
 
 }

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java Fri Apr 18 21:00:38 2014
@@ -21,19 +21,24 @@ import java.io.File;
 
 import org.apache.tools.ant.Project;
 
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
 
 /**
  * Test Java API of {@link FileResource}.
  */
-public class FileResourceTest extends TestCase {
+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);
@@ -43,6 +48,7 @@ public class FileResourceTest extends Te
         assertEquals("foo", f.getName());
     }
 
+    @Test
     public void testNonImmediateBasedir() {
         FileResource f = new FileResource();
         f.setBaseDir(root);
@@ -52,6 +58,7 @@ public class FileResourceTest extends Te
         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());
@@ -59,6 +66,7 @@ public class FileResourceTest extends Te
         assertEquals("foo", f.getName());
     }
 
+    @Test
     public void testBasedirAndName() {
         FileResource f = new FileResource(root, "foo");
         assertEquals(new File(root, "foo"), f.getFile());
@@ -66,6 +74,7 @@ public class FileResourceTest extends Te
         assertEquals("foo", f.getName());
     }
 
+    @Test
     public void testNonImmediateBasedirAndName() {
         FileResource f = new FileResource(root, "foo/bar");
         assertEquals(new File(root, "foo/bar"), f.getFile());
@@ -73,6 +82,7 @@ public class FileResourceTest extends Te
         assertEquals("foo/bar", f.getName().replace(File.separatorChar, '/'));
     }
 
+    @Test
     public void testProjectAndFilename() {
         Project p = new Project();
         p.setBaseDir(root);
@@ -82,6 +92,7 @@ public class FileResourceTest extends Te
         assertEquals("foo", f.getName());
     }
 
+    @Test
     public void testRelativeFactoryResource() {
         FileResource f = new FileResource(root, "foo");
         FileResource relative = f.getResource("bar").as(FileResource.class);
@@ -90,6 +101,7 @@ public class FileResourceTest extends Te
         assertEquals(root, relative.getBaseDir());
     }
 
+    @Test
     public void testAbsoluteFactoryResource() {
         FileResource f = new FileResource(new File(root, "foo/a"));
         assertEquals(new File(root, "foo"), f.getBaseDir());
@@ -99,6 +111,7 @@ public class FileResourceTest extends Te
         assertEquals(root, fromFactory.getBaseDir());
     }
 
+    @Test
     public void testParentSiblingFactoryResource() {
         FileResource f = new FileResource(new File(root, "foo/a"));
         assertEquals(new File(root, "foo"), f.getBaseDir());

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/JavaResourceTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/JavaResourceTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/JavaResourceTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/JavaResourceTest.java Fri Apr 18 21:00:38 2014
@@ -17,33 +17,43 @@
  */
 package org.apache.tools.ant.types.resources;
 
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
 
-public class JavaResourceTest extends BuildFileTest {
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
 
-    public JavaResourceTest(String name) {
-        super(name);
-    }
+public class JavaResourceTest {
+
+    @Rule
+    public BuildFileRule buildRule = new BuildFileRule();
 
+    @Before
     public void setUp() {
-        configureProject("src/etc/testcases/types/resources/javaresource.xml");
+        buildRule.configureProject("src/etc/testcases/types/resources/javaresource.xml");
     }
 
+    @Test
     public void testLoadManifest() {
-        executeTarget("loadManifest");
-        assertNotNull(getProject().getProperty("manifest"));
+        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(getProject().getProperty("manifest")
+        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");

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java Fri Apr 18 21:00:38 2014
@@ -23,15 +23,19 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.NoSuchElementException;
 
-import junit.framework.TestCase;
 
 import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.types.ResourceCollection;
+import org.junit.Test;
 
-public class LazyResourceCollectionTest extends TestCase {
+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.asList(new Resource[] {});
+        List resources = Arrays.<Resource>asList();
 
         List createdIterators = new ArrayList();
 
@@ -70,6 +74,7 @@ public class LazyResourceCollectionTest 
         }
     }
 
+    @Test
     public void testLazyLoading() throws Exception {
         StringResourceCollection collectionTest = new StringResourceCollection();
         LazyResourceCollectionWrapper lazyCollection = new LazyResourceCollectionWrapper();
@@ -102,7 +107,7 @@ public class LazyResourceCollectionTest 
 
         try {
             it.next();
-            fail("NoSuchElementException shoudl have been raised");
+            fail("NoSuchElementException should have been raised");
         } catch (NoSuchElementException e) {
             // ok
         }
@@ -114,6 +119,7 @@ public class LazyResourceCollectionTest 
                 testCollection.createdIterators.size());
     }
 
+    @Test
     public void testCaching() throws Exception {
         StringResourceCollection collectionTest = new StringResourceCollection();
         LazyResourceCollectionWrapper lazyCollection = new LazyResourceCollectionWrapper();

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/MultiRootFileSetTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/MultiRootFileSetTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/MultiRootFileSetTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/MultiRootFileSetTest.java Fri Apr 18 21:00:38 2014
@@ -25,15 +25,17 @@ 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.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 /**
  * This doesn't actually test much, mainly reference handling.
  */
 public class MultiRootFileSetTest extends AbstractFileSetTest {
 
-    public MultiRootFileSetTest(String name) {
-        super(name);
-    }
 
     protected AbstractFileSet getInstance() {
         return new MultiRootFileSet() {
@@ -56,6 +58,7 @@ public class MultiRootFileSetTest extend
         };
     }
 
+    @Test
     public void testEmptyElementIfIsReferenceAdditionalAttributes() {
         MultiRootFileSet f = new MultiRootFileSet();
         f.setProject(getProject());
@@ -115,6 +118,7 @@ public class MultiRootFileSetTest extend
         }
     }
 
+    @Test
     public void testDirCannotBeSet() {
         try {
             new MultiRootFileSet().setDir(new File("."));

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/ResourceListTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/ResourceListTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/ResourceListTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/ResourceListTest.java Fri Apr 18 21:00:38 2014
@@ -18,25 +18,38 @@
 package org.apache.tools.ant.types.resources;
 
 import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildFileRule;
 import org.apache.tools.ant.types.FilterChain;
 import org.apache.tools.ant.types.Reference;
-
-public class ResourceListTest extends BuildFileTest {
-
-    protected void setUp() throws Exception {
-        configureProject("src/etc/testcases/types/resources/resourcelist.xml");
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+public class ResourceListTest {
+
+    @Rule
+    public BuildFileRule buildRule = new BuildFileRule();
+
+    @Before
+    public void setUp() throws Exception {
+        buildRule.configureProject("src/etc/testcases/types/resources/resourcelist.xml");
     }
 
-    protected void tearDown() throws Exception {
-        executeTarget("tearDown");
+    @After
+    public void tearDown() throws Exception {
+        buildRule.executeTarget("tearDown");
     }
 
+    @Test
     public void testEmptyElementWithReference() {
         ResourceList rl = new ResourceList();
         rl.setEncoding("foo");
         try {
-            rl.setRefid(new Reference(getProject(), "dummyref"));
+            rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
             fail("Can add reference to ResourceList with encoding attribute set.");
         } catch (BuildException be) {
             assertEquals("You must not specify more than one attribute when using refid",
@@ -44,7 +57,7 @@ public class ResourceListTest extends Bu
         }
 
         rl = new ResourceList();
-        rl.setRefid(new Reference(getProject(), "dummyref"));
+        rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
         try {
             rl.setEncoding("foo");
             fail("Can set encoding in ResourceList that is a reference");
@@ -54,9 +67,9 @@ public class ResourceListTest extends Bu
         }
 
         rl = new ResourceList();
-        rl.add(new FileResource(getProject(), "."));
+        rl.add(new FileResource(buildRule.getProject(), "."));
         try {
-            rl.setRefid(new Reference(getProject(), "dummyref"));
+            rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
             fail("Can add reference to ResourceList with nested resource collection.");
         } catch (BuildException be) {
             assertEquals("You must not specify nested elements when using refid",
@@ -64,9 +77,9 @@ public class ResourceListTest extends Bu
         }
 
         rl = new ResourceList();
-        rl.setRefid(new Reference(getProject(), "dummyref"));
+        rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
         try {
-            rl.add(new FileResource(getProject(), "."));
+            rl.add(new FileResource(buildRule.getProject(), "."));
             fail("Can add reference to ResourceList with nested resource collection.");
         } catch (BuildException be) {
             assertEquals("You must not specify nested elements when using refid",
@@ -76,7 +89,7 @@ public class ResourceListTest extends Bu
         rl = new ResourceList();
         rl.addFilterChain(new FilterChain());
         try {
-            rl.setRefid(new Reference(getProject(), "dummyref"));
+            rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
             fail("Can add reference to ResourceList with nested filter chain.");
         } catch (BuildException be) {
             assertEquals("You must not specify nested elements when using refid",
@@ -84,7 +97,7 @@ public class ResourceListTest extends Bu
         }
 
         rl = new ResourceList();
-        rl.setRefid(new Reference(getProject(), "dummyref"));
+        rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
         try {
             rl.addFilterChain(new FilterChain());
             fail("Can add reference to ResourceList with nested filter chain.");
@@ -94,18 +107,19 @@ public class ResourceListTest extends Bu
         }
     }
 
+    @Test
     public void testCircularReference() throws Exception {
         ResourceList rl1 = new ResourceList();
-        rl1.setProject(getProject());
-        rl1.setRefid(new Reference(getProject(), "foo"));
+        rl1.setProject(buildRule.getProject());
+        rl1.setRefid(new Reference(buildRule.getProject(), "foo"));
 
         ResourceList rl2 = new ResourceList();
-        rl2.setProject(getProject());
-        getProject().addReference("foo", rl2);
+        rl2.setProject(buildRule.getProject());
+        buildRule.getProject().addReference("foo", rl2);
 
         Union u = new Union();
         u.add(rl1);
-        u.setProject(getProject());
+        u.setProject(buildRule.getProject());
 
         rl2.add(u);
 

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/TarResourceTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/TarResourceTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/TarResourceTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/resources/TarResourceTest.java Fri Apr 18 21:00:38 2014
@@ -17,26 +17,38 @@
  */
 package org.apache.tools.ant.types.resources;
 
-import org.apache.tools.ant.BuildFileTest;
-import org.apache.tools.ant.util.FileUtils;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
 
 import java.io.File;
 
-public class TarResourceTest extends BuildFileTest {
+import static org.apache.tools.ant.FileUtilities.getFileContents;
+import static org.junit.Assert.assertEquals;
 
-    private static final FileUtils FU = FileUtils.getFileUtils();
 
-    public TarResourceTest(String name) {
-        super(name);
+public class TarResourceTest {
+
+    @Rule
+    public BuildFileRule buildRule = new BuildFileRule();
+
+    @Before
+    public void setUp() throws Exception {
+        buildRule.configureProject("src/etc/testcases/types/resources/tarentry.xml");
     }
 
-    protected void setUp() throws Exception {
-        configureProject("src/etc/testcases/types/resources/tarentry.xml");
+
+    @After
+    public void tearDown() throws Exception {
+        buildRule.executeTarget("tearDown");
     }
 
+    @Test
     public void testUncompressSource() throws java.io.IOException {
-        executeTarget("uncompressSource");
-        assertTrue(FU.contentEquals(project.resolveFile("../../asf-logo.gif"),
-                                    new File(getProject().getProperty("output"), "asf-logo.gif")));
+        buildRule.executeTarget("uncompressSource");
+        assertEquals(getFileContents(buildRule.getProject().resolveFile("../../asf-logo.gif")),
+                getFileContents(new File(buildRule.getProject().getProperty("output"), "asf-logo.gif")));
     }
 }

Added: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorRule.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorRule.java?rev=1588563&view=auto
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorRule.java (added)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorRule.java Fri Apr 18 21:00:38 2014
@@ -0,0 +1,125 @@
+/*
+ *  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.BuildFileRule;
+
+
+/**
+ * Base test case for Selectors. Provides a shared test as well as
+ * a test bed for selecting on, and a helper method for determining
+ * whether selections are correct.
+ *
+ */
+public class BaseSelectorRule extends BuildFileRule {
+
+    private File beddir;
+    private File mirrordir;
+    private final String[] filenames = {".","asf-logo.gif.md5","asf-logo.gif.bz2",
+            "asf-logo.gif.gz","copy.filterset.filtered","zip/asf-logo.gif.zip",
+            "tar/asf-logo.gif.tar","tar/asf-logo-huge.tar.gz",
+            "tar/gz/asf-logo.gif.tar.gz","tar/bz2/asf-logo.gif.tar.bz2",
+            "tar/bz2/asf-logo-huge.tar.bz2","tar/bz2"};
+    private File[] files = new File[filenames.length];
+    private File[] mirrorfiles = new File[filenames.length];
+
+    @Override
+    public void before() throws Throwable {
+        super.before();
+        configureProject("src/etc/testcases/types/selectors.xml");
+        executeTarget("setUp");
+
+        executeTarget("setupfiles");
+        executeTarget("mirrorfiles");
+
+        beddir = new File(super.getProject().getProperty("test.dir"));
+        mirrordir = new File(super.getProject().getProperty("mirror.dir"));
+
+        for (int x = 0; x < files.length; x++) {
+            files[x] = new File(beddir,filenames[x]);
+            mirrorfiles[x] = new File(mirrordir,filenames[x]);
+        }
+    }
+
+    @Override
+    public void after() {
+        super.after();
+        executeTarget("tearDown");
+    }
+
+    public File getBeddir() {
+        return beddir;
+    }
+
+    public File[] getMirrorFiles() {
+        return mirrorfiles;
+    }
+
+    public File[] getFiles() {
+        return files;
+    }
+
+    public String[] getFilenames() {
+        return filenames;
+    }
+
+
+    /**
+     * This is a helper method that takes a selector and calls its
+     * isSelected() method on each file in the testbed. It returns
+     * a string of "T"s amd "F"s
+     */
+    public String selectionString(FileSelector selector) {
+        return selectionString(beddir,files,selector);
+    }
+
+    /**
+     * This is a helper method that takes a selector and calls its
+     * isSelected() method on each file in the mirror testbed. This
+     * variation is used for dependency checks and to get around the
+     * limitations in the touch task when running JDK 1.1. It returns
+     * a string of "T"s amd "F"s.
+     */
+    public String mirrorSelectionString(FileSelector selector) {
+        return selectionString(mirrordir,mirrorfiles,selector);
+    }
+
+    /**
+     * Worker method for the two convenience methods above. Applies a
+     * selector on a set of files passed in and returns a string of
+     * "T"s amd "F"s from applying the selector to each file.
+     */
+    public String selectionString(File basedir, File[] files, FileSelector selector) {
+        StringBuilder buf = new StringBuilder();
+        for (int x = 0; x < files.length; x++) {
+            if (selector.isSelected(basedir,filenames[x],files[x])) {
+                buf.append('T');
+            }
+            else {
+                buf.append('F');
+            }
+        }
+        return buf.toString();
+    }
+
+
+}

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorTest.java Fri Apr 18 21:00:38 2014
@@ -20,8 +20,6 @@ package org.apache.tools.ant.types.selec
 
 import java.io.File;
 
-import junit.framework.TestCase;
-
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.BuildFileTest;
 import org.apache.tools.ant.Project;
@@ -31,7 +29,9 @@ import org.apache.tools.ant.Project;
  * a test bed for selecting on, and a helper method for determining
  * whether selections are correct.
  *
+ * @deprecated as of 1.9.4. Use {@link org.apache.tools.ant.types.selectors.BaseSelectorRule} instead.
  */
+@Deprecated
 public abstract class BaseSelectorTest extends BuildFileTest {
 
     private Project project;

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java Fri Apr 18 21:00:38 2014
@@ -20,69 +20,37 @@ package org.apache.tools.ant.types.selec
 
 import java.io.File;
 
-import junit.framework.TestCase;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
 
-import org.apache.tools.ant.BuildFileTest;
-import org.apache.tools.ant.Project;
+import static org.junit.Assert.assertEquals;
 
 
-public class ContainsRegexpTest extends TestCase {
+public class ContainsRegexpTest {
 
-    private Project project;
-
-    public ContainsRegexpTest(String name) {
-        super(name);
-    }
+    @Rule
+    public BuildFileRule buildRule = new BuildFileRule();
 
+    @Before
     public void setUp() {
-        project = new Project();
-        project.setBasedir(".");
+        buildRule.configureProject("src/etc/testcases/types/selectors.xml");
     }
 
+    @Test
     public void testContainsRegexp() {
-        TaskdefForRegexpTest MyTask =
-            new TaskdefForRegexpTest("containsregexp");
-        try {
-            MyTask.setUp();
-            MyTask.test();
-        } finally {
-            MyTask.tearDown();
-        }
-    }
-
-    private class TaskdefForRegexpTest extends BuildFileTest {
-        TaskdefForRegexpTest(String name) {
-            super(name);
-        }
+        buildRule.executeTarget("containsregexp");
+        File dir = new File(buildRule.getOutputDir(), "regexpseltestdest");
+        File[] files = dir.listFiles();
+        int filecount = files.length;
+
+        if (filecount != 1)  {
+            assertEquals("ContainsRegexp test should have copied 1 file",
+                         1, files.length);
 
-        public void setUp() {
-            configureProject("src/etc/testcases/types/selectors.xml");
-        }
-
-        public void tearDown() {
-            try {
-                super.tearDown();
-            } catch (Exception exc) {
-                // ignore
-            }
-        }
-
-        public void test() {
-            File dir = null;
-            File[] files = null;
-            int filecount;
-
-            executeTarget("containsregexp");
-	
-            dir = new File(getOutputDir(), "regexpseltestdest");
-            files = dir.listFiles();
-            filecount = files.length;
-	
-            if (filecount != 1)
-                assertEquals("ContainsRegexp test should have copied 1 file",
-                             1, files.length);
-	
         }
     }
+
 }
 

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java Fri Apr 18 21:00:38 2014
@@ -19,49 +19,44 @@
 package org.apache.tools.ant.types.selectors;
 
 import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
 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 Contains Selectors.
  *
  */
-public class ContainsSelectorTest extends BaseSelectorTest {
+public class ContainsSelectorTest {
 
-    private Project project;
+    @Rule
+    public final BaseSelectorRule selectorRule = new BaseSelectorRule();
 
-    public ContainsSelectorTest(String name) {
-        super(name);
-    }
-
-    /**
-     * Factory method from base class. This is overriden in child
-     * classes to return a specific Selector class.
-     */
-    public BaseSelector getInstance() {
-        return new ContainsSelector();
-    }
 
     /**
      * Test the code that validates the selector.
      */
+    @Test
     public void testValidate() {
-        ContainsSelector s = (ContainsSelector)getInstance();
+        ContainsSelector s = new ContainsSelector();
         try {
-            s.isSelected(basedir,filenames[0],files[0]);
+            s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
             fail("ContainsSelector did not check for required field 'text'");
         } catch (BuildException be1) {
             assertEquals("The text attribute is required", be1.getMessage());
         }
 
-        s = (ContainsSelector)getInstance();
+        s = new ContainsSelector();
         Parameter param = new Parameter();
         param.setName("garbage in");
         param.setValue("garbage out");
         Parameter[] params = {param};
         s.setParameters(params);
         try {
-            s.isSelected(basedir,filenames[0],files[0]);
+            s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
             fail("ContainsSelector did not check for valid parameter element");
         } catch (BuildException be2) {
             assertEquals("Invalid parameter garbage in", be2.getMessage());
@@ -72,51 +67,47 @@ public class ContainsSelectorTest extend
     /**
      * Tests to make sure that the selector is selecting files correctly.
      */
+    @Test
     public void testSelectionBehaviour() {
         ContainsSelector s;
         String results;
 
-        try {
-            makeBed();
 
-            s = (ContainsSelector)getInstance();
-            s.setText("no such string in test files");
-            results = selectionString(s);
-            assertEquals("TFFFFFFFFFFT", results);
-
-            s = (ContainsSelector)getInstance();
-            s.setText("Apache Ant");
-            results = selectionString(s);
-            assertEquals("TFFFTFFFFFFT", results);
-
-            s = (ContainsSelector)getInstance();
-            s.setText("apache ant");
-            s.setCasesensitive(true);
-            results = selectionString(s);
-            assertEquals("TFFFFFFFFFFT", results);
-
-            s = (ContainsSelector)getInstance();
-            s.setText("apache ant");
-            s.setCasesensitive(false);
-            results = selectionString(s);
-            assertEquals("TFFFTFFFFFFT", results);
-
-            s = (ContainsSelector)getInstance();
-            s.setText("ApacheAnt");
-            s.setIgnorewhitespace(true);
-            results = selectionString(s);
-            assertEquals("TFFFTFFFFFFT", results);
-
-            s = (ContainsSelector)getInstance();
-            s.setText("A p a c h e    A n t");
-            s.setIgnorewhitespace(true);
-            results = selectionString(s);
-            assertEquals("TFFFTFFFFFFT", results);
+        s = new ContainsSelector();
+        s.setText("no such string in test files");
+        results = selectorRule.selectionString(s);
+        assertEquals("TFFFFFFFFFFT", results);
+
+        s = new ContainsSelector();
+        s.setText("Apache Ant");
+        results = selectorRule.selectionString(s);
+        assertEquals("TFFFTFFFFFFT", results);
+
+        s = new ContainsSelector();
+        s.setText("apache ant");
+        s.setCasesensitive(true);
+        results = selectorRule.selectionString(s);
+        assertEquals("TFFFFFFFFFFT", results);
+
+        s = new ContainsSelector();
+        s.setText("apache ant");
+        s.setCasesensitive(false);
+        results = selectorRule.selectionString(s);
+        assertEquals("TFFFTFFFFFFT", results);
+
+        s = new ContainsSelector();
+        s.setText("ApacheAnt");
+        s.setIgnorewhitespace(true);
+        results = selectorRule.selectionString(s);
+        assertEquals("TFFFTFFFFFFT", results);
+
+        s = new ContainsSelector();
+        s.setText("A p a c h e    A n t");
+        s.setIgnorewhitespace(true);
+        results = selectorRule.selectionString(s);
+        assertEquals("TFFFTFFFFFFT", results);
 
-        }
-        finally {
-            cleanupBed();
-        }
+        
 
     }
 

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/DateSelectorTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/DateSelectorTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/DateSelectorTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/DateSelectorTest.java Fri Apr 18 21:00:38 2014
@@ -20,43 +20,42 @@ package org.apache.tools.ant.types.selec
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.types.Parameter;
+import org.junit.Assume;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 
 
 /**
  * Tests Date Selectors.
  *
  */
-public class DateSelectorTest extends BaseSelectorTest {
+public class DateSelectorTest {
 
-    public DateSelectorTest(String name) {
-        super(name);
-    }
+    @Rule
+    public final BaseSelectorRule selectorRule = new BaseSelectorRule();
 
-    /**
-     * Factory method from base class. This is overriden in child
-     * classes to return a specific Selector class.
-     */
-    public BaseSelector getInstance() {
-        return new DateSelector();
-    }
 
     /**
      * Test the code that validates the selector.
      */
+    @Test
     public void testValidate() {
-        DateSelector s = (DateSelector)getInstance();
+        DateSelector s = new DateSelector();
         try {
-            s.isSelected(basedir,filenames[0],files[0]);
+            s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
             fail("DateSelector did not check for required fields");
         } catch (BuildException be1) {
             assertEquals("You must provide a datetime or the number of "
                     + "milliseconds.", be1.getMessage());
         }
 
-        s = (DateSelector)getInstance();
+        s = new DateSelector();
         s.setDatetime("01/01/1969 01:01 AM");
         try {
-            s.isSelected(basedir,filenames[0],files[0]);
+            s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
             fail("DateSelector did not check for Datetime being in the "
                     + "allowable range");
         } catch (BuildException be2) {
@@ -65,10 +64,10 @@ public class DateSelectorTest extends Ba
                     + "1970, 00:00:00 GMT).", be2.getMessage());
         }
 
-        s = (DateSelector)getInstance();
+        s = new DateSelector();
         s.setDatetime("this is not a date");
         try {
-            s.isSelected(basedir,filenames[0],files[0]);
+            s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
             fail("DateSelector did not check for Datetime being in a "
                     + "valid format");
         } catch (BuildException be3) {
@@ -77,7 +76,7 @@ public class DateSelectorTest extends Ba
                         + " MM/DD/YYYY HH:MM AM_PM format.", be3.getMessage());
         }
 
-        s = (DateSelector)getInstance();
+        s = new DateSelector();
         Parameter param = new Parameter();
         param.setName("garbage in");
         param.setValue("garbage out");
@@ -85,34 +84,34 @@ public class DateSelectorTest extends Ba
         params[0] = param;
         s.setParameters(params);
         try {
-            s.isSelected(basedir,filenames[0],files[0]);
+            s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
             fail("DateSelector did not check for valid parameter element");
         } catch (BuildException be4) {
             assertEquals("Invalid parameter garbage in", be4.getMessage());
         }
 
-        s = (DateSelector)getInstance();
+        s = new DateSelector();
         param = new Parameter();
         param.setName("millis");
         param.setValue("garbage out");
         params[0] = param;
         s.setParameters(params);
         try {
-            s.isSelected(basedir,filenames[0],files[0]);
+            s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
             fail("DateSelector did not check for valid millis parameter");
         } catch (BuildException be5) {
             assertEquals("Invalid millisecond setting garbage out",
                     be5.getMessage());
         }
 
-        s = (DateSelector)getInstance();
+        s = new DateSelector();
         param = new Parameter();
         param.setName("granularity");
         param.setValue("garbage out");
         params[0] = param;
         s.setParameters(params);
         try {
-            s.isSelected(basedir,filenames[0],files[0]);
+            s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
             fail("DateSelector did not check for valid granularity parameter");
         } catch (BuildException be6) {
             assertEquals("Invalid granularity setting garbage out",
@@ -124,6 +123,7 @@ public class DateSelectorTest extends Ba
     /**
      * Tests to make sure that the selector is selecting files correctly.
      */
+    @Test
     public void testSelectionBehaviour() {
         DateSelector s;
         String results;
@@ -138,93 +138,92 @@ public class DateSelectorTest extends Ba
                 DateSelector.TimeComparisons();
         after.setValue("after");
 
-        try {
-            makeBed();
 
-            s = (DateSelector)getInstance();
-            s.setDatetime("10/10/1999 1:45 PM");
-            s.setWhen(before);
-            results = selectionString(s);
-            assertEquals("TFFFFFFFFFFT", results);
-
-            s = (DateSelector)getInstance();
-            s.setDatetime("10/10/1999 1:45 PM");
-            s.setWhen(before);
-            s.setCheckdirs(true);
-            results = selectionString(s);
-            assertEquals("FFFFFFFFFFFF", results);
-
-            s = (DateSelector)getInstance();
-            s.setDatetime("10/10/1999 1:45 PM");
-            s.setWhen(after);
-            results = selectionString(s);
-            assertEquals("TTTTTTTTTTTT", results);
-
-            s = (DateSelector)getInstance();
-            s.setDatetime("11/21/2001 4:54 AM");
-            s.setWhen(before);
-            results = selectionString(s);
-            assertEquals("TFTFFFFFFFFT", results);
-
-            s = (DateSelector)getInstance();
-            s.setDatetime("11/21/2001 4:55 AM");
-
-            long milliseconds = s.getMillis();
-            s.setWhen(equal);
-            results = selectionString(s);
-            assertEquals("TTFFTFFFTTTT", results);
-
-            s = (DateSelector)getInstance();
-            s.setMillis(milliseconds);
-            s.setWhen(equal);
-            results = selectionString(s);
-            assertEquals("TTFFTFFFTTTT", results);
-
-            s = (DateSelector)getInstance();
-            s.setDatetime("11/21/2001 4:56 AM");
-            s.setWhen(after);
-            results = selectionString(s);
-            assertEquals("TFFTFTTTFFFT", results);
-
-            s = (DateSelector)getInstance();
-            Parameter param1 = new Parameter();
-            Parameter param2 = new Parameter();
-            param1.setName("datetime");
-            param1.setValue("11/21/2001 4:56 AM");
-            param2.setName("when");
-            param2.setValue("after");
-            Parameter[] params = {param1,param2};
-            s.setParameters(params);
-            results = selectionString(s);
-            assertEquals("TFFTFTTTFFFT", results);
-            try {
-                makeMirror();
-
-                s = (DateSelector)getInstance();
-                long testtime = mirrorfiles[5].lastModified();
-                s.setMillis(testtime);
-                s.setWhen(after);
-                s.setGranularity(2);
-                results = mirrorSelectionString(s);
-                assertEquals("TFFFFTTTTTTT", results);
-
-                s = (DateSelector)getInstance();
-                testtime = mirrorfiles[6].lastModified();
-                s.setMillis(testtime);
-                s.setWhen(before);
-                s.setGranularity(2);
-                results = mirrorSelectionString(s);
-                assertEquals("TTTTTTTFFFFT", results);
-            }
-            finally {
-                cleanupMirror();
-            }
+        s = new DateSelector();
+        s.setDatetime("10/10/1999 1:45 PM");
+        s.setWhen(before);
+        results = selectorRule.selectionString(s);
+        assertEquals("TFFFFFFFFFFT", results);
+
+        s = new DateSelector();
+        s.setDatetime("10/10/1999 1:45 PM");
+        s.setWhen(before);
+        s.setCheckdirs(true);
+        results = selectorRule.selectionString(s);
+        assertEquals("FFFFFFFFFFFF", results);
+
+        s = new DateSelector();
+        s.setDatetime("10/10/1999 1:45 PM");
+        s.setWhen(after);
+        results = selectorRule.selectionString(s);
+        assertEquals("TTTTTTTTTTTT", results);
+
+        s = new DateSelector();
+        s.setDatetime("11/21/2001 4:54 AM");
+        s.setWhen(before);
+        results = selectorRule.selectionString(s);
+        assertEquals("TFTFFFFFFFFT", results);
+
+        s = new DateSelector();
+        s.setDatetime("11/21/2001 4:55 AM");
+
+        long milliseconds = s.getMillis();
+        s.setWhen(equal);
+        results = selectorRule.selectionString(s);
+        assertEquals("TTFFTFFFTTTT", results);
+
+        s = new DateSelector();
+        s.setMillis(milliseconds);
+        s.setWhen(equal);
+        results = selectorRule.selectionString(s);
+        assertEquals("TTFFTFFFTTTT", results);
+
+        s = new DateSelector();
+        s.setDatetime("11/21/2001 4:56 AM");
+        s.setWhen(after);
+        results = selectorRule.selectionString(s);
+        assertEquals("TFFTFTTTFFFT", results);
+
+        s = new DateSelector();
+        Parameter param1 = new Parameter();
+        Parameter param2 = new Parameter();
+        param1.setName("datetime");
+        param1.setValue("11/21/2001 4:56 AM");
+        param2.setName("when");
+        param2.setValue("after");
+        Parameter[] params = {param1,param2};
+        s.setParameters(params);
+        results = selectorRule.selectionString(s);
+        assertEquals("TFFTFTTTFFFT", results);
+
+        s = new DateSelector();
+        long testtime = selectorRule.getMirrorFiles()[5].lastModified();
+        s.setMillis(testtime);
+        s.setWhen(after);
+        s.setGranularity(2);
 
+        // setup the modified timestamp to match what the test needs, although be aware that the 3rd and 4th
+        // files don't exist so can't be changed, so don't try and loop over them
+        for (int i = 1; i <=2; i++) {
+            Assume.assumeTrue("Cannot setup file times for test", selectorRule.getMirrorFiles()[i].setLastModified(testtime - (3*60*60*100)));
         }
-        finally {
-            cleanupBed();
+
+
+        results = selectorRule.mirrorSelectionString(s);
+        assertEquals("TFFFFTTTTTTT", results);
+
+        s = new DateSelector();
+        testtime = selectorRule.getMirrorFiles()[6].lastModified();
+        s.setMillis(testtime);
+        s.setWhen(before);
+        s.setGranularity(2);
+        for (int i = 7; i <= 10; i++) {
+            Assume.assumeTrue("Cannot setup file times for test", selectorRule.getMirrorFiles()[i].setLastModified(testtime + (3*60*60*100)));
         }
 
+        results = selectorRule.mirrorSelectionString(s);
+        assertEquals("TTTTTTTFFFFT", results);
+
     }
 
 }

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/DependSelectorTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/DependSelectorTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/DependSelectorTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/DependSelectorTest.java Fri Apr 18 21:00:38 2014
@@ -20,34 +20,28 @@ package org.apache.tools.ant.types.selec
 
 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 extends BaseSelectorTest {
-
-    public DependSelectorTest(String name) {
-        super(name);
-    }
+public class DependSelectorTest {
 
-    /**
-     * Factory method from base class. This is overriden in child
-     * classes to return a specific Selector class.
-     */
-    public BaseSelector getInstance() {
-        return new DependSelector();
-    }
+    @Rule
+    public final BaseSelectorRule selectorRule = new BaseSelectorRule();
 
-    /**
-     * Test the code that validates the selector.
-     */
-    public void testValidate() {
-        DependSelector s = (DependSelector)getInstance();
+    @Test
+    public void testValidateSingleMapper() {
         try {
+            DependSelector s = new DependSelector();
             s.createMapper();
             s.createMapper();
             fail("DependSelector allowed more than one nested mapper.");
@@ -55,10 +49,14 @@ public class DependSelectorTest extends 
             assertEquals("Cannot define more than one mapper",
                     be1.getMessage());
         }
+    }
+
 
-        s = (DependSelector)getInstance();
+    @Test
+     public void testValidateRequiredFields() {
         try {
-            s.isSelected(basedir,filenames[0],files[0]);
+            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.",
@@ -67,103 +65,121 @@ public class DependSelectorTest extends 
 
     }
 
-    /**
-     * Tests to make sure that the selector is selecting files correctly.
-     */
-    public void testSelectionBehaviour() {
-        DependSelector s;
-        String results;
-        File subdir;
-        Mapper m;
+    @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.MapperType glob = new Mapper.MapperType();
-        glob.setValue("glob");
+
+        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");
 
-        try {
-            makeBed();
+        Mapper m = s.createMapper();
+        m.setType(merge);
+        m.setTo("asf-logo.gif.gz");
 
-            s = (DependSelector)getInstance();
-            s.setTargetdir(beddir);
-            results = selectionString(s);
-            assertEquals("FFFFFFFFFFFF", results);
-
-            s = (DependSelector)getInstance();
-            s.setTargetdir(beddir);
-            m = s.createMapper();
-            m.setType(identity);
-            results = selectionString(s);
-            assertEquals("FFFFFFFFFFFF", results);
-
-            s = (DependSelector)getInstance();
-            s.setTargetdir(beddir);
-            m = s.createMapper();
-            m.setType(merge);
-            m.setTo("asf-logo.gif.gz");
-            results = selectionString(s);
-            assertEquals("TFFFFTTTFFF", results.substring(0,11));
-
-            s = (DependSelector)getInstance();
-            s.setTargetdir(beddir);
-            m = s.createMapper();
-            m.setType(merge);
-            m.setTo("asf-logo.gif.bz2");
-            results = selectionString(s);
-            assertEquals("TTFTTTTTTTTT", results);
-
-            // Test for path relative to project base directory
-            s = (DependSelector)getInstance();
-            subdir = new File("selectortest/tar/bz2");
-            s.setTargetdir(subdir);
-            m = s.createMapper();
-            m.setType(glob);
-            m.setFrom("*.bz2");
-            m.setTo("*.tar.bz2");
-            results = selectionString(s);
-            assertEquals("FFTFFFFFFTTF", results);
-
-            s = (DependSelector)getInstance();
-            subdir = new File(beddir,"tar/bz2");
-            s.setTargetdir(subdir);
-            m = s.createMapper();
-            m.setType(glob);
-            m.setFrom("*.bz2");
-            m.setTo("*.tar.bz2");
-            results = selectionString(s);
-            assertEquals("FFFFFFFFFTTF", results);
-
-            try {
-                makeMirror();
-
-                s = (DependSelector)getInstance();
-                File testdir = new File(getOutputDir(), "selectortest2");
-                s.setTargetdir(testdir);
-                results = selectionString(s);
-                assertEquals("FFFTTFFFFFFF", results);
-
-                s = (DependSelector)getInstance();
-                testdir = new File(getOutputDir(), "selectortest2/tar/bz2");
-                s.setTargetdir(testdir);
-                m = s.createMapper();
-                m.setType(glob);
-                m.setFrom("*.bz2");
-                m.setTo("*.tar.bz2");
-                results = mirrorSelectionString(s);
-                assertEquals("FFFFFFFFFTTF", results);
-                results = selectionString(s);
-                assertEquals("FFFFFFFFFTTF", results);
-            }
-            finally {
-                cleanupMirror();
-            }
+        String results = selectorRule.selectionString(s);
+        assertEquals("TFFFFTTTFFF", results.substring(0,11));
+    }
 
-        }
-        finally {
-            cleanupBed();
-        }
+    @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);
     }
 
 }

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/DepthSelectorTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/DepthSelectorTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/DepthSelectorTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/DepthSelectorTest.java Fri Apr 18 21:00:38 2014
@@ -20,43 +20,41 @@ package org.apache.tools.ant.types.selec
 
 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 extends BaseSelectorTest {
-
-    public DepthSelectorTest(String name) {
-        super(name);
-    }
+public class DepthSelectorTest {
+    
+    @Rule
+    public final BaseSelectorRule selectorRule = new BaseSelectorRule();
 
-    /**
-     * Factory method from base class. This is overriden in child
-     * classes to return a specific Selector class.
-     */
-    public BaseSelector getInstance() {
-        return new DepthSelector();
-    }
 
     /**
      * Test the code that validates the selector.
      */
+    @Test
     public void testValidate() {
-        DepthSelector s = (DepthSelector)getInstance();
+        DepthSelector s = new DepthSelector();
         try {
-            s.isSelected(basedir,filenames[0],files[0]);
+            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 = (DepthSelector)getInstance();
+        s = new DepthSelector();
         s.setMin(5);
         s.setMax(2);
         try {
-            s.isSelected(basedir,filenames[0],files[0]);
+            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) {
@@ -64,7 +62,7 @@ public class DepthSelectorTest extends B
                     be2.getMessage());
         }
 
-        s = (DepthSelector)getInstance();
+        s = new DepthSelector();
         Parameter param = new Parameter();
         param.setName("garbage in");
         param.setValue("garbage out");
@@ -72,34 +70,34 @@ public class DepthSelectorTest extends B
         params[0] = param;
         s.setParameters(params);
         try {
-            s.isSelected(basedir,filenames[0],files[0]);
+            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 = (DepthSelector)getInstance();
+        s = new DepthSelector();
         param = new Parameter();
         param.setName("min");
         param.setValue("garbage out");
         params[0] = param;
         s.setParameters(params);
         try {
-            s.isSelected(basedir,filenames[0],files[0]);
+            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 = (DepthSelector)getInstance();
+        s = new DepthSelector();
         param = new Parameter();
         param.setName("max");
         param.setValue("garbage out");
         params[0] = param;
         s.setParameters(params);
         try {
-            s.isSelected(basedir,filenames[0],files[0]);
+            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",
@@ -111,44 +109,38 @@ public class DepthSelectorTest extends B
     /**
      * Tests to make sure that the selector is selecting files correctly.
      */
+    @Test
     public void testSelectionBehaviour() {
         DepthSelector s;
         String results;
 
-        try {
-            makeBed();
-
-            s = (DepthSelector)getInstance();
-            s.setMin(20);
-            s.setMax(25);
-            results = selectionString(s);
-            assertEquals("FFFFFFFFFFFF", results);
-
-            s = (DepthSelector)getInstance();
-            s.setMin(0);
-            results = selectionString(s);
-            assertEquals("TTTTTTTTTTTT", results);
-
-            s = (DepthSelector)getInstance();
-            s.setMin(1);
-            results = selectionString(s);
-            assertEquals("FFFFFTTTTTTT", results);
-
-            s = (DepthSelector)getInstance();
-            s.setMax(0);
-            results = selectionString(s);
-            assertEquals("TTTTTFFFFFFF", results);
-
-            s = (DepthSelector)getInstance();
-            s.setMin(1);
-            s.setMax(1);
-            results = selectionString(s);
-            assertEquals("FFFFFTTTFFFT", 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);
 
-        }
-        finally {
-            cleanupBed();
-        }
 
     }