Browse Source

Tidy up/optimize the code

master
Gintas Grigelionis 7 years ago
parent
commit
efaebc3724
22 changed files with 151 additions and 154 deletions
  1. +2
    -2
      src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java
  2. +2
    -3
      src/tests/junit/org/apache/tools/ant/taskdefs/LoadFileTest.java
  3. +4
    -4
      src/tests/junit/org/apache/tools/ant/taskdefs/MakeUrlTest.java
  4. +21
    -6
      src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java
  5. +3
    -0
      src/tests/junit/org/apache/tools/ant/taskdefs/condition/TypeFoundTest.java
  6. +0
    -1
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java
  7. +3
    -0
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java
  8. +3
    -0
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/XsltTest.java
  9. +1
    -1
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java
  10. +2
    -2
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java
  11. +9
    -0
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
  12. +0
    -1
      src/tests/junit/org/apache/tools/ant/types/DirSetTest.java
  13. +75
    -82
      src/tests/junit/org/apache/tools/ant/types/MapperTest.java
  14. +0
    -1
      src/tests/junit/org/apache/tools/ant/types/PathTest.java
  15. +0
    -1
      src/tests/junit/org/apache/tools/ant/types/RedirectorElementTest.java
  16. +1
    -0
      src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java
  17. +4
    -6
      src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java
  18. +4
    -8
      src/tests/junit/org/apache/tools/ant/types/mappers/MapperResult.java
  19. +0
    -2
      src/tests/junit/org/apache/tools/ant/types/resources/MultiRootFileSetTest.java
  20. +3
    -8
      src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java
  21. +4
    -7
      src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
  22. +10
    -19
      src/tests/junit/org/apache/tools/mail/MailMessageTest.java

+ 2
- 2
src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java View File

@@ -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() { private static String getTestClassPath() {
String classpath = System.getProperty("build.tests"); String classpath = System.getProperty("build.tests");


+ 2
- 3
src/tests/junit/org/apache/tools/ant/taskdefs/LoadFileTest.java View File

@@ -134,9 +134,8 @@ public class LoadFileTest {
@Test @Test
public final void testStripJavaComments() throws BuildException { public final void testStripJavaComments() throws BuildException {
buildRule.executeTarget("testStripJavaComments"); 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 @Test


+ 4
- 4
src/tests/junit/org/apache/tools/ant/taskdefs/MakeUrlTest.java View File

@@ -50,28 +50,28 @@ public class MakeUrlTest {
@Test @Test
public void testEmpty() { public void testEmpty() {
thrown.expect(BuildException.class); thrown.expect(BuildException.class);
thrown.expectMessage("property");
thrown.expectMessage("No property defined");
buildRule.executeTarget("testEmpty"); buildRule.executeTarget("testEmpty");
} }


@Test @Test
public void testNoProperty() { public void testNoProperty() {
thrown.expect(BuildException.class); thrown.expect(BuildException.class);
thrown.expectMessage("property");
thrown.expectMessage("No property defined");
buildRule.executeTarget("testNoProperty"); buildRule.executeTarget("testNoProperty");
} }


@Test @Test
public void testNoFile() { public void testNoFile() {
thrown.expect(BuildException.class); thrown.expect(BuildException.class);
thrown.expectMessage("file");
thrown.expectMessage("No files defined");
buildRule.executeTarget("testNoFile"); buildRule.executeTarget("testNoFile");
} }


@Test @Test
public void testValidation() { public void testValidation() {
thrown.expect(BuildException.class); thrown.expect(BuildException.class);
thrown.expectMessage("file");
thrown.expectMessage("A source file is missing");
buildRule.executeTarget("testValidation"); buildRule.executeTarget("testValidation");
} }




+ 21
- 6
src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java View File

@@ -263,12 +263,12 @@ public class ManifestTest {
assertEquals("Class-Path attribute was not set correctly - ", assertEquals("Class-Path attribute was not set correctly - ",
LONG_LINE, classpath); 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<>(); Set<String> set = new HashSet<>();
try (FileReader fin = new FileReader(expandedManifest)) { try (FileReader fin = new FileReader(expandedManifest)) {
@@ -388,30 +388,45 @@ public class ManifestTest {
assertThat(buildRule.getLog(), containsString(Manifest.ERROR_FROM_FORBIDDEN)); assertThat(buildRule.getLog(), containsString(Manifest.ERROR_FROM_FORBIDDEN));
} }


/**
* Expected failure: manifest attribute names must not contain ' '
*/
@Test(expected = BuildException.class) @Test(expected = BuildException.class)
public void testIllegalName() { public void testIllegalName() {
buildRule.executeTarget("testIllegalName"); buildRule.executeTarget("testIllegalName");
// TODO assert value // TODO assert value
} }


/**
* Expected failure: manifest section names must not contain ' '
*/
@Test(expected = BuildException.class) @Test(expected = BuildException.class)
public void testIllegalNameInSection() { public void testIllegalNameInSection() {
buildRule.executeTarget("testIllegalNameInSection"); buildRule.executeTarget("testIllegalNameInSection");
// TODO assert value // TODO assert value
} }


/**
* Expected failure: manifest attribute names must not begin with '-'
*/
@Test(expected = BuildException.class) @Test(expected = BuildException.class)
public void testIllegalNameBegin() { public void testIllegalNameBegin() {
buildRule.executeTarget("testIllegalNameInSection"); buildRule.executeTarget("testIllegalNameInSection");
// TODO assert value // TODO assert value
} }


/**
* Expected failure: manifest attribute names must not contain '.'
*/
@Test(expected = BuildException.class) @Test(expected = BuildException.class)
public void testIllegalName2() { public void testIllegalName2() {
buildRule.executeTarget("testIllegalName"); buildRule.executeTarget("testIllegalName");
// TODO assert value // TODO assert value
} }


/**
* Expected failure: manifest attribute names must not contain '*'
*/
@Test(expected = BuildException.class) @Test(expected = BuildException.class)
public void testIllegalName3() { public void testIllegalName3() {
buildRule.executeTarget("testIllegalName"); buildRule.executeTarget("testIllegalName");


+ 3
- 0
src/tests/junit/org/apache/tools/ant/taskdefs/condition/TypeFoundTest.java View File

@@ -49,6 +49,9 @@ public class TypeFoundTest {
assertEquals("true", buildRule.getProject().getProperty("testTask")); assertEquals("true", buildRule.getProject().getProperty("testTask"));
} }


/**
* Expected failure due to missing name attribute
*/
@Test @Test
public void testUndefined() { public void testUndefined() {
thrown.expect(BuildException.class); thrown.expect(BuildException.class);


+ 0
- 1
src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java View File

@@ -25,7 +25,6 @@ import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;


import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;


/** /**
* Tests the examples of the &lt;script&gt; task docs. * Tests the examples of the &lt;script&gt; task docs.


+ 3
- 0
src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java View File

@@ -155,6 +155,9 @@ public class XmlValidateTest {
buildRule.executeTarget("testProperty.validXML"); buildRule.executeTarget("testProperty.validXML");
} }


/**
* Test should fail due to unsatisfied schema
*/
@Test(expected = BuildException.class) @Test(expected = BuildException.class)
public void testPropertySchemaForInvalidXML() { public void testPropertySchemaForInvalidXML() {
buildRule.executeTarget("testProperty.invalidXML"); buildRule.executeTarget("testProperty.invalidXML");


+ 3
- 0
src/tests/junit/org/apache/tools/ant/taskdefs/optional/XsltTest.java View File

@@ -47,6 +47,9 @@ public class XsltTest {
buildRule.configureProject(TASKDEFS_DIR + "xslt.xml"); buildRule.configureProject(TASKDEFS_DIR + "xslt.xml");
} }


/**
* Expected failure due to lacking DTD
*/
@Test(expected = BuildException.class) @Test(expected = BuildException.class)
public void testCatchNoDtd() { public void testCatchNoDtd() {
buildRule.executeTarget("testCatchNoDtd"); buildRule.executeTarget("testCatchNoDtd");


+ 1
- 1
src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java View File

@@ -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 * the outer class
*/ */
@Test @Test


+ 2
- 2
src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java View File

@@ -123,7 +123,7 @@ public class JUnitTestRunnerTest {
public void testStaticInitializerErrorTestCase() { public void testStaticInitializerErrorTestCase() {
TestRunner runner = createRunner(StaticInitializerErrorTestCase.class); TestRunner runner = createRunner(StaticInitializerErrorTestCase.class);
runner.run(); 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(); int ret = runner.getRetCode();
if (ret != JUnitTestRunner.FAILURES && ret != JUnitTestRunner.ERRORS) { if (ret != JUnitTestRunner.FAILURES && ret != JUnitTestRunner.ERRORS) {
fail("Unexpected result " + ret + " from junit runner"); fail("Unexpected result " + ret + " from junit runner");
@@ -143,7 +143,7 @@ public class JUnitTestRunnerTest {
// JUNIT3 test // JUNIT3 test
//assertEquals(error, JUnitTestRunner.FAILURES, runner.getRetCode()); //assertEquals(error, JUnitTestRunner.FAILURES, runner.getRetCode());
//@fixme as of now does not report the original stacktrace. //@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 // check that JUnit 4 synthetic AssertionFailedError gets message and cause from AssertionError


+ 9
- 0
src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java View File

@@ -65,6 +65,9 @@ public class ScriptDefTest {
containsString("Fileset basedir = " + baseDir.getAbsolutePath())); containsString("Fileset basedir = " + baseDir.getAbsolutePath()));
} }


/**
* Expected failure due to lacking language attribute
*/
@Test @Test
public void testNoLang() { public void testNoLang() {
thrown.expect(BuildException.class); thrown.expect(BuildException.class);
@@ -72,6 +75,9 @@ public class ScriptDefTest {
buildRule.executeTarget("nolang"); buildRule.executeTarget("nolang");
} }


/**
* Expected failure due to lacking name attribute
*/
@Test @Test
public void testNoName() { public void testNoName() {
thrown.expect(BuildException.class); thrown.expect(BuildException.class);
@@ -114,6 +120,9 @@ public class ScriptDefTest {
assertThat("Task2 did not execute", log, containsString("Task2")); assertThat("Task2 did not execute", log, containsString("Task2"));
} }


/**
* Expected failure due to duplicate attribute definition
*/
@Test @Test
public void testDoubleAttribute() { public void testDoubleAttribute() {
thrown.expect(BuildException.class); thrown.expect(BuildException.class);


+ 0
- 1
src/tests/junit/org/apache/tools/ant/types/DirSetTest.java View File

@@ -23,7 +23,6 @@ import java.io.FileOutputStream;


import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;


+ 75
- 82
src/tests/junit/org/apache/tools/ant/types/MapperTest.java View File

@@ -32,12 +32,12 @@ import org.apache.tools.ant.util.MergingMapper;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;


/** /**
* JUnit testcases for org.apache.tools.ant.types.Mapper. * JUnit testcases for org.apache.tools.ant.types.Mapper.
@@ -49,103 +49,96 @@ public class MapperTest {
@Rule @Rule
public BuildFileRule buildRule = new BuildFileRule(); public BuildFileRule buildRule = new BuildFileRule();


@Rule
public ExpectedException thrown = ExpectedException.none();

private Project project; private Project project;


private Mapper m;

@Before @Before
public void setUp() { public void setUp() {
project = new Project(); project = new Project();
project.setBasedir("."); project.setBasedir(".");
m = new Mapper(project);
} }


@Test @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"); 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 @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); project.addReference("dummy", m);
m.setRefid(new Reference(project, "dummy")); 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); Mapper m2 = new Mapper(project);
project.addReference("dummy2", m2); project.addReference("dummy2", m2);
m2.setRefid(new Reference(project, "dummy3")); m2.setRefid(new Reference(project, "dummy3"));
Mapper m3 = new Mapper(project); Mapper m3 = new Mapper(project);
project.addReference("dummy3", m3); 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" // (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); project.addReference("dummy2", m2);
m2.setRefid(new Reference(project, "dummy3")); m2.setRefid(new Reference(project, "dummy3"));
m3 = new Mapper(project);
Mapper m3 = new Mapper(project);
project.addReference("dummy3", m3); project.addReference("dummy3", m3);
Mapper.MapperType mt = new Mapper.MapperType(); Mapper.MapperType mt = new Mapper.MapperType();
mt.setValue("glob"); mt.setValue("glob");
m3.setType(mt); m3.setType(mt);
m3.setFrom("*.java"); m3.setFrom("*.java");
m3.setTo("*.class"); m3.setTo("*.class");
FileNameMapper fmm = m1.getImplementation();
FileNameMapper fmm = m.getImplementation();
assertTrue("should be glob", fmm instanceof GlobPatternMapper); assertTrue("should be glob", fmm instanceof GlobPatternMapper);
String[] result = fmm.mapFileName("a.java"); String[] result = fmm.mapFileName("a.java");
assertEquals("a.java should match", 1, result.length); assertEquals("a.java should match", 1, result.length);
@@ -166,12 +159,12 @@ public class MapperTest {
FileNameMapper mapper3 = new MergingMapper(); FileNameMapper mapper3 = new MergingMapper();
mapper3.setTo("mergefile"); 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"); String[] targets = fileNameMapper.mapFileName("fromfilename");
assertNotNull("no filenames mapped", targets); assertNotNull("no filenames mapped", targets);
assertEquals("wrong number of filenames mapped", 3, targets.length); assertEquals("wrong number of filenames mapped", 3, targets.length);
@@ -184,12 +177,14 @@ public class MapperTest {
list.contains("mergefile")); list.contains("mergefile"));
} }


/**
* <pre>
* a --> b --> c --- def
* \-- ghi
* </pre>
*/
@Test @Test
public void testChained() { public void testChained() {

// a --> b --> c --- def
// \-- ghi

FileNameMapper mapperAB = new GlobPatternMapper(); FileNameMapper mapperAB = new GlobPatternMapper();
mapperAB.setFrom("a"); mapperAB.setFrom("a");
mapperAB.setTo("b"); mapperAB.setTo("b");
@@ -198,9 +193,6 @@ public class MapperTest {
mapperBC.setFrom("b"); mapperBC.setFrom("b");
mapperBC.setTo("c"); mapperBC.setTo("c");


//implicit composite
Mapper mapperCX = new Mapper(project);

FileNameMapper mapperDEF = new GlobPatternMapper(); FileNameMapper mapperDEF = new GlobPatternMapper();
mapperDEF.setFrom("c"); mapperDEF.setFrom("c");
mapperDEF.setTo("def"); mapperDEF.setTo("def");
@@ -209,14 +201,15 @@ public class MapperTest {
mapperGHI.setFrom("c"); mapperGHI.setFrom("c");
mapperGHI.setTo("ghi"); mapperGHI.setTo("ghi");


mapperCX.add(mapperDEF);
mapperCX.add(mapperGHI);
// m is implicit composite
m.add(mapperDEF);
m.add(mapperGHI);


Mapper chained = new Mapper(project); Mapper chained = new Mapper(project);
chained.setClassname(ChainedMapper.class.getName()); chained.setClassname(ChainedMapper.class.getName());
chained.add(mapperAB); chained.add(mapperAB);
chained.add(mapperBC); chained.add(mapperBC);
chained.addConfiguredMapper(mapperCX);
chained.addConfiguredMapper(m);


FileNameMapper fileNameMapper = chained.getImplementation(); FileNameMapper fileNameMapper = chained.getImplementation();
String[] targets = fileNameMapper.mapFileName("a"); String[] targets = fileNameMapper.mapFileName("a");


+ 0
- 1
src/tests/junit/org/apache/tools/ant/types/PathTest.java View File

@@ -29,7 +29,6 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;


import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.endsWith;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;


+ 0
- 1
src/tests/junit/org/apache/tools/ant/types/RedirectorElementTest.java View File

@@ -24,7 +24,6 @@ import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;


import static org.hamcrest.Matchers.both;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;


+ 1
- 0
src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java View File

@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
* <p>This doesn't actually test much, mainly reference handling.</p>
*/ */


package org.apache.tools.ant.types; package org.apache.tools.ant.types;


+ 4
- 6
src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java View File

@@ -106,8 +106,7 @@ public class XMLCatalogTest {
// has a different idea of how file URLs are created on windoze // has a different idea of how file URLs are created on windoze
// ie file://c:/foo instead of file:///c:/foo // 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 // on Sun's Java6 this returns an unexpected number of four
// leading slashes, at least on Linux - strip all of them // leading slashes, at least on Linux - strip all of them
while (resultStr.startsWith("/")) { while (resultStr.startsWith("/")) {
@@ -122,13 +121,12 @@ public class XMLCatalogTest {
dtd.setPublicId("PUBLIC ID ONE"); dtd.setPublicId("PUBLIC ID ONE");
dtd.setLocation("i/dont/exist.dtd"); 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); assertNull("Nonexistent Catalog entry should not be returned", isResult);


Source result = catalog.resolve("i/dont/exist.dtd", null); 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); String resultStr = fileURLPartWithoutLeadingSlashes((SAXSource) result);
assertThat("Nonexistent Catalog entry return input with a system ID like " assertThat("Nonexistent Catalog entry return input with a system ID like "
+ expected + " but was " + resultStr, + expected + " but was " + resultStr,


+ 4
- 8
src/tests/junit/org/apache/tools/ant/types/mappers/MapperResult.java View File

@@ -23,6 +23,9 @@ import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Mapper; import org.apache.tools.ant.types.Mapper;
import org.apache.tools.ant.util.FileNameMapper; 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 * This is a test task to show the result of a mapper
* on a specific input. * on a specific input.
@@ -80,14 +83,7 @@ public class MapperResult extends Task {
if (result == null) { if (result == null) {
flattened = NULL_MAPPER_RESULT; flattened = NULL_MAPPER_RESULT;
} else { } 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)) { if (!flattened.equals(output)) {
throw new BuildException(failMessage + " got " + flattened + " expected " + output); throw new BuildException(failMessage + " got " + flattened + " expected " + output);


+ 0
- 2
src/tests/junit/org/apache/tools/ant/types/resources/MultiRootFileSetTest.java View File

@@ -26,9 +26,7 @@ import org.apache.tools.ant.types.AbstractFileSet;
import org.apache.tools.ant.types.AbstractFileSetTest; import org.apache.tools.ant.types.AbstractFileSetTest;
import org.apache.tools.ant.types.Reference; import org.apache.tools.ant.types.Reference;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;


import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.endsWith;




+ 3
- 8
src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java View File

@@ -41,15 +41,10 @@ public class ContainsRegexpTest {
@Test @Test
public void testContainsRegexp() { public void testContainsRegexp() {
buildRule.executeTarget("containsregexp"); 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);
} }


} }

+ 4
- 7
src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java View File

@@ -95,8 +95,7 @@ public class ModifiedSelectorTest {
String name = "this-is-not-a-valid-cache-name"; String name = "this-is-not-a-valid-cache-name";
thrown.expect(BuildException.class); thrown.expect(BuildException.class);
thrown.expectMessage(name + " is not a legal value for this attribute"); 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. */ /** Test correct use of cache names. */
@@ -105,8 +104,7 @@ public class ModifiedSelectorTest {
String name = "this-is-not-a-valid-algorithm-name"; String name = "this-is-not-a-valid-algorithm-name";
thrown.expect(BuildException.class); thrown.expect(BuildException.class);
thrown.expectMessage(name + " is not a legal value for this attribute"); 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. */ /** Test correct use of comparator names. */
@@ -115,8 +113,7 @@ public class ModifiedSelectorTest {
String name = "this-is-not-a-valid-comparator-name"; String name = "this-is-not-a-valid-comparator-name";
thrown.expect(BuildException.class); thrown.expect(BuildException.class);
thrown.expectMessage(name + " is not a legal value for this attribute"); 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. */ /** 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. * but provides public methods to fire the build events.
*/ */
private class MockProject extends Project { private class MockProject extends Project {


+ 10
- 19
src/tests/junit/org/apache/tools/mail/MailMessageTest.java View File

@@ -18,6 +18,9 @@


package org.apache.tools.mail; package org.apache.tools.mail;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@@ -28,7 +31,6 @@ import java.io.PrintStream;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.util.Enumeration;
import java.util.Vector; import java.util.Vector;


import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
@@ -36,9 +38,6 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.internal.AssumptionViolatedException; 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. * JUnit testcases for org.apache.tools.mail.MailMessage.
* *
@@ -603,26 +602,18 @@ public class MailMessageTest {
try { try {
msg.from(from); 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) { if (subject != null) {


Loading…
Cancel
Save