| @@ -29,6 +29,7 @@ import org.apache.tools.ant.DefaultLogger; | |||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| import org.apache.tools.ant.util.FileUtils; | import org.apache.tools.ant.util.FileUtils; | ||||
| import org.junit.After; | import org.junit.After; | ||||
| import org.junit.Before; | |||||
| import org.junit.Test; | import org.junit.Test; | ||||
| import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
| @@ -38,16 +39,33 @@ import static org.junit.Assert.assertEquals; | |||||
| */ | */ | ||||
| public class EchoTest { | public class EchoTest { | ||||
| private Project p; | |||||
| private EchoTestLogger logger; | |||||
| private Echo echo; | |||||
| private File removeThis; | private File removeThis; | ||||
| @Test | |||||
| public void testLogBlankEcho() { | |||||
| Project p = new Project(); | |||||
| @Before | |||||
| public void setUp() { | |||||
| p = new Project(); | |||||
| p.init(); | p.init(); | ||||
| EchoTestLogger logger = new EchoTestLogger(); | |||||
| logger = new EchoTestLogger(); | |||||
| p.addBuildListener(logger); | p.addBuildListener(logger); | ||||
| Echo echo = new Echo(); | |||||
| echo = new Echo(); | |||||
| echo.setProject(p); | echo.setProject(p); | ||||
| } | |||||
| @After | |||||
| public void tearDown() { | |||||
| if (removeThis != null && removeThis.exists() && !removeThis.delete()) { | |||||
| removeThis.deleteOnExit(); | |||||
| } | |||||
| } | |||||
| @Test | |||||
| public void testLogBlankEcho() { | |||||
| echo.setTaskName("testLogBlankEcho"); | echo.setTaskName("testLogBlankEcho"); | ||||
| echo.execute(); | echo.execute(); | ||||
| assertEquals("[testLogBlankEcho] ", logger.lastLoggedMessage); | assertEquals("[testLogBlankEcho] ", logger.lastLoggedMessage); | ||||
| @@ -55,12 +73,6 @@ public class EchoTest { | |||||
| @Test | @Test | ||||
| public void testLogUTF8Echo() throws IOException { | public void testLogUTF8Echo() throws IOException { | ||||
| Project p = new Project(); | |||||
| p.init(); | |||||
| EchoTestLogger logger = new EchoTestLogger(); | |||||
| p.addBuildListener(logger); | |||||
| Echo echo = new Echo(); | |||||
| echo.setProject(p); | |||||
| echo.setTaskName("testLogUTF8Echo"); | echo.setTaskName("testLogUTF8Echo"); | ||||
| echo.setMessage("\u00e4\u00a9"); | echo.setMessage("\u00e4\u00a9"); | ||||
| removeThis = new File("abc.txt"); | removeThis = new File("abc.txt"); | ||||
| @@ -71,15 +83,6 @@ public class EchoTest { | |||||
| assertEquals(x, "\u00e4\u00a9"); | assertEquals(x, "\u00e4\u00a9"); | ||||
| } | } | ||||
| @After | |||||
| public void tearDown() { | |||||
| if (removeThis != null && removeThis.exists()) { | |||||
| if (!removeThis.delete()) { | |||||
| removeThis.deleteOnExit(); | |||||
| } | |||||
| } | |||||
| } | |||||
| private class EchoTestLogger extends DefaultLogger { | private class EchoTestLogger extends DefaultLogger { | ||||
| String lastLoggedMessage; | String lastLoggedMessage; | ||||
| @@ -55,17 +55,18 @@ public class ParallelTest { | |||||
| /** the build file associated with this test */ | /** the build file associated with this test */ | ||||
| public static final String TEST_BUILD_FILE = "src/etc/testcases/taskdefs/parallel.xml"; | public static final String TEST_BUILD_FILE = "src/etc/testcases/taskdefs/parallel.xml"; | ||||
| private Project p; | |||||
| /** The JUnit setup method */ | /** The JUnit setup method */ | ||||
| @Before | @Before | ||||
| public void setUp() { | public void setUp() { | ||||
| buildRule.configureProject(TEST_BUILD_FILE); | buildRule.configureProject(TEST_BUILD_FILE); | ||||
| p = buildRule.getProject(); | |||||
| } | } | ||||
| /** tests basic operation of the parallel task */ | /** tests basic operation of the parallel task */ | ||||
| @Test | @Test | ||||
| public void testBasic() { | public void testBasic() { | ||||
| // should get no output at all | // should get no output at all | ||||
| Project p = buildRule.getProject(); | |||||
| p.setUserProperty("test.direct", DIRECT_MESSAGE); | p.setUserProperty("test.direct", DIRECT_MESSAGE); | ||||
| p.setUserProperty("test.delayed", DELAYED_MESSAGE); | p.setUserProperty("test.delayed", DELAYED_MESSAGE); | ||||
| buildRule.executeTarget("testBasic"); | buildRule.executeTarget("testBasic"); | ||||
| @@ -81,7 +82,6 @@ public class ParallelTest { | |||||
| @Test | @Test | ||||
| public void testThreadCount() { | public void testThreadCount() { | ||||
| // should get no output at all | // should get no output at all | ||||
| Project p = buildRule.getProject(); | |||||
| p.setUserProperty("test.direct", DIRECT_MESSAGE); | p.setUserProperty("test.direct", DIRECT_MESSAGE); | ||||
| p.setUserProperty("test.delayed", DELAYED_MESSAGE); | p.setUserProperty("test.delayed", DELAYED_MESSAGE); | ||||
| buildRule.executeTarget("testThreadCount"); | buildRule.executeTarget("testThreadCount"); | ||||
| @@ -140,7 +140,6 @@ public class ParallelTest { | |||||
| // should get no output at all | // should get no output at all | ||||
| thrown.expect(BuildException.class); | thrown.expect(BuildException.class); | ||||
| thrown.expectMessage(FAILURE_MESSAGE); | thrown.expectMessage(FAILURE_MESSAGE); | ||||
| Project p = buildRule.getProject(); | |||||
| p.setUserProperty("test.failure", FAILURE_MESSAGE); | p.setUserProperty("test.failure", FAILURE_MESSAGE); | ||||
| p.setUserProperty("test.delayed", DELAYED_MESSAGE); | p.setUserProperty("test.delayed", DELAYED_MESSAGE); | ||||
| buildRule.executeTarget("testFail"); | buildRule.executeTarget("testFail"); | ||||
| @@ -149,7 +148,6 @@ public class ParallelTest { | |||||
| /** tests the demuxing of output streams in a multithreaded situation */ | /** tests the demuxing of output streams in a multithreaded situation */ | ||||
| @Test | @Test | ||||
| public void testDemux() { | public void testDemux() { | ||||
| Project p = buildRule.getProject(); | |||||
| p.addTaskDefinition("demuxtest", DemuxOutputTask.class); | p.addTaskDefinition("demuxtest", DemuxOutputTask.class); | ||||
| synchronized (System.out) { | synchronized (System.out) { | ||||
| PrintStream out = System.out; | PrintStream out = System.out; | ||||
| @@ -18,6 +18,7 @@ | |||||
| package org.apache.tools.ant.taskdefs.condition; | package org.apache.tools.ant.taskdefs.condition; | ||||
| import org.junit.Before; | |||||
| import org.junit.Test; | import org.junit.Test; | ||||
| import static org.junit.Assert.assertFalse; | import static org.junit.Assert.assertFalse; | ||||
| @@ -29,9 +30,15 @@ import static org.junit.Assert.assertTrue; | |||||
| */ | */ | ||||
| public class EqualsTest { | public class EqualsTest { | ||||
| private Equals eq; | |||||
| @Before | |||||
| public void setUp() { | |||||
| eq = new Equals(); | |||||
| } | |||||
| @Test | @Test | ||||
| public void testTrim() { | public void testTrim() { | ||||
| Equals eq = new Equals(); | |||||
| eq.setArg1("a"); | eq.setArg1("a"); | ||||
| eq.setArg2(" a"); | eq.setArg2(" a"); | ||||
| assertFalse(eq.eval()); | assertFalse(eq.eval()); | ||||
| @@ -45,7 +52,6 @@ public class EqualsTest { | |||||
| @Test | @Test | ||||
| public void testCaseSensitive() { | public void testCaseSensitive() { | ||||
| Equals eq = new Equals(); | |||||
| eq.setArg1("a"); | eq.setArg1("a"); | ||||
| eq.setArg2("A"); | eq.setArg2("A"); | ||||
| assertFalse(eq.eval()); | assertFalse(eq.eval()); | ||||
| @@ -44,6 +44,8 @@ public class CommandlineJavaTest { | |||||
| private Project project; | private Project project; | ||||
| private CommandlineJava c; | |||||
| @Before | @Before | ||||
| public void setUp() { | public void setUp() { | ||||
| project = new Project(); | project = new Project(); | ||||
| @@ -55,6 +57,7 @@ public class CommandlineJavaTest { | |||||
| if (cloneVm != null) { | if (cloneVm != null) { | ||||
| System.setProperty("ant.build.clonevm", "false"); | System.setProperty("ant.build.clonevm", "false"); | ||||
| } | } | ||||
| c = new CommandlineJava(); | |||||
| } | } | ||||
| @After | @After | ||||
| @@ -72,7 +75,6 @@ public class CommandlineJavaTest { | |||||
| @Test | @Test | ||||
| public void testGetCommandline() throws CloneNotSupportedException { | public void testGetCommandline() throws CloneNotSupportedException { | ||||
| assertNotNull("Ant home not set", System.getProperty("ant.home")); | assertNotNull("Ant home not set", System.getProperty("ant.home")); | ||||
| CommandlineJava c = new CommandlineJava(); | |||||
| c.createArgument().setValue("org.apache.tools.ant.CommandlineJavaTest"); | c.createArgument().setValue("org.apache.tools.ant.CommandlineJavaTest"); | ||||
| c.setClassname("junit.textui.TestRunner"); | c.setClassname("junit.textui.TestRunner"); | ||||
| c.createVmArgument().setValue("-Djava.compiler=NONE"); | c.createVmArgument().setValue("-Djava.compiler=NONE"); | ||||
| @@ -108,7 +110,6 @@ public class CommandlineJavaTest { | |||||
| @Test | @Test | ||||
| public void testJarOption() { | public void testJarOption() { | ||||
| CommandlineJava c = new CommandlineJava(); | |||||
| c.createArgument().setValue("arg1"); | c.createArgument().setValue("arg1"); | ||||
| c.setJar("myfile.jar"); | c.setJar("myfile.jar"); | ||||
| c.createVmArgument().setValue("-classic"); | c.createVmArgument().setValue("-classic"); | ||||
| @@ -126,7 +127,6 @@ public class CommandlineJavaTest { | |||||
| String currentClasspath = System.getProperty("java.class.path"); | String currentClasspath = System.getProperty("java.class.path"); | ||||
| assertNotNull(currentClasspath); | assertNotNull(currentClasspath); | ||||
| assertNull(System.getProperty("key")); | assertNull(System.getProperty("key")); | ||||
| CommandlineJava c = new CommandlineJava(); | |||||
| Environment.Variable v = new Environment.Variable(); | Environment.Variable v = new Environment.Variable(); | ||||
| v.setKey("key"); | v.setKey("key"); | ||||
| v.setValue("value"); | v.setValue("value"); | ||||
| @@ -157,7 +157,6 @@ public class CommandlineJavaTest { | |||||
| @Test | @Test | ||||
| public void testAssertions() throws Exception { | public void testAssertions() throws Exception { | ||||
| CommandlineJava c = new CommandlineJava(); | |||||
| c.createArgument().setValue("org.apache.tools.ant.CommandlineJavaTest"); | c.createArgument().setValue("org.apache.tools.ant.CommandlineJavaTest"); | ||||
| c.setClassname("junit.textui.TestRunner"); | c.setClassname("junit.textui.TestRunner"); | ||||
| c.createVmArgument().setValue("-Djava.compiler=NONE"); | c.createVmArgument().setValue("-Djava.compiler=NONE"); | ||||
| @@ -19,6 +19,7 @@ | |||||
| package org.apache.tools.ant.types; | package org.apache.tools.ant.types; | ||||
| import org.apache.tools.ant.BuildFileRule; | import org.apache.tools.ant.BuildFileRule; | ||||
| import org.junit.Before; | |||||
| import org.junit.Rule; | import org.junit.Rule; | ||||
| import org.junit.Test; | import org.junit.Test; | ||||
| @@ -35,7 +36,10 @@ public class XMLCatalogBuildFileTest { | |||||
| @Rule | @Rule | ||||
| public BuildFileRule buildRule = new BuildFileRule(); | public BuildFileRule buildRule = new BuildFileRule(); | ||||
| @Before | |||||
| public void setUp() { | |||||
| buildRule.configureProject("src/etc/testcases/types/xmlcatalog.xml"); | |||||
| } | |||||
| // | // | ||||
| // Ensure that an external entity resolves as expected with NO | // Ensure that an external entity resolves as expected with NO | ||||
| @@ -46,7 +50,6 @@ public class XMLCatalogBuildFileTest { | |||||
| // | // | ||||
| @Test | @Test | ||||
| public void testEntityNoCatalog() { | public void testEntityNoCatalog() { | ||||
| buildRule.configureProject("src/etc/testcases/types/xmlcatalog.xml"); | |||||
| buildRule.executeTarget("testentitynocatalog"); | buildRule.executeTarget("testentitynocatalog"); | ||||
| assertEquals("A stitch in time saves nine", buildRule.getProject().getProperty("val1")); | assertEquals("A stitch in time saves nine", buildRule.getProject().getProperty("val1")); | ||||
| } | } | ||||
| @@ -61,7 +64,6 @@ public class XMLCatalogBuildFileTest { | |||||
| // | // | ||||
| @Test | @Test | ||||
| public void testEntityWithCatalog() { | public void testEntityWithCatalog() { | ||||
| buildRule.configureProject("src/etc/testcases/types/xmlcatalog.xml"); | |||||
| buildRule.executeTarget("testentitywithcatalog"); | buildRule.executeTarget("testentitywithcatalog"); | ||||
| assertEquals("No news is good news", buildRule.getProject().getProperty("val2")); | assertEquals("No news is good news", buildRule.getProject().getProperty("val2")); | ||||
| } | } | ||||
| @@ -76,7 +78,6 @@ public class XMLCatalogBuildFileTest { | |||||
| // | // | ||||
| @Test | @Test | ||||
| public void testDocumentNoCatalog() { | public void testDocumentNoCatalog() { | ||||
| buildRule.configureProject("src/etc/testcases/types/xmlcatalog.xml"); | |||||
| buildRule.executeTarget("testdocumentnocatalog"); | buildRule.executeTarget("testdocumentnocatalog"); | ||||
| assertEquals("A stitch in time saves nine", buildRule.getProject().getProperty("val3")); | assertEquals("A stitch in time saves nine", buildRule.getProject().getProperty("val3")); | ||||
| } | } | ||||
| @@ -91,7 +92,6 @@ public class XMLCatalogBuildFileTest { | |||||
| // Stuff result into the property: val4 | // Stuff result into the property: val4 | ||||
| @Test | @Test | ||||
| public void testDocumentWithCatalog() { | public void testDocumentWithCatalog() { | ||||
| buildRule.configureProject("src/etc/testcases/types/xmlcatalog.xml"); | |||||
| buildRule.executeTarget("testdocumentwithcatalog"); | buildRule.executeTarget("testdocumentwithcatalog"); | ||||
| assertEquals("No news is good news", buildRule.getProject().getProperty("val4")); | assertEquals("No news is good news", buildRule.getProject().getProperty("val4")); | ||||
| } | } | ||||