You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by mc...@apache.org on 2014/04/18 23:00:43 UTC
svn commit: r1588563 [13/16] - in /ant/core/trunk: ./ manual/ manual/Types/
src/etc/testcases/taskdefs/ src/etc/testcases/taskdefs/optional/
src/etc/testcases/taskdefs/optional/antlr/
src/etc/testcases/taskdefs/optional/depend/ src/etc/testcases/taskde...
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/vss/MSVSSTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/vss/MSVSSTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/vss/MSVSSTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/vss/MSVSSTest.java Fri Apr 18 21:00:38 2014
@@ -23,18 +23,26 @@ import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.Location;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Tstamp;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.Path;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
* Testcase to ensure that command line generation and required attributes are correct.
*
*/
-public class MSVSSTest extends BuildFileTest implements MSVSSConstants {
+public class MSVSSTest implements MSVSSConstants {
private Commandline commandline;
@@ -52,43 +60,30 @@ public class MSVSSTest extends BuildFile
private static final String OUTPUT = "output.log";
private static final String SS_DIR = "c:/winnt".replace('/', File.separatorChar);
- /**
- * Constructor for the MSVSSTest object
- *
- * @param s Test name
- */
- public MSVSSTest(String s) {
- super(s);
- }
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+ private Project project;
- /**
- * The JUnit setup method
- *
- * @throws Exception
- */
- protected void setUp()
- throws Exception {
+ @Before
+ public void setUp(){
project = new Project();
project.setBasedir(".");
+ project.init();
}
- /**
- * The teardown method for JUnit
- *
- * @throws Exception
- */
- protected void tearDown()
- throws Exception {
+ @After
+ public void tearDown() {
File file = new File(project.getBaseDir(), LOCAL_PATH);
if (file.exists()) {
file.delete();
}
}
- /** Tests VSSGet commandline generation. */
+ @Test
public void testGetCommandLine() {
String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_GET, DS_VSS_PROJECT_PATH,
- MSVSS.FLAG_OVERRIDE_WORKING_DIR + project.getBaseDir().getAbsolutePath()
+ MSVSS.FLAG_OVERRIDE_WORKING_DIR + project.getBaseDir()
+ .getAbsolutePath()
+ File.separator + LOCAL_PATH, MSVSS.FLAG_AUTORESPONSE_DEF,
MSVSS.FLAG_RECURSION, MSVSS.FLAG_VERSION + VERSION, MSVSS.FLAG_LOGIN
+ VSS_USERNAME + "," + VSS_PASSWORD, FLAG_FILETIME_UPDATED, FLAG_SKIP_WRITABLE};
@@ -117,12 +112,14 @@ public class MSVSSTest extends BuildFile
}
/** Tests VSSGet required attributes. */
+ @Test
public void testGetExceptions() {
- configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
expectSpecificBuildException("vssget.1", "some cause", "vsspath attribute must be set!");
}
/** Tests Label commandline generation. */
+ @Test
public void testLabelCommandLine1() {
String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_LABEL, DS_VSS_PROJECT_PATH,
MSVSS.FLAG_COMMENT + SRC_COMMENT, MSVSS.FLAG_AUTORESPONSE_YES,
@@ -145,6 +142,7 @@ public class MSVSSTest extends BuildFile
}
/** Tests Label commandline generation with a label of more than 31 chars. */
+ @Test
public void testLabelCommandLine2() {
String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_LABEL, DS_VSS_PROJECT_PATH,
MSVSS.FLAG_COMMENT + SRC_COMMENT, MSVSS.FLAG_AUTORESPONSE_DEF,
@@ -167,18 +165,21 @@ public class MSVSSTest extends BuildFile
/**
* Test VSSLabel required attributes.
*/
+ @Test
public void testLabelExceptions() {
- configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
expectSpecificBuildException("vsslabel.1", "some cause", "vsspath attribute must be set!");
expectSpecificBuildException("vsslabel.2", "some cause", "label attribute must be set!");
}
/** Tests VSSHistory commandline generation with from label. */
+ @Test
public void testHistoryCommandLine1() {
String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_HISTORY, DS_VSS_PROJECT_PATH,
MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_VERSION_LABEL + LONG_LABEL
+ MSVSS.VALUE_FROMLABEL + SRC_LABEL, MSVSS.FLAG_LOGIN + VSS_USERNAME
- + "," + VSS_PASSWORD, MSVSS.FLAG_OUTPUT + project.getBaseDir().getAbsolutePath()
+ + "," + VSS_PASSWORD, MSVSS.FLAG_OUTPUT + project.getBaseDir()
+ .getAbsolutePath()
+ File.separator + OUTPUT};
// Set up a VSSHistory task
@@ -199,6 +200,7 @@ public class MSVSSTest extends BuildFile
}
/** Tests VSSHistory commandline generation with from date. */
+ @Test
public void testHistoryCommandLine2() {
String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_HISTORY, DS_VSS_PROJECT_PATH,
MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_VERSION_DATE + DATE + MSVSS.VALUE_FROMDATE
@@ -219,6 +221,7 @@ public class MSVSSTest extends BuildFile
}
/** Tests VSSHistory commandline generation with date calculation. */
+ @Test
public void testHistoryCommandLine3() {
// Set up a Timestamp
Tstamp tstamp = new Tstamp();
@@ -256,12 +259,24 @@ public class MSVSSTest extends BuildFile
/**
* Tests VSSHistory required attributes.
*/
+ @Test
public void testHistoryExceptions() {
- configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
expectSpecificBuildException("vsshistory.1", "some cause", "vsspath attribute must be set!");
}
+ private void expectSpecificBuildException(String target, String failMessage,
+ String exceptionMessage) {
+ try {
+ buildRule.executeTarget(target);
+ fail(failMessage);
+ } catch(BuildException ex) {
+ assertEquals(exceptionMessage, ex.getMessage());
+ }
+ }
+
/** Tests CheckIn commandline generation. */
+ @Test
public void testCheckinCommandLine() {
String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_CHECKIN, DS_VSS_PROJECT_PATH,
MSVSS.FLAG_AUTORESPONSE_NO, MSVSS.FLAG_WRITABLE, MSVSS.FLAG_LOGIN + VSS_USERNAME,
@@ -284,12 +299,14 @@ public class MSVSSTest extends BuildFile
/**
* Test VSSCheckIn required attributes.
*/
+ @Test
public void testCheckinExceptions() {
- configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
expectSpecificBuildException("vsscheckin.1", "some cause", "vsspath attribute must be set!");
}
/** Tests CheckOut commandline generation. */
+ @Test
public void testCheckoutCommandLine() {
String[] sTestCmdLine = {SS_DIR + File.separator + MSVSS.SS_EXE, MSVSS.COMMAND_CHECKOUT,
DS_VSS_PROJECT_PATH, MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_RECURSION,
@@ -318,13 +335,15 @@ public class MSVSSTest extends BuildFile
/**
* Test VSSCheckout required attributes.
*/
+ @Test
public void testCheckoutExceptions() {
- configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
expectSpecificBuildException("vsscheckout.1", "some cause", "vsspath attribute must be set!");
expectSpecificBuildException("vsscheckout.2", "some cause", "blah is not a legal value for this attribute");
}
/** Tests Add commandline generation. */
+ @Test
public void testAddCommandLine() {
String[] sTestCmdLine = {SS_DIR + File.separator + MSVSS.SS_EXE, MSVSS.COMMAND_ADD,
project.getBaseDir().getAbsolutePath() + File.separator + LOCAL_PATH,
@@ -349,12 +368,14 @@ public class MSVSSTest extends BuildFile
/**
* Test VSSAdd required attributes.
*/
+ @Test
public void testAddExceptions() {
- configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
expectSpecificBuildException("vssadd.1", "some cause", "localPath attribute must be set!");
}
/** Tests CP commandline generation. */
+ @Test
public void testCpCommandLine() {
String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_CP,
DS_VSS_PROJECT_PATH, MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_LOGIN +
@@ -374,12 +395,14 @@ public class MSVSSTest extends BuildFile
/**
* Test VSSCP required attributes.
*/
+ @Test
public void testCpExceptions() {
- configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
expectSpecificBuildException("vsscp.1", "some cause", "vsspath attribute must be set!");
}
/** Tests Create commandline generation. */
+ @Test
public void testCreateCommandLine() {
String[] sTestCmdLine = { MSVSS.SS_EXE, MSVSS.COMMAND_CREATE,
DS_VSS_PROJECT_PATH, MSVSS.FLAG_COMMENT + SRC_COMMENT, MSVSS.FLAG_AUTORESPONSE_NO,
@@ -403,8 +426,9 @@ public class MSVSSTest extends BuildFile
/**
* Test VSSCreate required attributes.
*/
+ @Test
public void testCreateExceptions() {
- configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
expectSpecificBuildException("vsscreate.1", "some cause", "vsspath attribute must be set!");
}
@@ -422,7 +446,7 @@ public class MSVSSTest extends BuildFile
while (testIndex < testLength) {
try {
- if (sGeneratedCmdLine[genIndex] == "") {
+ if (sGeneratedCmdLine[genIndex].equals("")) {
genIndex++;
continue;
}
@@ -439,7 +463,7 @@ public class MSVSSTest extends BuildFile
// Count the number of empty strings
int cnt = 0;
for (int i = 0; i < genLength; i++) {
- if (sGeneratedCmdLine[i] == "") {
+ if (sGeneratedCmdLine[i].equals("")) {
cnt++;
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/AbstractFileSetTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/AbstractFileSetTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/AbstractFileSetTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/AbstractFileSetTest.java Fri Apr 18 21:00:38 2014
@@ -20,10 +20,13 @@ package org.apache.tools.ant.types;
import java.io.File;
-import junit.framework.TestCase;
-
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
* Base class for FileSetTest and DirSetTest.
@@ -32,14 +35,12 @@ import org.apache.tools.ant.Project;
*
*/
-public abstract class AbstractFileSetTest extends TestCase {
+public abstract class AbstractFileSetTest {
private Project project;
- public AbstractFileSetTest(String name) {
- super(name);
- }
+ @Before
public void setUp() {
project = new Project();
project.setBasedir(".");
@@ -51,6 +52,7 @@ public abstract class AbstractFileSetTes
return project;
}
+ @Test
public final void testEmptyElementIfIsReference() {
AbstractFileSet f = getInstance();
f.setIncludes("**/*.java");
@@ -182,6 +184,7 @@ public abstract class AbstractFileSetTes
}
}
+ @Test
public void testCircularReferenceCheck() {
AbstractFileSet f = getInstance();
project.addReference("dummy", f);
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/AddTypeTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/AddTypeTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/AddTypeTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/AddTypeTest.java Fri Apr 18 21:00:38 2014
@@ -18,84 +18,121 @@
package org.apache.tools.ant.types;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.AntAssert;
+import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.condition.Condition;
-
-public class AddTypeTest extends BuildFileTest {
-
- public AddTypeTest(String name) {
- super(name);
- }
-
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.fail;
+
+public class AddTypeTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/types/addtype.xml");
+ buildRule.configureProject("src/etc/testcases/types/addtype.xml");
}
+ @Test
public void testAddPath() {
- executeTarget("addpath");
+ buildRule.executeTarget("addpath");
}
+ @Test
public void testAddCondition() {
- executeTarget("addcondition");
+ buildRule.executeTarget("addcondition");
}
+ @Test
public void testAddFilter() {
- executeTarget("addfilter");
+ buildRule.executeTarget("addfilter");
}
+ @Test
public void testAddSelector() {
- executeTarget("addselector");
+ buildRule.executeTarget("addselector");
}
+ @Test
public void testNestedA() {
- expectLogContaining("nested.a", "add A called");
+ buildRule.executeTarget("nested.a");
+ AntAssert.assertContains("add A called", buildRule.getLog());
}
+ @Test
public void testNestedB() {
- expectLogContaining("nested.b", "add B called");
+ buildRule.executeTarget("nested.b");
+ AntAssert.assertContains( "add B called", buildRule.getLog());
}
+ @Test
public void testNestedC() {
- expectLogContaining("nested.c", "add C called");
+ buildRule.executeTarget("nested.c");
+ AntAssert.assertContains( "add C called", buildRule.getLog());
}
+ @Test
public void testNestedAB() {
- expectBuildExceptionContaining(
- "nested.ab", "Should have got ambiguous", "ambiguous");
+ try {
+ buildRule.executeTarget("nested.ab");
+ fail("Build exception expected: Should have got ambiguous");
+ } catch (BuildException ex) {
+ AntAssert.assertContains("ambiguous", ex.getMessage());
+ }
}
+ @Test
public void testConditionType() {
- expectLogContaining("condition.type", "beforeafter");
+ buildRule.executeTarget("condition.type");
+ AntAssert.assertContains( "beforeafter", buildRule.getLog());
}
+ @Test
public void testConditionTask() {
- expectLogContaining("condition.task", "My Condition execution");
+ buildRule.executeTarget("condition.task");
+ AntAssert.assertContains( "My Condition execution", buildRule.getLog());
}
+
+ @Test
public void testConditionConditionType() {
- expectLogContaining("condition.condition.type", "My Condition eval");
+ buildRule.executeTarget("condition.condition.type");
+ AntAssert.assertContains( "My Condition eval", buildRule.getLog());
}
+
+ @Test
public void testConditionConditionTask() {
- expectBuildExceptionContaining(
- "condition.condition.task", "task masking condition",
- "doesn't support the nested");
+ try {
+ buildRule.executeTarget("condition.condition.task");
+ fail("Build exception expected: Task masking condition");
+ } catch (BuildException ex) {
+ AntAssert.assertContains("doesn't support the nested", ex.getMessage());
+ }
}
+ @Test
public void testAddConfigured() {
- expectLogContaining(
- "myaddconfigured", "value is Value Setexecute: value is Value Set");
+ buildRule.executeTarget("myaddconfigured");
+ AntAssert.assertContains("value is Value Setexecute: value is Value Set",
+ buildRule.getLog());
}
+ @Test
public void testAddConfiguredValue() {
- expectLogContaining(
- "myaddconfiguredvalue",
- "value is Value Setexecute: value is Value Set");
+ buildRule.executeTarget("myaddconfiguredvalue");
+ AntAssert.assertContains("value is Value Setexecute: value is Value Set",
+ buildRule.getLog());
}
+ @Test
public void testNamespace() {
- executeTarget("namespacetest");
+ buildRule.executeTarget("namespacetest");
}
// The following will be used as types and tasks
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/AssertionsTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/AssertionsTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/AssertionsTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/AssertionsTest.java Fri Apr 18 21:00:38 2014
@@ -17,81 +17,108 @@
*/
package org.apache.tools.ant.types;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.apache.tools.ant.AntAssert.assertContains;
+import static org.junit.Assert.fail;
/**
* test assertion handling
*/
-public class AssertionsTest extends BuildFileTest {
+public class AssertionsTest {
- public AssertionsTest(String name) {
- super(name);
- }
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
- protected void setUp() throws Exception {
- configureProject("src/etc/testcases/types/assertions.xml");
+ @Before
+ public void setUp() {
+ buildRule.configureProject("src/etc/testcases/types/assertions.xml");
}
+
/**
* runs a test and expects an assertion thrown in forked code
* @param target
*/
- protected void expectAssertion(String target) {
- expectBuildExceptionContaining(target,
- "assertion not thrown in "+target,
- "Java returned: 1");
+ private void expectAssertion(String target) {
+ try {
+ buildRule.executeTarget(target);
+ fail("BuildException should have been thrown by assertion fail in task");
+ } catch (BuildException ex) {
+ assertContains("assertion not thrown in "+target, "Java returned: 1", ex.getMessage());
+ }
}
+ @Test
public void testClassname() {
expectAssertion("test-classname");
}
+ @Test
public void testPackage() {
expectAssertion("test-package");
}
+ @Test
public void testEmptyAssertions() {
- executeTarget("test-empty-assertions");
+ buildRule.executeTarget("test-empty-assertions");
}
+ @Test
public void testDisable() {
- executeTarget("test-disable");
+ buildRule.executeTarget("test-disable");
}
+ @Test
public void testOverride() {
expectAssertion("test-override");
}
+ @Test
public void testOverride2() {
- executeTarget("test-override2");
+ buildRule.executeTarget("test-override2");
}
+
+ @Test
public void testReferences() {
expectAssertion("test-references");
}
+ @Test
public void testMultipleAssertions() {
- expectBuildExceptionContaining("test-multiple-assertions",
- "multiple assertions rejected",
- "Only one assertion declaration is allowed");
+ try {
+ buildRule.executeTarget("test-multiple-assertions");
+ fail("BuildException should have been thrown by assertion fail in task");
+ } catch (BuildException ex) {
+ assertContains("multiple assertions rejected", "Only one assertion declaration is allowed", ex.getMessage());
+ }
}
+ @Test
public void testReferenceAbuse() {
- expectBuildExceptionContaining("test-reference-abuse",
- "reference abuse rejected",
- "You must not specify");
+ try {
+ buildRule.executeTarget("test-reference-abuse");
+ fail("BuildException should have been thrown by reference abuse");
+ } catch (BuildException ex) {
+ assertContains("reference abuse rejected", "You must not specify", ex.getMessage());
+ }
}
+ @Test
public void testNofork() {
- if (AssertionsTest.class.desiredAssertionStatus()) {
- return; // ran Ant tests with -ea and this would fail spuriously
- }
- expectLogContaining("test-nofork",
- "Assertion statements are currently ignored in non-forked mode");
+ Assume.assumeFalse("ran Ant tests with -ea and this would fail spuriously", AssertionsTest.class.desiredAssertionStatus());
+ buildRule.executeTarget("test-nofork");
+ assertContains("Assertion statements are currently ignored in non-forked mode", buildRule.getLog());
}
-
+ @Test
public void testJUnit() {
- executeTarget("test-junit");
+ buildRule.executeTarget("test-junit");
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java Fri Apr 18 21:00:38 2014
@@ -18,25 +18,31 @@
package org.apache.tools.ant.types;
-import junit.framework.TestCase;
import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Project;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
/**
- * JUnit 3 testcases for org.apache.tools.ant.CommandlineJava
+ * JUnit testcases for org.apache.tools.ant.CommandlineJava
*
*/
-public class CommandlineJavaTest extends TestCase {
+public class CommandlineJavaTest {
private String cloneVm;
- public CommandlineJavaTest(String name) {
- super(name);
- }
private Project project;
+ @Before
public void setUp() {
project = new Project();
project.setBasedir(System.getProperty("root"));
@@ -47,12 +53,14 @@ public class CommandlineJavaTest extends
}
}
+ @After
public void tearDown() {
if (cloneVm != null) {
System.setProperty("ant.build.clonevm", cloneVm);
}
}
+ @Test
public void testGetCommandline() throws Exception {
CommandlineJava c = new CommandlineJava();
c.createArgument().setValue("org.apache.tools.ant.CommandlineJavaTest");
@@ -73,7 +81,7 @@ public class CommandlineJavaTest extends
assertEquals("no classpath",
"org.apache.tools.ant.CommandlineJavaTest", s[3]);
try {
- CommandlineJava c2 = (CommandlineJava) c.clone();
+ c.clone();
} catch (NullPointerException ex) {
fail("cloning should work without classpath specified");
}
@@ -94,6 +102,7 @@ public class CommandlineJavaTest extends
"org.apache.tools.ant.CommandlineJavaTest", s[5]);
}
+ @Test
public void testJarOption() throws Exception {
CommandlineJava c = new CommandlineJava();
c.createArgument().setValue("arg1");
@@ -108,6 +117,7 @@ public class CommandlineJavaTest extends
assertEquals("arg1", s[5]);
}
+ @Test
public void testSysproperties() {
String currentClasspath = System.getProperty("java.class.path");
assertNotNull(currentClasspath);
@@ -141,6 +151,7 @@ public class CommandlineJavaTest extends
assertNull(System.getProperty("key2"));
}
+ @Test
public void testAssertions() throws Exception {
CommandlineJava c = new CommandlineJava();
c.createArgument().setValue("org.apache.tools.ant.CommandlineJavaTest");
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/CommandlineTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/CommandlineTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/CommandlineTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/CommandlineTest.java Fri Apr 18 21:00:38 2014
@@ -18,20 +18,20 @@
package org.apache.tools.ant.types;
-import junit.framework.TestCase;
-
import org.apache.tools.ant.BuildException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertNotNull;
/**
* JUnit 3 testcases for org.apache.tools.ant.CommandLine
*
*/
-public class CommandlineTest extends TestCase {
-
- public CommandlineTest(String name) {
- super(name);
- }
+public class CommandlineTest {
+ @Test
public void testTokenizer() {
String[] s = Commandline.translateCommandline("1 2 3");
assertEquals("Simple case", 3, s.length);
@@ -107,20 +107,21 @@ public class CommandlineTest extends Tes
// now to the expected failures
try {
- s = Commandline.translateCommandline("a \'b c");
+ Commandline.translateCommandline("a \'b c");
fail("unbalanced single quotes undetected");
} catch (BuildException be) {
assertEquals("unbalanced quotes in a \'b c", be.getMessage());
}
try {
- s = Commandline.translateCommandline("a \"b c");
+ Commandline.translateCommandline("a \"b c");
fail("unbalanced double quotes undetected");
} catch (BuildException be) {
assertEquals("unbalanced quotes in a \"b c", be.getMessage());
}
}
+ @Test
public void testToString() {
assertEquals("", Commandline.toString(new String[0]));
assertEquals("", Commandline.toString(null));
@@ -130,6 +131,7 @@ public class CommandlineTest extends Tes
assertEquals("1 \'2\"3\'", Commandline.toString(new String[] {"1", "2\"3"}));
}
+ @Test
public void testAwkCommand() {
Commandline c = new Commandline();
c.setExecutable("awk");
@@ -141,6 +143,7 @@ public class CommandlineTest extends Tes
assertEquals("'NR == 2 { print $NF }'", s[1]);
}
+ @Test
public void testPrefix() {
Commandline c = new Commandline();
Commandline.Argument a = c.createArgument();
@@ -151,6 +154,7 @@ public class CommandlineTest extends Tes
assertEquals("-f=foo", s[0]);
}
+ @Test
public void testSuffix() {
Commandline c = new Commandline();
Commandline.Argument a = c.createArgument();
@@ -161,6 +165,7 @@ public class CommandlineTest extends Tes
assertEquals("foo,1", s[0]);
}
+ @Test
public void testPrefixSuffixLine() {
Commandline c = new Commandline();
Commandline.Argument a = c.createArgument();
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/DescriptionTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/DescriptionTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/DescriptionTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/DescriptionTest.java Fri Apr 18 21:00:38 2014
@@ -18,41 +18,42 @@
package org.apache.tools.ant.types;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
/**
* FilterSet testing
*
*/
-public class DescriptionTest extends BuildFileTest {
-
- public DescriptionTest(String name) {
- super(name);
- }
-
- public void setUp() {
- }
-
- public void tearDown() {
- }
+public class DescriptionTest {
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Test
public void test1() {
- configureProject("src/etc/testcases/types/description1.xml");
- assertEquals("Single description failed", "Test Project Description", project.getDescription());
+ buildRule.configureProject("src/etc/testcases/types/description1.xml");
+ assertEquals("Single description failed", "Test Project Description", buildRule.getProject().getDescription());
}
+ @Test
public void test2() {
- configureProject("src/etc/testcases/types/description2.xml");
- assertEquals("Multi line description failed", "Multi Line\nProject Description", project.getDescription());
+ buildRule.configureProject("src/etc/testcases/types/description2.xml");
+ assertEquals("Multi line description failed", "Multi Line\nProject Description", buildRule.getProject().getDescription());
}
+ @Test
public void test3() {
- configureProject("src/etc/testcases/types/description3.xml");
- assertEquals("Multi instance description failed", "Multi Instance Project Description", project.getDescription());
+ buildRule.configureProject("src/etc/testcases/types/description3.xml");
+ assertEquals("Multi instance description failed", "Multi Instance Project Description", buildRule.getProject().getDescription());
}
+ @Test
public void test4() {
- configureProject("src/etc/testcases/types/description4.xml");
- assertEquals("Multi instance nested description failed", "Multi Instance Nested Project Description", project.getDescription());
+ buildRule.configureProject("src/etc/testcases/types/description4.xml");
+ assertEquals("Multi instance nested description failed", "Multi Instance Nested Project Description", buildRule.getProject().getDescription());
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/DirSetTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/DirSetTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/DirSetTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/DirSetTest.java Fri Apr 18 21:00:38 2014
@@ -21,6 +21,10 @@ package org.apache.tools.ant.types;
import java.io.File;
import java.io.FileOutputStream;
import org.apache.tools.ant.BuildException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
* JUnit 3 testcases for org.apache.tools.ant.types.DirSet.
@@ -28,14 +32,11 @@ import org.apache.tools.ant.BuildExcepti
*/
public class DirSetTest extends AbstractFileSetTest {
- public DirSetTest(String name) {
- super(name);
- }
-
protected AbstractFileSet getInstance() {
return new DirSet();
}
+ @Test
public void testFileSetIsNoDirSet() {
DirSet ds = (DirSet) getInstance();
ds.setProject(getProject());
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/EnumeratedAttributeTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/EnumeratedAttributeTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/EnumeratedAttributeTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/EnumeratedAttributeTest.java Fri Apr 18 21:00:38 2014
@@ -18,21 +18,22 @@
package org.apache.tools.ant.types;
-import junit.framework.TestCase;
import org.apache.tools.ant.BuildException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
- * JUnit 3 testcases for org.apache.tools.ant.EnumeratedAttribute.
+ * JUnit testcases for org.apache.tools.ant.EnumeratedAttribute.
*/
-public class EnumeratedAttributeTest extends TestCase {
+public class EnumeratedAttributeTest {
private static String[] expected = {"a", "b", "c"};
- public EnumeratedAttributeTest(String name) {
- super(name);
- }
-
+ @Test
public void testContains() {
EnumeratedAttribute t1 = new TestNormal();
for (int i=0; i<expected.length; i++) {
@@ -47,6 +48,7 @@ public class EnumeratedAttributeTest ext
!(new TestNull()).containsValue("d"));
}
+ @Test
public void testFactory() {
Factory ea = (Factory)EnumeratedAttribute.getInstance(Factory.class, "one");
assertEquals("Factory did not set the right value.", ea.getValue(), "one");
@@ -55,9 +57,11 @@ public class EnumeratedAttributeTest ext
fail("Factory should fail when trying to set an illegal value.");
} catch (BuildException be) {
// was expected
+ //TODO assert exception message
}
}
+ @Test
public void testExceptions() {
EnumeratedAttribute t1 = new TestNormal();
for (int i=0; i<expected.length; i++) {
@@ -71,13 +75,13 @@ public class EnumeratedAttributeTest ext
t1.setValue("d");
fail("expected exception for value \"d\"");
} catch (BuildException be) {
+ //TODO assert build exception
}
try {
(new TestNull()).setValue("d");
fail("expected exception for value \"d\" in TestNull");
} catch (BuildException be) {
- } catch (Throwable other) {
- fail("unexpected death of TestNull: "+other.getMessage());
+ //TODO assert exception message
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/FileListTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/FileListTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/FileListTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/FileListTest.java Fri Apr 18 21:00:38 2014
@@ -18,30 +18,37 @@
package org.apache.tools.ant.types;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
import java.io.File;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileTest;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
* Some tests for filelist.
*/
-public class FileListTest extends BuildFileTest {
-
- public FileListTest(String name) {
- super(name);
- }
+public class FileListTest {
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/types/filelist.xml");
+ buildRule.configureProject("src/etc/testcases/types/filelist.xml");
}
+ @Test
public void testEmptyElementIfIsReference() {
FileList f = new FileList();
- f.setDir(project.resolveFile("."));
+ f.setDir(buildRule.getProject().resolveFile("."));
try {
- f.setRefid(new Reference(getProject(), "dummyref"));
+ f.setRefid(new Reference(buildRule.getProject(), "dummyref"));
fail("Can add reference to FileList with directory attribute set.");
} catch (BuildException be) {
assertEquals("You must not specify more than one attribute when using refid",
@@ -51,7 +58,7 @@ public class FileListTest extends BuildF
f = new FileList();
f.setFiles("foo.xml,c/d/bar.xml");
try {
- f.setRefid(new Reference(getProject(), "dummyref"));
+ f.setRefid(new Reference(buildRule.getProject(), "dummyref"));
fail("Can add reference to FileList with file attribute set.");
} catch (BuildException be) {
assertEquals("You must not specify more than one attribute when using refid",
@@ -59,7 +66,7 @@ public class FileListTest extends BuildF
}
f = new FileList();
- f.setRefid(new Reference(getProject(), "dummyref"));
+ f.setRefid(new Reference(buildRule.getProject(), "dummyref"));
try {
f.setFiles("a/b/foo.java");
fail("Can set files in FileList that is a reference.");
@@ -68,7 +75,7 @@ public class FileListTest extends BuildF
be.getMessage());
}
try {
- f.setDir(project.resolveFile("."));
+ f.setDir(buildRule.getProject().resolveFile("."));
fail("Can set dir in FileList that is a reference.");
} catch (BuildException be) {
assertEquals("You must not specify more than one attribute when using refid",
@@ -76,19 +83,20 @@ public class FileListTest extends BuildF
}
}
+ @Test
public void testCircularReferenceCheck() {
FileList f = new FileList();
- project.addReference("dummy", f);
- f.setRefid(new Reference(getProject(), "dummy"));
+ buildRule.getProject().addReference("dummy", f);
+ f.setRefid(new Reference(buildRule.getProject(), "dummy"));
try {
- f.getDir(project);
+ f.getDir(buildRule.getProject());
fail("Can make FileList a Reference to itself.");
} catch (BuildException be) {
assertEquals("This data type contains a circular reference.",
be.getMessage());
}
try {
- f.getFiles(project);
+ f.getFiles(buildRule.getProject());
fail("Can make FileList a Reference to itself.");
} catch (BuildException be) {
assertEquals("This data type contains a circular reference.",
@@ -97,23 +105,23 @@ public class FileListTest extends BuildF
// dummy1 --> dummy2 --> dummy3 --> dummy1
FileList f1 = new FileList();
- project.addReference("dummy1", f1);
- f1.setRefid(new Reference(getProject(), "dummy2"));
+ buildRule.getProject().addReference("dummy1", f1);
+ f1.setRefid(new Reference(buildRule.getProject(), "dummy2"));
FileList f2 = new FileList();
- project.addReference("dummy2", f2);
- f2.setRefid(new Reference(getProject(), "dummy3"));
+ buildRule.getProject().addReference("dummy2", f2);
+ f2.setRefid(new Reference(buildRule.getProject(), "dummy3"));
FileList f3 = new FileList();
- project.addReference("dummy3", f3);
- f3.setRefid(new Reference(getProject(), "dummy1"));
+ buildRule.getProject().addReference("dummy3", f3);
+ f3.setRefid(new Reference(buildRule.getProject(), "dummy1"));
try {
- f1.getDir(project);
+ f1.getDir(buildRule.getProject());
fail("Can make circular reference.");
} catch (BuildException be) {
assertEquals("This data type contains a circular reference.",
be.getMessage());
}
try {
- f1.getFiles(project);
+ f1.getFiles(buildRule.getProject());
fail("Can make circular reference.");
} catch (BuildException be) {
assertEquals("This data type contains a circular reference.",
@@ -123,27 +131,33 @@ public class FileListTest extends BuildF
// dummy1 --> dummy2 --> dummy3
// (which has the Project's basedir as root).
f1 = new FileList();
- project.addReference("dummy1", f1);
- f1.setRefid(new Reference(getProject(), "dummy2"));
+ buildRule.getProject().addReference("dummy1", f1);
+ f1.setRefid(new Reference(buildRule.getProject(), "dummy2"));
f2 = new FileList();
- project.addReference("dummy2", f2);
- f2.setRefid(new Reference(getProject(), "dummy3"));
+ buildRule.getProject().addReference("dummy2", f2);
+ f2.setRefid(new Reference(buildRule.getProject(), "dummy3"));
f3 = new FileList();
- project.addReference("dummy3", f3);
- f3.setDir(project.resolveFile("."));
- File dir = f1.getDir(project);
- assertEquals("Dir is basedir", dir, project.getBaseDir());
+ buildRule.getProject().addReference("dummy3", f3);
+ f3.setDir(buildRule.getProject().resolveFile("."));
+ File dir = f1.getDir(buildRule.getProject());
+ assertEquals("Dir is basedir", dir, buildRule.getProject().getBaseDir());
}
-
+
+ @Test
public void testSimple() {
- expectLog("simple", "/abc/a");
+ buildRule.executeTarget("simple");
+ assertEquals("/abc/a", buildRule.getLog());
}
+ @Test
public void testDouble() {
- expectLog("double", "/abc/a:/abc/b");
+ buildRule.executeTarget("double");
+ assertEquals("/abc/a:/abc/b", buildRule.getLog());
}
+ @Test
public void testNested() {
- expectLog("nested", "/abc/a:/abc/b");
+ buildRule.executeTarget("nested");
+ assertEquals("/abc/a:/abc/b", buildRule.getLog());
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/FileSetTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/FileSetTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/FileSetTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/FileSetTest.java Fri Apr 18 21:00:38 2014
@@ -28,9 +28,6 @@ package org.apache.tools.ant.types;
public class FileSetTest extends AbstractFileSetTest {
- public FileSetTest(String name) {
- super(name);
- }
protected AbstractFileSet getInstance() {
return new FileSet();
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/FilterSetTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/FilterSetTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/FilterSetTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/FilterSetTest.java Fri Apr 18 21:00:38 2014
@@ -18,47 +18,60 @@
package org.apache.tools.ant.types;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Hashtable;
-import org.apache.tools.ant.BuildFileTest;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* FilterSet testing
*
*/
-public class FilterSetTest extends BuildFileTest {
+public class FilterSetTest {
static private final int BUF_SIZE = 32768;
- public FilterSetTest(String name) {
- super(name);
- }
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/types/filterset.xml");
+ buildRule.configureProject("src/etc/testcases/types/filterset.xml");
}
+ @After
public void tearDown() {
- executeTarget("cleanup");
+ buildRule.executeTarget("cleanup");
}
- public void test1() {
- executeTarget("test1");
+ @Test
+ public void test1() throws IOException {
+ buildRule.executeTarget("test1");
assertTrue("Filterset 1 failed", compareFiles("src/etc/testcases/types/gold/filterset1.txt",
"src/etc/testcases/types/dest1.txt"));
}
- public void test2() {
- executeTarget("test2");
+ @Test
+ public void test2() throws IOException {
+ buildRule.executeTarget("test2");
assertTrue("Filterset 2 failed", compareFiles("src/etc/testcases/types/gold/filterset2.txt",
"src/etc/testcases/types/dest2.txt"));
}
- public void test3() {
- executeTarget("test3");
+ @Test
+ public void test3() throws IOException {
+ buildRule.executeTarget("test3");
assertTrue("Filterset 3 failed", compareFiles("src/etc/testcases/types/gold/filterset3.txt",
"src/etc/testcases/types/dest3.txt"));
}
@@ -68,6 +81,7 @@ public class FilterSetTest extends Build
* the filter value @test@ contains another filter value, it will
* actually resolve.
*/
+ @Test
public void testRecursive() {
String result = "it works line";
String line="@test@ line";
@@ -84,6 +98,7 @@ public class FilterSetTest extends Build
* Test to see what happens when the resolving occurs in an
* infinite loop.
*/
+ @Test
public void testInfinite() {
String result = "@test@ line testvalue";
String line = "@test@ line @test3@";
@@ -101,6 +116,7 @@ public class FilterSetTest extends Build
* Test to see what happens when the resolving occurs in
* what would be an infinite loop, but with recursion disabled.
*/
+ @Test
public void testRecursionDisabled() {
String result = "@test1@ line testvalue";
String line = "@test@ line @test2@";
@@ -114,6 +130,7 @@ public class FilterSetTest extends Build
assertEquals(result, fs.replaceTokens(line));
}
+ @Test
public void testNonInfiniteRecursiveMultipleOnSingleLine() {
FilterSet filters = new FilterSet();
@@ -131,91 +148,92 @@ public class FilterSetTest extends Build
assertEquals(result, filters.replaceTokens(line));
}
+ @Test
public void testNestedFilterSets() {
- executeTarget("test-nested-filtersets");
+ buildRule.executeTarget("test-nested-filtersets");
- FilterSet fs = (FilterSet) getProject().getReference("1");
+ FilterSet fs = (FilterSet) buildRule.getProject().getReference("1");
Hashtable filters = fs.getFilterHash();
assertEquals(1, filters.size());
assertEquals("value1", filters.get("token1"));
- fs = (FilterSet) getProject().getReference("2");
+ fs = (FilterSet) buildRule.getProject().getReference("2");
filters = fs.getFilterHash();
assertEquals(2, filters.size());
assertEquals("1111", filters.get("aaaa"));
assertEquals("2222", filters.get("bbbb"));
- fs = (FilterSet) getProject().getReference("3");
+ fs = (FilterSet) buildRule.getProject().getReference("3");
filters = fs.getFilterHash();
assertEquals(1, filters.size());
assertEquals("value4", filters.get("token4"));
- fs = (FilterSet) getProject().getReference("5");
+ fs = (FilterSet) buildRule.getProject().getReference("5");
filters = fs.getFilterHash();
assertEquals(1, filters.size());
assertEquals("value1", filters.get("token1"));
}
+ @Test
public void testFiltersFileElement() {
- executeTarget("testFiltersFileElement");
+ buildRule.executeTarget("testFiltersFileElement");
}
+ @Test
public void testFiltersFileAttribute() {
- executeTarget("testFiltersFileAttribute");
+ buildRule.executeTarget("testFiltersFileAttribute");
}
+ @Test
public void testMultipleFiltersFiles() {
- executeTarget("testMultipleFiltersFiles");
+ buildRule.executeTarget("testMultipleFiltersFiles");
}
+ @Test
public void testMissingFiltersFile() {
- expectBuildException("testMissingFiltersFile",
- "should fail due to missing filtersfile");
+ try {
+ buildRule.executeTarget("testMissingFiltersFile");
+ fail("should fail due to missing filtersfile");
+ } catch (BuildException ex) {
+ //TODO assert exception text
+ }
}
+ @Test
public void testAllowMissingFiltersFile() {
- executeTarget("testAllowMissingFiltersFile");
+ buildRule.executeTarget("testAllowMissingFiltersFile");
}
- private boolean compareFiles(String name1, String name2) {
+ private boolean compareFiles(String name1, String name2) throws IOException {
File file1 = new File(System.getProperty("root"), name1);
File file2 = new File(System.getProperty("root"), name2);
- try {
- if (!file1.exists() || !file2.exists()) {
- System.out.println("One or both files do not exist:" + name1 + ", " + name2);
- return false;
- }
- if (file1.length() != file2.length()) {
- System.out.println("File size mismatch:" + name1 + "(" + file1.length() + "), " +
- name2 + "(" + file2.length() + ")");
- return false;
- }
+ if (!file1.exists() || !file2.exists()) {
+ return false;
+ }
+
+ if (file1.length() != file2.length()) {
+ return false;
+ }
- // byte - byte compare
- byte[] buffer1 = new byte[BUF_SIZE];
- byte[] buffer2 = new byte[BUF_SIZE];
-
- FileInputStream fis1 = new FileInputStream(file1);
- FileInputStream fis2 = new FileInputStream(file2);
- int index = 0;
- int read = 0;
- while ((read = fis1.read(buffer1)) != -1) {
- fis2.read(buffer2);
- for (int i = 0; i < read; ++i, ++index) {
- if (buffer1[i] != buffer2[i]) {
- System.out.println("Bytes mismatch:" + name1 + ", " + name2 +
- " at byte " + index);
- return false;
- }
+ // byte - byte compare
+ byte[] buffer1 = new byte[BUF_SIZE];
+ byte[] buffer2 = new byte[BUF_SIZE];
+
+ FileInputStream fis1 = new FileInputStream(file1);
+ FileInputStream fis2 = new FileInputStream(file2);
+ int index = 0;
+ int read = 0;
+ while ((read = fis1.read(buffer1)) != -1) {
+ fis2.read(buffer2);
+ for (int i = 0; i < read; ++i, ++index) {
+ if (buffer1[i] != buffer2[i]) {
+ return false;
}
}
- return true;
- }
- catch (IOException e) {
- System.out.println("IOException comparing files: " + name1 + ", " + name2);
- return false;
}
+ return true;
+
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/FlexIntegerTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/FlexIntegerTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/FlexIntegerTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/FlexIntegerTest.java Fri Apr 18 21:00:38 2014
@@ -18,24 +18,30 @@
package org.apache.tools.ant.types;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
-public class FlexIntegerTest extends BuildFileTest {
+import static org.junit.Assert.assertEquals;
- public FlexIntegerTest(String name) {
- super(name);
- }
+public class FlexIntegerTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/types/flexinteger.xml");
+ buildRule.configureProject("src/etc/testcases/types/flexinteger.xml");
}
+ @Test
public void testFlexInteger() {
- executeTarget("test");
- assertEquals(project.getProperty("flexint.value1"), "10");
- assertEquals(project.getProperty("flexint.value2"), "8");
+ buildRule.executeTarget("test");
+ assertEquals(buildRule.getProject().getProperty("flexint.value1"), "10");
+ assertEquals(buildRule.getProject().getProperty("flexint.value2"), "8");
}
// This class acts as a custom Ant task also
@@ -44,12 +50,7 @@ public class FlexIntegerTest extends Bui
String propName;
private FlexInteger value;
- /**
- * To make taskdef happy
- */
- public FlexIntegerTest() {
- super("FlexIntegerTest");
- }
+
public void setPropName(String propName) {
this.propName = propName;
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/MapperTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/MapperTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/MapperTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/MapperTest.java Fri Apr 18 21:00:38 2014
@@ -18,39 +18,45 @@
package org.apache.tools.ant.types;
-import java.io.File;
-import java.io.FilenameFilter;
import java.util.Arrays;
import java.util.List;
-import junit.framework.TestCase;
-
import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.ChainedMapper;
import org.apache.tools.ant.util.FileNameMapper;
import org.apache.tools.ant.util.FlatFileNameMapper;
import org.apache.tools.ant.util.GlobPatternMapper;
import org.apache.tools.ant.util.MergingMapper;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
- * JUnit 3 testcases for org.apache.tools.ant.types.Mapper.
+ * JUnit testcases for org.apache.tools.ant.types.Mapper.
+ *
*/
-public class MapperTest extends TestCase {
+public class MapperTest {
- private Project project;
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
- public MapperTest(String name) {
- super(name);
- }
+ private Project project;
+ @Before
public void setUp() {
project = new Project();
project.setBasedir(".");
}
+ @Test
public void testEmptyElementIfIsReference() {
Mapper m = new Mapper(project);
m.setFrom("*.java");
@@ -92,6 +98,7 @@ public class MapperTest extends TestCase
}
}
+ @Test
public void testCircularReferenceCheck() {
Mapper m = new Mapper(project);
project.addReference("dummy", m);
@@ -144,6 +151,7 @@ public class MapperTest extends TestCase
assertEquals("a.class", result[0]);
}
+ @Test
public void testNested() {
Mapper mapper1 = new Mapper(project);
Mapper.MapperType mt = new Mapper.MapperType();
@@ -175,6 +183,7 @@ public class MapperTest extends TestCase
list.contains("mergefile"));
}
+ @Test
public void testChained() {
// a --> b --> c --- def
@@ -217,35 +226,10 @@ public class MapperTest extends TestCase
assertTrue("cannot find expected target \"ghi\"", list.contains("ghi"));
}
+ @Test
public void testCopyTaskWithTwoFilesets() {
- TaskdefForCopyTest t = new TaskdefForCopyTest("test1");
- try {
- t.setUp();
- t.test1();
- } finally {
- t.tearDown();
- }
+ buildRule.configureProject("src/etc/testcases/types/mapper.xml");
+ buildRule.executeTarget("test1");
}
- private class TaskdefForCopyTest extends BuildFileTest {
- TaskdefForCopyTest(String name) {
- super(name);
- }
-
- public void setUp() {
- configureProject("src/etc/testcases/types/mapper.xml");
- }
-
- public void tearDown() {
- try {
- super.tearDown();
- } catch (Exception exc) {
- // ignore
- }
- }
-
- public void test1() {
- executeTarget("test1");
- }
- }
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/PathTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/PathTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/PathTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/PathTest.java Fri Apr 18 21:00:38 2014
@@ -21,34 +21,36 @@ package org.apache.tools.ant.types;
import java.io.File;
import java.util.Locale;
-import junit.framework.TestCase;
-
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.condition.Os;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
- * JUnit 3 testcases for org.apache.tools.ant.types.Path
+ * JUnit testcases for org.apache.tools.ant.types.Path
*
*/
-public class PathTest extends TestCase {
+public class PathTest {
public static boolean isUnixStyle = File.pathSeparatorChar == ':';
public static boolean isNetWare = Os.isFamily("netware");
private Project project;
- public PathTest(String name) {
- super(name);
- }
-
+ @Before
public void setUp() {
project = new Project();
project.setBasedir(System.getProperty("root"));
}
// actually tests constructor as well as setPath
+ @Test
public void testConstructorUnixStyle() {
Path p = new Path(project, "/a:/b");
String[] l = p.list();
@@ -66,6 +68,7 @@ public class PathTest extends TestCase {
}
}
+ @Test
public void testRelativePathUnixStyle() {
project.setBasedir(new File(System.getProperty("root"), "src/etc").getAbsolutePath());
Path p = new Path(project, "..:testcases");
@@ -89,6 +92,7 @@ public class PathTest extends TestCase {
}
}
+ @Test
public void testConstructorWindowsStyle() {
Path p = new Path(project, "\\a;\\b");
String[] l = p.list();
@@ -176,6 +180,7 @@ public class PathTest extends TestCase {
}
}
+ @Test
public void testConstructorNetWareStyle() {
// try a netware-volume length path, see how it is handled
Path p = new Path(project, "sys:\\test");
@@ -296,6 +301,7 @@ public class PathTest extends TestCase {
}
}
+ @Test
public void testConstructorMixedStyle() {
Path p = new Path(project, "\\a;\\b:/c");
String[] l = p.list();
@@ -316,6 +322,7 @@ public class PathTest extends TestCase {
}
}
+ @Test
public void testSetLocation() {
Path p = new Path(project);
p.setLocation(new File(File.separatorChar+"a"));
@@ -332,6 +339,7 @@ public class PathTest extends TestCase {
}
}
+ @Test
public void testAppending() {
Path p = new Path(project, "/a:/b");
String[] l = p.list();
@@ -350,6 +358,7 @@ public class PathTest extends TestCase {
assertEquals("7 after append", 7, l.length);
}
+ @Test
public void testEmpyPath() {
Path p = new Path(project, "");
String[] l = p.list();
@@ -365,6 +374,7 @@ public class PathTest extends TestCase {
assertEquals("0 after append", 0, l.length);
}
+ @Test
public void testUnique() {
Path p = new Path(project, "/a:/a");
String[] l = p.list();
@@ -384,6 +394,7 @@ public class PathTest extends TestCase {
assertEquals("1 after append", 1, l.length);
}
+ @Test
public void testEmptyElementIfIsReference() {
Path p = new Path(project, "/a:/a");
try {
@@ -465,6 +476,7 @@ public class PathTest extends TestCase {
}
}
+ @Test
public void testCircularReferenceCheck() {
Path p = new Path(project);
project.addReference("dummy", p);
@@ -513,6 +525,7 @@ public class PathTest extends TestCase {
}
}
+ @Test
public void testFileList() {
Path p = new Path(project);
FileList f = new FileList();
@@ -525,6 +538,7 @@ public class PathTest extends TestCase {
assertEquals(project.resolveFile("build.xml").getAbsolutePath(), l[0]);
}
+ @Test
public void testFileSet() {
Path p = new Path(project);
FileSet f = new FileSet();
@@ -537,6 +551,7 @@ public class PathTest extends TestCase {
assertEquals(project.resolveFile("build.xml").getAbsolutePath(), l[0]);
}
+ @Test
public void testDirSet() {
Path p = new Path(project);
DirSet d = new DirSet();
@@ -549,6 +564,7 @@ public class PathTest extends TestCase {
assertEquals(project.resolveFile("build").getAbsolutePath(), l[0]);
}
+ @Test
public void testRecursion() {
Path p = new Path(project);
try {
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/PatternSetTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/PatternSetTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/PatternSetTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/PatternSetTest.java Fri Apr 18 21:00:38 2014
@@ -18,12 +18,15 @@
package org.apache.tools.ant.types;
-import java.io.File;
-
-import junit.framework.TestCase;
-
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
* JUnit 3 testcases for org.apache.tools.ant.types.PatternSet.
@@ -32,19 +35,17 @@ import org.apache.tools.ant.Project;
*
*/
-public class PatternSetTest extends TestCase {
+public class PatternSetTest {
private Project project;
- public PatternSetTest(String name) {
- super(name);
- }
-
+ @Before
public void setUp() {
project = new Project();
project.setBasedir(".");
}
+ @Test
public void testEmptyElementIfIsReference() {
PatternSet p = new PatternSet();
p.setIncludes("**/*.java");
@@ -119,6 +120,7 @@ public class PatternSetTest extends Test
}
}
+ @Test
public void testCircularReferenceCheck() {
PatternSet p = new PatternSet();
project.addReference("dummy", p);
@@ -185,6 +187,7 @@ public class PatternSetTest extends Test
assertEquals("exclude", i[0]);
}
+ @Test
public void testNestedPatternset() {
PatternSet p = new PatternSet();
p.setIncludes("**/*.java");
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/PermissionsTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/PermissionsTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/PermissionsTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/PermissionsTest.java Fri Apr 18 21:00:38 2014
@@ -18,22 +18,21 @@
package org.apache.tools.ant.types;
-import junit.framework.TestCase;
-
import org.apache.tools.ant.ExitException;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.fail;
/**
* JUnit 3 testcases for org.apache.tools.ant.types.Permissions.
*
*/
-public class PermissionsTest extends TestCase {
+public class PermissionsTest {
Permissions perms;
- public PermissionsTest(String name) {
- super(name);
- }
-
+ @Before
public void setUp() {
perms = new Permissions();
Permissions.Permission perm = new Permissions.Permission();
@@ -72,16 +71,18 @@ public class PermissionsTest extends Tes
}
/** Tests a permission that is granted per default. */
+ @Test
public void testDefaultGranted() {
perms.setSecurityManager();
try {
- String s = System.getProperty("line.separator");
+ System.getProperty("line.separator");
} finally {
perms.restoreSecurityManager();
}
}
/** Tests a permission that has been granted later via wildcard. */
+ @Test
public void testGranted() {
perms.setSecurityManager();
try {
@@ -93,6 +94,7 @@ public class PermissionsTest extends Tes
}
/** Tests a permission that has been granted and revoked later. */
+ @Test
public void testGrantedAndRevoked() {
perms.setSecurityManager();
try {
@@ -107,6 +109,7 @@ public class PermissionsTest extends Tes
}
/** Tests a permission that is granted as per default but revoked later via wildcard. */
+ @Test
public void testDefaultRevoked() {
perms.setSecurityManager();
try {
@@ -119,13 +122,15 @@ public class PermissionsTest extends Tes
}
}
/** Tests a permission that has not been granted or revoked. */
+ @Test
public void testOther() {
String ls = System.getProperty("line.separator");
perms.setSecurityManager();
try {
- String s = System.setProperty("line.separator",ls);
+ System.setProperty("line.separator",ls);
fail("Could perform an action that should have been forbidden.");
} catch (SecurityException e){
+ //TODO assert exception message
// Was expected, test passes
} finally {
perms.restoreSecurityManager();
@@ -133,6 +138,7 @@ public class PermissionsTest extends Tes
}
/** Tests an exit condition. */
+ @Test
public void testExit() {
perms.setSecurityManager();
try {
@@ -149,8 +155,4 @@ public class PermissionsTest extends Tes
}
}
-
- public void tearDown() {
- }
-
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/PolyTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/PolyTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/PolyTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/PolyTest.java Fri Apr 18 21:00:38 2014
@@ -18,34 +18,46 @@
package org.apache.tools.ant.types;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.AntAssert;
+import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
-
-public class PolyTest extends BuildFileTest {
-
- public PolyTest(String name) {
- super(name);
- }
-
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class PolyTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/types/poly.xml");
+ buildRule.configureProject("src/etc/testcases/types/poly.xml");
}
+ @Test
public void testFileSet() {
- expectLogContaining("fileset", "types.FileSet");
+ buildRule.executeTarget("fileset");
+ AntAssert.assertContains( "types.FileSet", buildRule.getLog());
}
+ @Test
public void testFileSetAntType() {
- expectLogContaining("fileset-ant-type", "types.PolyTest$MyFileSet");
+ buildRule.executeTarget("fileset-ant-type");
+ AntAssert.assertContains("types.PolyTest$MyFileSet", buildRule.getLog());
}
+ @Test
public void testPath() {
- expectLogContaining("path", "types.Path");
+ buildRule.executeTarget("path");
+ AntAssert.assertContains( "types.Path", buildRule.getLog());
}
+ @Test
public void testPathAntType() {
- expectLogContaining("path-ant-type", "types.PolyTest$MyPath");
+ buildRule.executeTarget("path-ant-type");
+ AntAssert.assertContains( "types.PolyTest$MyPath", buildRule.getLog());
}
public static class MyFileSet extends FileSet {}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/RedirectorElementTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/RedirectorElementTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/RedirectorElementTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/RedirectorElementTest.java Fri Apr 18 21:00:38 2014
@@ -17,48 +17,70 @@
*/
package org.apache.tools.ant.types;
+import org.apache.tools.ant.AntAssert;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.Project;
-import org.apache.tools.ant.BuildFileTest;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
-public class RedirectorElementTest extends BuildFileTest {
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
- public RedirectorElementTest(String name) {
- super(name);
- }
+public class RedirectorElementTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/types/redirector.xml", Project.MSG_VERBOSE);
+ buildRule.configureProject("src/etc/testcases/types/redirector.xml", Project.MSG_VERBOSE);
}
+ @Test
public void test1() {
- executeTarget("test1");
- assertTrue((getProject().<Object> getReference("test1")
+ buildRule.executeTarget("test1");
+ assertTrue((buildRule.getProject().<Object> getReference("test1")
instanceof RedirectorElement));
}
+ @Test
public void test2() {
- expectBuildException("test2", "You must not specify more than one "
- + "attribute when using refid");
+ try {
+ buildRule.executeTarget("test2");
+ fail("You must not specify more than one attribute when using refid");
+ } catch (BuildException ex) {
+ //TODO assert exception message
+ }
}
+ @Test
public void test3() {
- expectBuildException("test3", "You must not specify nested elements "
- + "when using refid");
+ try {
+ buildRule.executeTarget("test3");
+ fail("You must not specify nested elements when using refid");
+ } catch (BuildException ex) {
+ //TODO assert exception message
+ }
}
+ @Test
public void test4() {
- executeTarget("test4");
+ buildRule.executeTarget("test4");
}
+ @Test
public void testLogInputString() {
- executeTarget("testLogInputString");
- if (super.getLog().indexOf("testLogInputString can-cat") >=0 ) {
- assertDebuglogContaining("Using input string");
+ buildRule.executeTarget("testLogInputString");
+ if (buildRule.getLog().indexOf("testLogInputString can-cat") >=0 ) {
+ AntAssert.assertContains("Using input string", buildRule.getFullLog());
}
}
+ @Test
public void testRefid() {
- executeTarget("testRefid");
+ buildRule.executeTarget("testRefid");
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/ResourceOutputTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/ResourceOutputTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/ResourceOutputTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/ResourceOutputTest.java Fri Apr 18 21:00:38 2014
@@ -23,7 +23,6 @@ import java.io.IOException;
import java.net.UnknownServiceException;
import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileTest;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Zip;
import org.apache.tools.ant.types.resources.ImmutableResourceException;
@@ -33,78 +32,85 @@ import org.apache.tools.ant.types.resour
import org.apache.tools.ant.types.resources.ZipResource;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.ResourceUtils;
+import org.junit.Before;
+import org.junit.Test;
-public class ResourceOutputTest extends BuildFileTest {
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+public class ResourceOutputTest {
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
private static final File basedir = new File(System.getProperty("root"),
"src/etc/testcases/types/resources");
- public ResourceOutputTest(String name) {
- super(name);
- }
+ private Project project;
+ @Before
public void setUp() {
project = new Project();
project.init();
project.setUserProperty("basedir" , basedir.getAbsolutePath());
}
+ @Test
public void testresourceoutput() {
try {
testoutputbe(new Resource("foo"));
fail("should have caught UnsupportedOperationException");
} catch (UnsupportedOperationException e) {
+ //TODO assert exception message
}
}
+ @Test
public void teststringoutput1() {
StringResource r = new StringResource();
testoutputbe(r);
assertEquals("foo", r.getValue());
}
- public void teststringoutput2() {
+ @Test
+ public void teststringoutput2() throws IOException {
StringResource r = new StringResource("bar");
try {
testoutput(r);
fail("should have caught ImmutableResourceException");
} catch (ImmutableResourceException e) {
- } catch (IOException e) {
- fail("caught some other IOException: " + e);
+ //TODO assert exception message
}
assertEquals("bar", r.getValue());
}
+ @Test
public void testpropertyoutput1() {
- PropertyResource r = new PropertyResource(getProject(), "bar");
+ PropertyResource r = new PropertyResource(project, "bar");
testoutputbe(r);
- assertPropertyEquals("bar", "foo");
+ assertEquals("foo", project.getProperty("bar"));
}
- public void testpropertyoutput2() {
- getProject().setNewProperty("bar", "bar");
- PropertyResource r = new PropertyResource(getProject(), "bar");
+ @Test
+ public void testpropertyoutput2() throws IOException {
+ project.setNewProperty("bar", "bar");
+ PropertyResource r = new PropertyResource(project, "bar");
try {
testoutput(r);
fail("should have caught ImmutableResourceException");
} catch (ImmutableResourceException e) {
- } catch (IOException e) {
- fail("caught some other IOException: " + e);
+ //TODO assert exception message
}
- assertPropertyEquals("bar", "bar");
+ assertEquals("bar", project.getProperty("bar"));
}
- public void testurloutput() {
- File f = getProject().resolveFile("testurloutput");
+ @Test
+ public void testurloutput() throws IOException {
+ File f = project.resolveFile("testurloutput");
try {
FILE_UTILS.createNewFile(f);
testoutput(new URLResource(f));
fail("should have caught UnknownServiceException");
} catch (UnknownServiceException e) {
- } catch (IOException e) {
- e.printStackTrace(System.err);
- fail("caught some other IOException: " + e);
+ //TODO assert exception message
} finally {
if (!f.delete()) {
f.deleteOnExit();
@@ -112,15 +118,16 @@ public class ResourceOutputTest extends
}
}
+ @Test
public void testzipentryoutput() {
Zip z = new Zip();
- z.setProject(getProject());
+ z.setProject(project);
Zip.WhenEmpty create = new Zip.WhenEmpty();
create.setValue("create");
z.setWhenempty(create);
z.setBasedir(basedir);
z.setExcludes("**/*");
- File f = getProject().resolveFile("foo");
+ File f = project.resolveFile("foo");
z.setDestFile(f);
z.execute();
ZipResource r = new ZipResource();
@@ -130,6 +137,7 @@ public class ResourceOutputTest extends
testoutputbe(r);
fail("should have caught UnsupportedOperationException");
} catch (UnsupportedOperationException e) {
+ //TODO assert exception message
} finally {
if (!f.delete()) {
f.deleteOnExit();
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java Fri Apr 18 21:00:38 2014
@@ -21,6 +21,11 @@ package org.apache.tools.ant.types;
import java.io.File;
import org.apache.tools.ant.BuildException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* JUnit 3 testcases for org.apache.tools.ant.types.TarFileSet.
@@ -31,13 +36,12 @@ import org.apache.tools.ant.BuildExcepti
public class TarFileSetTest extends AbstractFileSetTest {
- public TarFileSetTest(String name) {
- super(name);
- }
protected AbstractFileSet getInstance() {
return new TarFileSet();
}
+
+ @Test
public final void testAttributes() {
TarFileSet f = (TarFileSet)getInstance();
//check that dir and src are incompatible
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/XMLCatalogBuildFileTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/XMLCatalogBuildFileTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/XMLCatalogBuildFileTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/XMLCatalogBuildFileTest.java Fri Apr 18 21:00:38 2014
@@ -18,25 +18,24 @@
package org.apache.tools.ant.types;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
/**
- * BuildFileTest testcases for org.apache.tools.ant.types.XMLCatalog
+ * testcases for org.apache.tools.ant.types.XMLCatalog
*
* @see org.apache.tools.ant.types.XMLCatalogTest
*
*/
-public class XMLCatalogBuildFileTest extends BuildFileTest {
+public class XMLCatalogBuildFileTest {
- public XMLCatalogBuildFileTest(String name) {
- super(name);
- }
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
- public void setUp() {
- }
- public void tearDown() {
- }
//
// Ensure that an external entity resolves as expected with NO
@@ -45,10 +44,11 @@ public class XMLCatalogBuildFileTest ext
// Transform an XML file that refers to the entity into a text
// file, stuff result into property: val1
//
+ @Test
public void testEntityNoCatalog() {
- configureProject("src/etc/testcases/types/xmlcatalog.xml");
- expectPropertySet("testentitynocatalog", "val1",
- "A stitch in time saves nine");
+ buildRule.configureProject("src/etc/testcases/types/xmlcatalog.xml");
+ buildRule.executeTarget("testentitynocatalog");
+ assertEquals("A stitch in time saves nine", buildRule.getProject().getProperty("val1"));
}
//
@@ -59,10 +59,11 @@ public class XMLCatalogBuildFileTest ext
// file, entity is listed in the XMLCatalog pointing to a
// different file. Stuff result into property: val2
//
+ @Test
public void testEntityWithCatalog() {
- configureProject("src/etc/testcases/types/xmlcatalog.xml");
- expectPropertySet("testentitywithcatalog", "val2",
- "No news is good news");
+ buildRule.configureProject("src/etc/testcases/types/xmlcatalog.xml");
+ buildRule.executeTarget("testentitywithcatalog");
+ assertEquals("No news is good news", buildRule.getProject().getProperty("val2"));
}
//
@@ -73,10 +74,11 @@ public class XMLCatalogBuildFileTest ext
// via the document() function. The _second_ XML file refers to an entity.
// Stuff result into the property: val3
//
+ @Test
public void testDocumentNoCatalog() {
- configureProject("src/etc/testcases/types/xmlcatalog.xml");
- expectPropertySet("testdocumentnocatalog", "val3",
- "A stitch in time saves nine");
+ buildRule.configureProject("src/etc/testcases/types/xmlcatalog.xml");
+ buildRule.executeTarget("testdocumentnocatalog");
+ assertEquals("A stitch in time saves nine", buildRule.getProject().getProperty("val3"));
}
//
@@ -87,10 +89,10 @@ public class XMLCatalogBuildFileTest ext
// via the document() function. The _second_ XML file refers to an entity.
// The entity is listed in the XMLCatalog pointing to a different file.
// Stuff result into the property: val4
- //
+ @Test
public void testDocumentWithCatalog() {
- configureProject("src/etc/testcases/types/xmlcatalog.xml");
- expectPropertySet("testdocumentwithcatalog", "val4",
- "No news is good news");
+ buildRule.configureProject("src/etc/testcases/types/xmlcatalog.xml");
+ buildRule.executeTarget("testdocumentwithcatalog");
+ assertEquals("No news is good news", buildRule.getProject().getProperty("val4"));
}
}