Browse Source

Extract more fixtures

master
Gintas Grigelionis 7 years ago
parent
commit
a92e73743f
5 changed files with 41 additions and 35 deletions
  1. +23
    -20
      src/tests/junit/org/apache/tools/ant/taskdefs/EchoTest.java
  2. +2
    -4
      src/tests/junit/org/apache/tools/ant/taskdefs/ParallelTest.java
  3. +8
    -2
      src/tests/junit/org/apache/tools/ant/taskdefs/condition/EqualsTest.java
  4. +3
    -4
      src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java
  5. +5
    -5
      src/tests/junit/org/apache/tools/ant/types/XMLCatalogBuildFileTest.java

+ 23
- 20
src/tests/junit/org/apache/tools/ant/taskdefs/EchoTest.java View File

@@ -29,6 +29,7 @@ import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
@@ -38,16 +39,33 @@ import static org.junit.Assert.assertEquals;
*/
public class EchoTest {

private Project p;

private EchoTestLogger logger;

private Echo echo;

private File removeThis;

@Test
public void testLogBlankEcho() {
Project p = new Project();
@Before
public void setUp() {
p = new Project();
p.init();
EchoTestLogger logger = new EchoTestLogger();
logger = new EchoTestLogger();
p.addBuildListener(logger);
Echo echo = new Echo();
echo = new Echo();
echo.setProject(p);
}

@After
public void tearDown() {
if (removeThis != null && removeThis.exists() && !removeThis.delete()) {
removeThis.deleteOnExit();
}
}

@Test
public void testLogBlankEcho() {
echo.setTaskName("testLogBlankEcho");
echo.execute();
assertEquals("[testLogBlankEcho] ", logger.lastLoggedMessage);
@@ -55,12 +73,6 @@ public class EchoTest {

@Test
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.setMessage("\u00e4\u00a9");
removeThis = new File("abc.txt");
@@ -71,15 +83,6 @@ public class EchoTest {
assertEquals(x, "\u00e4\u00a9");
}

@After
public void tearDown() {
if (removeThis != null && removeThis.exists()) {
if (!removeThis.delete()) {
removeThis.deleteOnExit();
}
}
}

private class EchoTestLogger extends DefaultLogger {
String lastLoggedMessage;



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

@@ -55,17 +55,18 @@ public class ParallelTest {
/** the build file associated with this test */
public static final String TEST_BUILD_FILE = "src/etc/testcases/taskdefs/parallel.xml";

private Project p;
/** The JUnit setup method */
@Before
public void setUp() {
buildRule.configureProject(TEST_BUILD_FILE);
p = buildRule.getProject();
}

/** tests basic operation of the parallel task */
@Test
public void testBasic() {
// should get no output at all
Project p = buildRule.getProject();
p.setUserProperty("test.direct", DIRECT_MESSAGE);
p.setUserProperty("test.delayed", DELAYED_MESSAGE);
buildRule.executeTarget("testBasic");
@@ -81,7 +82,6 @@ public class ParallelTest {
@Test
public void testThreadCount() {
// should get no output at all
Project p = buildRule.getProject();
p.setUserProperty("test.direct", DIRECT_MESSAGE);
p.setUserProperty("test.delayed", DELAYED_MESSAGE);
buildRule.executeTarget("testThreadCount");
@@ -140,7 +140,6 @@ public class ParallelTest {
// should get no output at all
thrown.expect(BuildException.class);
thrown.expectMessage(FAILURE_MESSAGE);
Project p = buildRule.getProject();
p.setUserProperty("test.failure", FAILURE_MESSAGE);
p.setUserProperty("test.delayed", DELAYED_MESSAGE);
buildRule.executeTarget("testFail");
@@ -149,7 +148,6 @@ public class ParallelTest {
/** tests the demuxing of output streams in a multithreaded situation */
@Test
public void testDemux() {
Project p = buildRule.getProject();
p.addTaskDefinition("demuxtest", DemuxOutputTask.class);
synchronized (System.out) {
PrintStream out = System.out;


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

@@ -18,6 +18,7 @@

package org.apache.tools.ant.taskdefs.condition;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertFalse;
@@ -29,9 +30,15 @@ import static org.junit.Assert.assertTrue;
*/
public class EqualsTest {

private Equals eq;

@Before
public void setUp() {
eq = new Equals();
}

@Test
public void testTrim() {
Equals eq = new Equals();
eq.setArg1("a");
eq.setArg2(" a");
assertFalse(eq.eval());
@@ -45,7 +52,6 @@ public class EqualsTest {

@Test
public void testCaseSensitive() {
Equals eq = new Equals();
eq.setArg1("a");
eq.setArg2("A");
assertFalse(eq.eval());


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

@@ -44,6 +44,8 @@ public class CommandlineJavaTest {

private Project project;

private CommandlineJava c;

@Before
public void setUp() {
project = new Project();
@@ -55,6 +57,7 @@ public class CommandlineJavaTest {
if (cloneVm != null) {
System.setProperty("ant.build.clonevm", "false");
}
c = new CommandlineJava();
}

@After
@@ -72,7 +75,6 @@ public class CommandlineJavaTest {
@Test
public void testGetCommandline() throws CloneNotSupportedException {
assertNotNull("Ant home not set", System.getProperty("ant.home"));
CommandlineJava c = new CommandlineJava();
c.createArgument().setValue("org.apache.tools.ant.CommandlineJavaTest");
c.setClassname("junit.textui.TestRunner");
c.createVmArgument().setValue("-Djava.compiler=NONE");
@@ -108,7 +110,6 @@ public class CommandlineJavaTest {

@Test
public void testJarOption() {
CommandlineJava c = new CommandlineJava();
c.createArgument().setValue("arg1");
c.setJar("myfile.jar");
c.createVmArgument().setValue("-classic");
@@ -126,7 +127,6 @@ public class CommandlineJavaTest {
String currentClasspath = System.getProperty("java.class.path");
assertNotNull(currentClasspath);
assertNull(System.getProperty("key"));
CommandlineJava c = new CommandlineJava();
Environment.Variable v = new Environment.Variable();
v.setKey("key");
v.setValue("value");
@@ -157,7 +157,6 @@ public class CommandlineJavaTest {

@Test
public void testAssertions() throws Exception {
CommandlineJava c = new CommandlineJava();
c.createArgument().setValue("org.apache.tools.ant.CommandlineJavaTest");
c.setClassname("junit.textui.TestRunner");
c.createVmArgument().setValue("-Djava.compiler=NONE");


+ 5
- 5
src/tests/junit/org/apache/tools/ant/types/XMLCatalogBuildFileTest.java View File

@@ -19,6 +19,7 @@
package org.apache.tools.ant.types;

import org.apache.tools.ant.BuildFileRule;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

@@ -35,7 +36,10 @@ public class XMLCatalogBuildFileTest {
@Rule
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
@@ -46,7 +50,6 @@ public class XMLCatalogBuildFileTest {
//
@Test
public void testEntityNoCatalog() {
buildRule.configureProject("src/etc/testcases/types/xmlcatalog.xml");
buildRule.executeTarget("testentitynocatalog");
assertEquals("A stitch in time saves nine", buildRule.getProject().getProperty("val1"));
}
@@ -61,7 +64,6 @@ public class XMLCatalogBuildFileTest {
//
@Test
public void testEntityWithCatalog() {
buildRule.configureProject("src/etc/testcases/types/xmlcatalog.xml");
buildRule.executeTarget("testentitywithcatalog");
assertEquals("No news is good news", buildRule.getProject().getProperty("val2"));
}
@@ -76,7 +78,6 @@ public class XMLCatalogBuildFileTest {
//
@Test
public void testDocumentNoCatalog() {
buildRule.configureProject("src/etc/testcases/types/xmlcatalog.xml");
buildRule.executeTarget("testdocumentnocatalog");
assertEquals("A stitch in time saves nine", buildRule.getProject().getProperty("val3"));
}
@@ -91,7 +92,6 @@ public class XMLCatalogBuildFileTest {
// Stuff result into the property: val4
@Test
public void testDocumentWithCatalog() {
buildRule.configureProject("src/etc/testcases/types/xmlcatalog.xml");
buildRule.executeTarget("testdocumentwithcatalog");
assertEquals("No news is good news", buildRule.getProject().getProperty("val4"));
}


Loading…
Cancel
Save