Repository: ant
Updated Branches:
  refs/heads/master beb67e322 -> 47f8c5d46


Tidy up/optimize the code

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

Branch: refs/heads/master
Commit: efaebc37243b4346226902935ee355df5f9f1c16
Parents: beb67e3
Author: Gintas Grigelionis <[email protected]>
Authored: Sun Apr 22 18:42:14 2018 +0200
Committer: Gintas Grigelionis <[email protected]>
Committed: Sun Apr 22 18:45:44 2018 +0200

----------------------------------------------------------------------
 .../tools/ant/taskdefs/ExecuteJavaTest.java     |   4 +-
 .../apache/tools/ant/taskdefs/LoadFileTest.java |   5 +-
 .../apache/tools/ant/taskdefs/MakeUrlTest.java  |   8 +-
 .../apache/tools/ant/taskdefs/ManifestTest.java |  27 +++-
 .../ant/taskdefs/condition/TypeFoundTest.java   |   3 +
 .../ant/taskdefs/optional/RhinoScriptTest.java  |   1 -
 .../ant/taskdefs/optional/XmlValidateTest.java  |   3 +
 .../tools/ant/taskdefs/optional/XsltTest.java   |   3 +
 .../taskdefs/optional/depend/DependTest.java    |   2 +-
 .../optional/junit/JUnitTestRunnerTest.java     |   4 +-
 .../taskdefs/optional/script/ScriptDefTest.java |   9 ++
 .../org/apache/tools/ant/types/DirSetTest.java  |   1 -
 .../org/apache/tools/ant/types/MapperTest.java  | 157 +++++++++----------
 .../org/apache/tools/ant/types/PathTest.java    |   1 -
 .../tools/ant/types/RedirectorElementTest.java  |   1 -
 .../apache/tools/ant/types/TarFileSetTest.java  |   1 +
 .../apache/tools/ant/types/XMLCatalogTest.java  |  10 +-
 .../tools/ant/types/mappers/MapperResult.java   |  12 +-
 .../types/resources/MultiRootFileSetTest.java   |   2 -
 .../ant/types/selectors/ContainsRegexpTest.java |  11 +-
 .../types/selectors/ModifiedSelectorTest.java   |  11 +-
 .../org/apache/tools/mail/MailMessageTest.java  |  29 ++--
 22 files changed, 151 insertions(+), 154 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/efaebc37/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java 
b/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java
index e6dca54..747e44d 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java
@@ -115,8 +115,8 @@ public class ExecuteJavaTest {
     }
 
     /**
-     * Dangerous method to obtain the classpath for the test. This is
-     * severely tighted to the build.xml properties.
+     * Dangerous method to obtain the classpath for the test.
+     * This is severely dependent on the build.xml properties.
      */
     private static String getTestClassPath() {
         String classpath = System.getProperty("build.tests");

http://git-wip-us.apache.org/repos/asf/ant/blob/efaebc37/src/tests/junit/org/apache/tools/ant/taskdefs/LoadFileTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/LoadFileTest.java 
b/src/tests/junit/org/apache/tools/ant/taskdefs/LoadFileTest.java
index 19571f1..c0b3a1f 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/LoadFileTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/LoadFileTest.java
@@ -134,9 +134,8 @@ public class LoadFileTest {
     @Test
     public final void testStripJavaComments() throws BuildException {
         buildRule.executeTarget("testStripJavaComments");
-        final String expected = buildRule.getProject().getProperty("expected");
-        final String generated = 
buildRule.getProject().getProperty("testStripJavaComments");
-        assertEquals(expected, generated);
+        assertEquals(buildRule.getProject().getProperty("expected"),
+                buildRule.getProject().getProperty("testStripJavaComments"));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/ant/blob/efaebc37/src/tests/junit/org/apache/tools/ant/taskdefs/MakeUrlTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/MakeUrlTest.java 
b/src/tests/junit/org/apache/tools/ant/taskdefs/MakeUrlTest.java
index 62f7e9e..7c9576e 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/MakeUrlTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/MakeUrlTest.java
@@ -50,28 +50,28 @@ public class MakeUrlTest {
     @Test
     public void testEmpty() {
         thrown.expect(BuildException.class);
-        thrown.expectMessage("property");
+        thrown.expectMessage("No property defined");
         buildRule.executeTarget("testEmpty");
     }
 
     @Test
     public void testNoProperty() {
         thrown.expect(BuildException.class);
-        thrown.expectMessage("property");
+        thrown.expectMessage("No property defined");
         buildRule.executeTarget("testNoProperty");
     }
 
     @Test
     public void testNoFile() {
         thrown.expect(BuildException.class);
-        thrown.expectMessage("file");
+        thrown.expectMessage("No files defined");
         buildRule.executeTarget("testNoFile");
     }
 
     @Test
     public void testValidation() {
         thrown.expect(BuildException.class);
-        thrown.expectMessage("file");
+        thrown.expectMessage("A source file is missing");
         buildRule.executeTarget("testValidation");
     }
 

http://git-wip-us.apache.org/repos/asf/ant/blob/efaebc37/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java 
b/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java
index 7a72fd3..bad93fe 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java
@@ -263,12 +263,12 @@ public class ManifestTest {
         assertEquals("Class-Path attribute was not set correctly - ",
             LONG_LINE, classpath);
 
-        String value = mainSection.getAttributeValue(LONG_68_NAME);
-        assertEquals("LONG_68_NAME_VALUE_MISMATCH", VALUE, value);
-        value = mainSection.getAttributeValue(LONG_70_NAME);
-        assertEquals("LONG_70_NAME_VALUE_MISMATCH", VALUE, value);
-        value = mainSection.getAttributeValue(NOT_LONG_NAME);
-        assertEquals("NOT_LONG_NAME_VALUE_MISMATCH", VALUE, value);
+        assertEquals("LONG_68_NAME_VALUE_MISMATCH", VALUE,
+                mainSection.getAttributeValue(LONG_68_NAME));
+        assertEquals("LONG_70_NAME_VALUE_MISMATCH", VALUE,
+                mainSection.getAttributeValue(LONG_70_NAME));
+        assertEquals("NOT_LONG_NAME_VALUE_MISMATCH", VALUE,
+                mainSection.getAttributeValue(NOT_LONG_NAME));
 
         Set<String> set = new HashSet<>();
         try (FileReader fin = new FileReader(expandedManifest)) {
@@ -388,30 +388,45 @@ public class ManifestTest {
         assertThat(buildRule.getLog(), 
containsString(Manifest.ERROR_FROM_FORBIDDEN));
     }
 
+    /**
+     * Expected failure: manifest attribute names must not contain ' '
+     */
     @Test(expected = BuildException.class)
     public void testIllegalName() {
         buildRule.executeTarget("testIllegalName");
         // TODO assert value
     }
 
+    /**
+     * Expected failure: manifest section names must not contain ' '
+     */
     @Test(expected = BuildException.class)
     public void testIllegalNameInSection() {
         buildRule.executeTarget("testIllegalNameInSection");
         // TODO assert value
     }
 
+    /**
+     * Expected failure: manifest attribute names must not begin with '-'
+     */
     @Test(expected = BuildException.class)
     public void testIllegalNameBegin() {
         buildRule.executeTarget("testIllegalNameInSection");
         // TODO assert value
     }
 
+    /**
+     * Expected failure: manifest attribute names must not contain '.'
+     */
     @Test(expected = BuildException.class)
     public void testIllegalName2() {
         buildRule.executeTarget("testIllegalName");
         // TODO assert value
     }
 
+    /**
+     * Expected failure: manifest attribute names must not contain '*'
+     */
     @Test(expected = BuildException.class)
     public void testIllegalName3() {
         buildRule.executeTarget("testIllegalName");

http://git-wip-us.apache.org/repos/asf/ant/blob/efaebc37/src/tests/junit/org/apache/tools/ant/taskdefs/condition/TypeFoundTest.java
----------------------------------------------------------------------
diff --git 
a/src/tests/junit/org/apache/tools/ant/taskdefs/condition/TypeFoundTest.java 
b/src/tests/junit/org/apache/tools/ant/taskdefs/condition/TypeFoundTest.java
index fabb589..dab25e1 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/condition/TypeFoundTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/condition/TypeFoundTest.java
@@ -49,6 +49,9 @@ public class TypeFoundTest {
         assertEquals("true", buildRule.getProject().getProperty("testTask"));
     }
 
+    /**
+     * Expected failure due to missing name attribute
+     */
     @Test
     public void testUndefined() {
         thrown.expect(BuildException.class);

http://git-wip-us.apache.org/repos/asf/ant/blob/efaebc37/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java
----------------------------------------------------------------------
diff --git 
a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java 
b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java
index c8c33d6..6a1346e 100644
--- 
a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java
+++ 
b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java
@@ -25,7 +25,6 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 /**
  * Tests the examples of the &lt;script&gt; task docs.

http://git-wip-us.apache.org/repos/asf/ant/blob/efaebc37/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java
----------------------------------------------------------------------
diff --git 
a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java 
b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java
index 8faaf50..30b2a00 100644
--- 
a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java
+++ 
b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java
@@ -155,6 +155,9 @@ public class XmlValidateTest {
         buildRule.executeTarget("testProperty.validXML");
     }
 
+    /**
+     * Test should fail due to unsatisfied schema
+     */
     @Test(expected = BuildException.class)
     public void testPropertySchemaForInvalidXML() {
         buildRule.executeTarget("testProperty.invalidXML");

http://git-wip-us.apache.org/repos/asf/ant/blob/efaebc37/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XsltTest.java
----------------------------------------------------------------------
diff --git 
a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XsltTest.java 
b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XsltTest.java
index 334485f..64499c1 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XsltTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XsltTest.java
@@ -47,6 +47,9 @@ public class XsltTest {
         buildRule.configureProject(TASKDEFS_DIR + "xslt.xml");
     }
 
+    /**
+     * Expected failure due to lacking DTD
+     */
     @Test(expected = BuildException.class)
     public void testCatchNoDtd() {
         buildRule.executeTarget("testCatchNoDtd");

http://git-wip-us.apache.org/repos/asf/ant/blob/efaebc37/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java
----------------------------------------------------------------------
diff --git 
a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java 
b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java
index 6558507..39d5496 100644
--- 
a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java
+++ 
b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java
@@ -115,7 +115,7 @@ public class DependTest {
     }
 
     /**
-     * Test that multi-leve inner class dependencies trigger deletion of
+     * Test that multi-level inner class dependencies trigger deletion of
      * the outer class
      */
     @Test

http://git-wip-us.apache.org/repos/asf/ant/blob/efaebc37/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java
----------------------------------------------------------------------
diff --git 
a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java
 
b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java
index 086d17c..e68eb30 100644
--- 
a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java
+++ 
b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java
@@ -123,7 +123,7 @@ public class JUnitTestRunnerTest {
     public void testStaticInitializerErrorTestCase() {
         TestRunner runner = createRunner(StaticInitializerErrorTestCase.class);
         runner.run();
-        // On junit3 this is a FAILURE, on junit4 this is an ERROR
+        // For JUnit 3 this is a FAILURE, for JUnit 4 this is an ERROR
         int ret = runner.getRetCode();
         if (ret != JUnitTestRunner.FAILURES && ret != JUnitTestRunner.ERRORS) {
             fail("Unexpected result " + ret + " from junit runner");
@@ -143,7 +143,7 @@ public class JUnitTestRunnerTest {
         // JUNIT3 test
         //assertEquals(error, JUnitTestRunner.FAILURES, runner.getRetCode());
         //@fixme as of now does not report the original stacktrace.
-        //assertTrue(error, error.indexOf("thrown on purpose") != -1);
+        //assertThat(error, error, containsString("thrown on purpose"));
     }
 
     // check that JUnit 4 synthetic AssertionFailedError gets message and 
cause from AssertionError

http://git-wip-us.apache.org/repos/asf/ant/blob/efaebc37/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
----------------------------------------------------------------------
diff --git 
a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
 
b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
index 6ba512b..267e122 100644
--- 
a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
+++ 
b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
@@ -65,6 +65,9 @@ public class ScriptDefTest {
                 containsString("Fileset basedir = " + 
baseDir.getAbsolutePath()));
     }
 
+    /**
+     * Expected failure due to lacking language attribute
+     */
     @Test
     public void testNoLang() {
         thrown.expect(BuildException.class);
@@ -72,6 +75,9 @@ public class ScriptDefTest {
         buildRule.executeTarget("nolang");
     }
 
+    /**
+     * Expected failure due to lacking name attribute
+     */
     @Test
     public void testNoName() {
         thrown.expect(BuildException.class);
@@ -114,6 +120,9 @@ public class ScriptDefTest {
         assertThat("Task2 did not execute", log, containsString("Task2"));
     }
 
+    /**
+     * Expected failure due to duplicate attribute definition
+     */
     @Test
     public void testDoubleAttribute() {
         thrown.expect(BuildException.class);

http://git-wip-us.apache.org/repos/asf/ant/blob/efaebc37/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 6248c21..8f0040f 100644
--- a/src/tests/junit/org/apache/tools/ant/types/DirSetTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/DirSetTest.java
@@ -23,7 +23,6 @@ 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;

http://git-wip-us.apache.org/repos/asf/ant/blob/efaebc37/src/tests/junit/org/apache/tools/ant/types/MapperTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/types/MapperTest.java 
b/src/tests/junit/org/apache/tools/ant/types/MapperTest.java
index 3949a15..2a17c30 100644
--- a/src/tests/junit/org/apache/tools/ant/types/MapperTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/MapperTest.java
@@ -32,12 +32,12 @@ import org.apache.tools.ant.util.MergingMapper;
 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.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 /**
  * JUnit testcases for org.apache.tools.ant.types.Mapper.
@@ -49,103 +49,96 @@ public class MapperTest {
     @Rule
     public BuildFileRule buildRule = new BuildFileRule();
 
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
+
     private Project project;
 
+    private Mapper m;
+
     @Before
     public void setUp() {
         project = new Project();
         project.setBasedir(".");
+        m = new Mapper(project);
     }
 
     @Test
-    public void testEmptyElementIfIsReference() {
-        Mapper m = new Mapper(project);
+    public void testEmptyElementIfIsReference1() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify more than one attribute 
when using refid");
         m.setFrom("*.java");
-        try {
-            m.setRefid(new Reference(project, "dummyref"));
-            fail("Can add reference to Mapper with from attribute set");
-        } catch (BuildException be) {
-            assertEquals("You must not specify more than one attribute when 
using refid",
-                    be.getMessage());
-        }
+        m.setRefid(new Reference(project, "dummy"));
+    }
 
-        m = new Mapper(project);
-        m.setRefid(new Reference(project, "dummyref"));
-        try {
-            m.setFrom("*.java");
-            fail("Can set from in Mapper that is a reference.");
-        } catch (BuildException be) {
-            assertEquals("You must not specify more than one attribute when 
using refid",
-                    be.getMessage());
-        }
+    @Test
+    public void testEmptyElementIfIsReference2() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify more than one attribute 
when using refid");
+        m.setRefid(new Reference(project, "dummy"));
+        m.setFrom("*.java");
+    }
 
-        m = new Mapper(project);
-        m.setRefid(new Reference(project, "dummyref"));
-        try {
-            m.setTo("*.java");
-            fail("Can set to in Mapper that is a reference.");
-        } catch (BuildException be) {
-            assertEquals("You must not specify more than one attribute when 
using refid",
-                    be.getMessage());
-        }
-        try {
-            Mapper.MapperType mt = new Mapper.MapperType();
-            mt.setValue("glob");
-            m.setType(mt);
-            fail("Can set type in Mapper that is a reference.");
-        } catch (BuildException be) {
-            assertEquals("You must not specify more than one attribute when 
using refid",
-                    be.getMessage());
-        }
+    @Test
+    public void testEmptyElementIfIsReference3() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify more than one attribute 
when using refid");
+        m.setRefid(new Reference(project, "dummy"));
+        m.setTo("*.java");
     }
 
     @Test
-    public void testCircularReferenceCheck() {
-        Mapper m = new Mapper(project);
+    public void testEmptyElementIfIsReference4() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("You must not specify more than one attribute 
when using refid");
+        m.setRefid(new Reference(project, "dummy"));
+        Mapper.MapperType mt = new Mapper.MapperType();
+        mt.setValue("glob");
+        m.setType(mt);
+    }
+
+    @Test
+    public void testCircularReferenceCheck1() {
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("This data type contains a circular reference.");
         project.addReference("dummy", m);
         m.setRefid(new Reference(project, "dummy"));
-        try {
-            m.getImplementation();
-            fail("Can make Mapper a Reference to itself.");
-        } catch (BuildException be) {
-            assertEquals("This data type contains a circular reference.",
-                    be.getMessage());
-        }
-
-        // dummy1 --> dummy2 --> dummy3 --> dummy1
-        Mapper m1 = new Mapper(project);
-        project.addReference("dummy1", m1);
-        m1.setRefid(new Reference(project, "dummy2"));
+        m.getImplementation();
+    }
+
+    @Test
+    public void testCircularReferenceCheck2() {
+        // dummy --> dummy2 --> dummy3 --> dummy
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("This data type contains a circular reference.");
+        project.addReference("dummy", m);
+        m.setRefid(new Reference(project, "dummy2"));
         Mapper m2 = new Mapper(project);
         project.addReference("dummy2", m2);
         m2.setRefid(new Reference(project, "dummy3"));
         Mapper m3 = new Mapper(project);
         project.addReference("dummy3", m3);
-        m3.setRefid(new Reference(project, "dummy1"));
-        try {
-            m1.getImplementation();
-            fail("Can make circular reference.");
-        } catch (BuildException be) {
-            assertEquals("This data type contains a circular reference.",
-                    be.getMessage());
-        }
-
-        // dummy1 --> dummy2 --> dummy3
+        m3.setRefid(new Reference(project, "dummy"));
+        m.getImplementation();
+    }
+
+    @Test
+    public void testCircularReferenceCheck3() {
+        // dummy --> dummy2 --> dummy3
         // (which holds a glob mapper from "*.java" to "*.class"
-        m1 = new Mapper(project);
-        project.addReference("dummy1", m1);
-        m1.setRefid(new Reference(project, "dummy2"));
-        m2 = new Mapper(project);
+        project.addReference("dummy", m);
+        m.setRefid(new Reference(project, "dummy2"));
+        Mapper m2 = new Mapper(project);
         project.addReference("dummy2", m2);
         m2.setRefid(new Reference(project, "dummy3"));
-        m3 = new Mapper(project);
+        Mapper m3 = new Mapper(project);
         project.addReference("dummy3", m3);
         Mapper.MapperType mt = new Mapper.MapperType();
         mt.setValue("glob");
         m3.setType(mt);
         m3.setFrom("*.java");
         m3.setTo("*.class");
-        FileNameMapper fmm = m1.getImplementation();
+        FileNameMapper fmm = m.getImplementation();
         assertTrue("should be glob", fmm instanceof GlobPatternMapper);
         String[] result = fmm.mapFileName("a.java");
         assertEquals("a.java should match", 1, result.length);
@@ -166,12 +159,12 @@ public class MapperTest {
         FileNameMapper mapper3 = new MergingMapper();
         mapper3.setTo("mergefile");
 
-        Mapper container = new Mapper(project);
-        container.addConfiguredMapper(mapper1);
-        container.add(mapper2);
-        container.add(mapper3);
+        // m is implicit composite
+        m.addConfiguredMapper(mapper1);
+        m.add(mapper2);
+        m.add(mapper3);
 
-        FileNameMapper fileNameMapper = container.getImplementation();
+        FileNameMapper fileNameMapper = m.getImplementation();
         String[] targets = fileNameMapper.mapFileName("fromfilename");
         assertNotNull("no filenames mapped", targets);
         assertEquals("wrong number of filenames mapped", 3, targets.length);
@@ -184,12 +177,14 @@ public class MapperTest {
                 list.contains("mergefile"));
     }
 
+    /**
+     * <pre>
+     * a --> b --> c --- def
+     *              \-- ghi
+     * </pre>
+     */
     @Test
     public void testChained() {
-
-        // a --> b --> c --- def
-        //               \-- ghi
-
         FileNameMapper mapperAB = new GlobPatternMapper();
         mapperAB.setFrom("a");
         mapperAB.setTo("b");
@@ -198,9 +193,6 @@ public class MapperTest {
         mapperBC.setFrom("b");
         mapperBC.setTo("c");
 
-        //implicit composite
-        Mapper mapperCX = new Mapper(project);
-
         FileNameMapper mapperDEF = new GlobPatternMapper();
         mapperDEF.setFrom("c");
         mapperDEF.setTo("def");
@@ -209,14 +201,15 @@ public class MapperTest {
         mapperGHI.setFrom("c");
         mapperGHI.setTo("ghi");
 
-        mapperCX.add(mapperDEF);
-        mapperCX.add(mapperGHI);
+        // m is implicit composite
+        m.add(mapperDEF);
+        m.add(mapperGHI);
 
         Mapper chained = new Mapper(project);
         chained.setClassname(ChainedMapper.class.getName());
         chained.add(mapperAB);
         chained.add(mapperBC);
-        chained.addConfiguredMapper(mapperCX);
+        chained.addConfiguredMapper(m);
 
         FileNameMapper fileNameMapper = chained.getImplementation();
         String[] targets = fileNameMapper.mapFileName("a");

http://git-wip-us.apache.org/repos/asf/ant/blob/efaebc37/src/tests/junit/org/apache/tools/ant/types/PathTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/types/PathTest.java 
b/src/tests/junit/org/apache/tools/ant/types/PathTest.java
index 57a9ea0..062fe31 100644
--- a/src/tests/junit/org/apache/tools/ant/types/PathTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/PathTest.java
@@ -29,7 +29,6 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
-import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.endsWith;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertThat;

http://git-wip-us.apache.org/repos/asf/ant/blob/efaebc37/src/tests/junit/org/apache/tools/ant/types/RedirectorElementTest.java
----------------------------------------------------------------------
diff --git 
a/src/tests/junit/org/apache/tools/ant/types/RedirectorElementTest.java 
b/src/tests/junit/org/apache/tools/ant/types/RedirectorElementTest.java
index ee97275..567d378 100644
--- a/src/tests/junit/org/apache/tools/ant/types/RedirectorElementTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/RedirectorElementTest.java
@@ -24,7 +24,6 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
-import static org.hamcrest.Matchers.both;
 import static org.hamcrest.Matchers.containsString;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;

http://git-wip-us.apache.org/repos/asf/ant/blob/efaebc37/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 15d4217..556ec6e 100644
--- a/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java
@@ -14,6 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  *
+ * <p>This doesn't actually test much, mainly reference handling.</p>
  */
 
 package org.apache.tools.ant.types;

http://git-wip-us.apache.org/repos/asf/ant/blob/efaebc37/src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java 
b/src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java
index 5b607e4..b96143f 100644
--- a/src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java
@@ -106,8 +106,7 @@ public class XMLCatalogTest {
         // has a different idea of how file URLs are created on windoze
         // ie file://c:/foo instead of file:///c:/foo
         //
-        String resultStr =
-            new URL(result.getInputSource().getSystemId()).getFile();
+        String resultStr = new 
URL(result.getInputSource().getSystemId()).getFile();
         // on Sun's Java6 this returns an unexpected number of four
         // leading slashes, at least on Linux - strip all of them
         while (resultStr.startsWith("/")) {
@@ -122,13 +121,12 @@ public class XMLCatalogTest {
         dtd.setPublicId("PUBLIC ID ONE");
         dtd.setLocation("i/dont/exist.dtd");
 
-        InputSource isResult = catalog.resolveEntity("PUBLIC ID ONE",
-                                                   "i/dont/exist.dtd");
+        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 expected = toURLString(new File(project.getBaseDir().toURL()
+                + "/i/dont/exist.dtd"));
         String resultStr = fileURLPartWithoutLeadingSlashes((SAXSource) 
result);
         assertThat("Nonexistent Catalog entry return input with a system ID 
like "
                    + expected + " but was " + resultStr,

http://git-wip-us.apache.org/repos/asf/ant/blob/efaebc37/src/tests/junit/org/apache/tools/ant/types/mappers/MapperResult.java
----------------------------------------------------------------------
diff --git 
a/src/tests/junit/org/apache/tools/ant/types/mappers/MapperResult.java 
b/src/tests/junit/org/apache/tools/ant/types/mappers/MapperResult.java
index 8382e05..1f85a88 100644
--- a/src/tests/junit/org/apache/tools/ant/types/mappers/MapperResult.java
+++ b/src/tests/junit/org/apache/tools/ant/types/mappers/MapperResult.java
@@ -23,6 +23,9 @@ import org.apache.tools.ant.Task;
 import org.apache.tools.ant.types.Mapper;
 import org.apache.tools.ant.util.FileNameMapper;
 
+import java.util.Arrays;
+import java.util.stream.Collectors;
+
 /**
  * This is a test task to show the result of a mapper
  * on a specific input.
@@ -80,14 +83,7 @@ public class MapperResult extends Task {
         if (result == null) {
             flattened = NULL_MAPPER_RESULT;
         } else {
-            StringBuilder b = new StringBuilder();
-            for (int i = 0; i < result.length; ++i) {
-                if (i != 0) {
-                    b.append("|");
-                }
-                b.append(result[i]);
-            }
-            flattened = b.toString();
+            flattened = 
Arrays.asList(result).stream().collect(Collectors.joining("|"));
         }
         if (!flattened.equals(output)) {
             throw new BuildException(failMessage + " got " + flattened + " 
expected " + output);

http://git-wip-us.apache.org/repos/asf/ant/blob/efaebc37/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 de5a5a3..655353f 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
@@ -26,9 +26,7 @@ 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.hamcrest.Matchers.endsWith;
 

http://git-wip-us.apache.org/repos/asf/ant/blob/efaebc37/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java
----------------------------------------------------------------------
diff --git 
a/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java 
b/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java
index 4928e76..10b14c4 100644
--- 
a/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java
+++ 
b/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java
@@ -41,15 +41,10 @@ public class ContainsRegexpTest {
     @Test
     public void testContainsRegexp() {
         buildRule.executeTarget("containsregexp");
-        File dir = new File(buildRule.getOutputDir(), "regexpseltestdest");
-        File[] files = dir.listFiles();
-        int filecount = files.length;
+        File[] files = new File(buildRule.getOutputDir(), 
"regexpseltestdest").listFiles();
 
-        if (filecount != 1)  {
-            assertEquals("ContainsRegexp test should have copied 1 file",
-                         1, files.length);
-
-        }
+        assertEquals("ContainsRegexp test should have copied 1 file",
+                1, files.length);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/ant/blob/efaebc37/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
----------------------------------------------------------------------
diff --git 
a/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
 
b/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
index e5d5216..3f9165c 100644
--- 
a/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
+++ 
b/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
@@ -95,8 +95,7 @@ public class ModifiedSelectorTest {
         String name = "this-is-not-a-valid-cache-name";
         thrown.expect(BuildException.class);
         thrown.expectMessage(name + " is not a legal value for this 
attribute");
-        ModifiedSelector.CacheName cacheName = new 
ModifiedSelector.CacheName();
-        cacheName.setValue(name);
+        new ModifiedSelector.CacheName().setValue(name);
     }
 
     /** Test correct use of cache names. */
@@ -105,8 +104,7 @@ public class ModifiedSelectorTest {
         String name = "this-is-not-a-valid-algorithm-name";
         thrown.expect(BuildException.class);
         thrown.expectMessage(name + " is not a legal value for this 
attribute");
-        ModifiedSelector.AlgorithmName algoName = new 
ModifiedSelector.AlgorithmName();
-        algoName.setValue(name);
+        new ModifiedSelector.AlgorithmName().setValue(name);
     }
 
     /** Test correct use of comparator names. */
@@ -115,8 +113,7 @@ public class ModifiedSelectorTest {
         String name = "this-is-not-a-valid-comparator-name";
         thrown.expect(BuildException.class);
         thrown.expectMessage(name + " is not a legal value for this 
attribute");
-        ModifiedSelector.ComparatorName compName = new 
ModifiedSelector.ComparatorName();
-        compName.setValue(name);
+        new ModifiedSelector.ComparatorName().setValue(name);
     }
 
     /** Test correct use of algorithm names. */
@@ -906,7 +903,7 @@ public class ModifiedSelectorTest {
     }
 
     /**
-     * MockProject wrappes a very small ant project (one target, one task)
+     * MockProject wraps a very small ant project (one target, one task)
      * but provides public methods to fire the build events.
      */
     private class MockProject extends Project {

http://git-wip-us.apache.org/repos/asf/ant/blob/efaebc37/src/tests/junit/org/apache/tools/mail/MailMessageTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/mail/MailMessageTest.java 
b/src/tests/junit/org/apache/tools/mail/MailMessageTest.java
index 56407ac..805a66b 100644
--- a/src/tests/junit/org/apache/tools/mail/MailMessageTest.java
+++ b/src/tests/junit/org/apache/tools/mail/MailMessageTest.java
@@ -18,6 +18,9 @@
 
 package org.apache.tools.mail;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.ByteArrayOutputStream;
@@ -28,7 +31,6 @@ import java.io.PrintStream;
 import java.net.InetAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
-import java.util.Enumeration;
 import java.util.Vector;
 
 import org.apache.tools.ant.BuildException;
@@ -36,9 +38,6 @@ import org.junit.Before;
 import org.junit.Test;
 import org.junit.internal.AssumptionViolatedException;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-
 /**
  * JUnit testcases for org.apache.tools.mail.MailMessage.
  *
@@ -603,26 +602,18 @@ public class MailMessageTest {
             try {
                 msg.from(from);
 
-                Enumeration<String> e;
-
-                e = replyToList.elements();
-                while (e.hasMoreElements()) {
-                    msg.replyto(e.nextElement());
-                }
+                replyToList.forEach(e -> msg.replyto(e));
 
-                e = toList.elements();
-                while (e.hasMoreElements()) {
-                    msg.to(e.nextElement());
+                for (String e : toList) {
+                    msg.to(e);
                 }
 
-                e = ccList.elements();
-                while (e.hasMoreElements()) {
-                    msg.cc(e.nextElement());
+                for (String e : ccList) {
+                    msg.cc(e);
                 }
 
-                e = bccList.elements();
-                while (e.hasMoreElements()) {
-                    msg.bcc(e.nextElement());
+                for (String e : bccList) {
+                    msg.bcc(e);
                 }
 
                 if (subject != null) {

Reply via email to