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 [9/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/taskdef...
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/WarTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/WarTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/WarTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/WarTest.java Fri Apr 18 21:00:38 2014
@@ -20,30 +20,36 @@ package org.apache.tools.ant.taskdefs;
import java.io.File;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
/**
* Testcase for the war task
*
*/
-public class WarTest extends BuildFileTest {
+public class WarTest {
public static final String TEST_BUILD_FILE
= "src/etc/testcases/taskdefs/war.xml";
- public WarTest(String name) {
- super(name);
- }
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+ @Before
public void setUp() {
- configureProject(TEST_BUILD_FILE);
+ buildRule.configureProject(TEST_BUILD_FILE);
}
/**
* Test direct dependency removal
*/
+ @Test
public void testLibRefs() {
- executeTarget("testlibrefs");
- File f = new File(getOutputDir(), "WEB-INF/lib/war.xml");
+ buildRule.executeTarget("testlibrefs");
+ File f = new File(buildRule.getOutputDir(), "WEB-INF/lib/war.xml");
assertTrue("File has been put into lib", f.exists());
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/WhichResourceTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/WhichResourceTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/WhichResourceTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/WhichResourceTest.java Fri Apr 18 21:00:38 2014
@@ -18,32 +18,41 @@
package org.apache.tools.ant.taskdefs;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
-public class WhichResourceTest extends BuildFileTest {
+import static org.junit.Assert.assertNotNull;
+
+public class WhichResourceTest {
public static final String TEST_BUILD_FILE
= "src/etc/testcases/taskdefs/whichresource.xml";
- public WhichResourceTest(String name) {
- super(name);
- }
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
public void setUp() {
- configureProject(TEST_BUILD_FILE);
+ buildRule.configureProject(TEST_BUILD_FILE);
}
+ @Test
public void testClassname() {
- executeTarget("testClassname");
- assertNotNull(getProject().getProperty("antmain"));
+ buildRule.executeTarget("testClassname");
+ assertNotNull(buildRule.getProject().getProperty("antmain"));
}
+ @Test
public void testResourcename() {
- executeTarget("testResourcename");
- assertNotNull(getProject().getProperty("defaults"));
+ buildRule.executeTarget("testResourcename");
+ assertNotNull(buildRule.getProject().getProperty("defaults"));
}
+ @Test
public void testResourcenameWithLeadingSlash() {
- executeTarget("testResourcenameWithLeadingSlash");
- assertNotNull(getProject().getProperty("defaults"));
+ buildRule.executeTarget("testResourcenameWithLeadingSlash");
+ assertNotNull(buildRule.getProject().getProperty("defaults"));
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/XmlPropertyTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/XmlPropertyTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/XmlPropertyTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/XmlPropertyTest.java Fri Apr 18 21:00:38 2014
@@ -27,95 +27,116 @@ import java.util.Hashtable;
import java.util.Properties;
import java.util.Vector;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.util.FileUtils;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
*/
-public class XmlPropertyTest extends BuildFileTest {
+public class XmlPropertyTest {
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
- public XmlPropertyTest(String name) {
- super(name);
- }
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/taskdefs/xmlproperty.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/xmlproperty.xml");
}
+ @Test
public void testFile() {
testProperties("test");
}
+ @Test
public void testResource() {
testProperties("testResource");
}
private void testProperties(String target) {
- executeTarget(target);
- assertEquals("true", getProject().getProperty("root-tag(myattr)"));
- assertEquals("Text", getProject().getProperty("root-tag.inner-tag"));
+ buildRule.executeTarget(target);
+ assertEquals("true", buildRule.getProject().getProperty("root-tag(myattr)"));
+ assertEquals("Text", buildRule.getProject().getProperty("root-tag.inner-tag"));
assertEquals("val",
- getProject().getProperty("root-tag.inner-tag(someattr)"));
- assertEquals("false", getProject().getProperty("root-tag.a2.a3.a4"));
+ buildRule.getProject().getProperty("root-tag.inner-tag(someattr)"));
+ assertEquals("false", buildRule.getProject().getProperty("root-tag.a2.a3.a4"));
assertEquals("CDATA failed",
- "<test>", getProject().getProperty("root-tag.cdatatag"));
+ "<test>", buildRule.getProject().getProperty("root-tag.cdatatag"));
}
+ @Test
public void testDTD() {
- executeTarget("testdtd");
- assertEquals("Text", getProject().getProperty("root-tag.inner-tag"));
+ buildRule.executeTarget("testdtd");
+ assertEquals("Text", buildRule.getProject().getProperty("root-tag.inner-tag"));
}
- public void testNone () {
+ @Test
+ public void testNone () throws IOException {
doTest("testNone", false, false, false, false, false);
}
- public void testKeeproot() {
+ @Test
+ public void testKeeproot() throws IOException {
doTest("testKeeproot", true, false, false, false, false);
}
- public void testCollapse () {
+ @Test
+ public void testCollapse () throws IOException {
doTest("testCollapse", false, true, false, false, false);
}
- public void testSemantic () {
+ @Test
+ public void testSemantic () throws IOException {
doTest("testSemantic", false, false, true, false, false);
}
- public void testKeeprootCollapse () {
+ @Test
+ public void testKeeprootCollapse () throws IOException {
doTest("testKeeprootCollapse", true, true, false, false, false);
}
- public void testKeeprootSemantic () {
+ @Test
+ public void testKeeprootSemantic () throws IOException {
doTest("testKeeprootSemantic", true, false, true, false, false);
}
- public void testCollapseSemantic () {
+ @Test
+ public void testCollapseSemantic () throws IOException {
doTest("testCollapseSemantic", false, true, true, false, false);
}
- public void testKeeprootCollapseSemantic () {
+ @Test
+ public void testKeeprootCollapseSemantic () throws IOException {
doTest("testKeeprootCollapseSemantic", true, true, true, false, false);
}
- public void testInclude () {
+ @Test
+ public void testInclude () throws IOException {
doTest("testInclude", false, false, false, true, false);
}
- public void testSemanticInclude () {
+ @Test
+ public void testSemanticInclude () throws IOException {
doTest("testSemanticInclude", false, false, true, true, false);
}
- public void testSemanticLocal () {
+ @Test
+ public void testSemanticLocal () throws IOException {
doTest("testSemanticInclude", false, false, true, false, true);
}
+ @Test
public void testNeedsCatalog() {
- executeTarget("testneedscat");
- assertEquals("true", getProject().getProperty("skinconfig.foo"));
+ buildRule.executeTarget("testneedscat");
+ assertEquals("true", buildRule.getProject().getProperty("skinconfig.foo"));
}
/**
@@ -123,7 +144,7 @@ public class XmlPropertyTest extends Bui
* goldfile)
*/
private void doTest(String msg, boolean keepRoot, boolean collapse,
- boolean semantic, boolean include, boolean localRoot) {
+ boolean semantic, boolean include, boolean localRoot) throws IOException {
Enumeration iter =
getFiles(new File(System.getProperty("root"), "src/etc/testcases/taskdefs/xmlproperty/inputs"));
while (iter.hasMoreElements()) {
@@ -137,49 +158,45 @@ public class XmlPropertyTest extends Bui
workingDir = FILE_UTILS.resolveFile(new File("."), ".");
}
- try {
- File propertyFile = getGoldfile(inputFile, keepRoot, collapse,
- semantic, include, localRoot);
- if (!propertyFile.exists()) {
+ File propertyFile = getGoldfile(inputFile, keepRoot, collapse,
+ semantic, include, localRoot);
+ if (!propertyFile.exists()) {
// System.out.println("Skipping as "
// + propertyFile.getAbsolutePath()
// + ") doesn't exist.");
- continue;
- }
+ continue;
+ }
- // System.out.println(msg + " (" + propertyFile.getName() + ") in (" + workingDir + ")");
+ // System.out.println(msg + " (" + propertyFile.getName() + ") in (" + workingDir + ")");
- Project p = new Project();
+ Project p = new Project();
- XmlProperty xmlproperty = new XmlProperty();
- xmlproperty.setProject(p);
- xmlproperty.setFile(inputFile);
+ XmlProperty xmlproperty = new XmlProperty();
+ xmlproperty.setProject(p);
+ xmlproperty.setFile(inputFile);
- xmlproperty.setKeeproot(keepRoot);
- xmlproperty.setCollapseAttributes(collapse);
- xmlproperty.setSemanticAttributes(semantic);
- xmlproperty.setIncludeSemanticAttribute(include);
- xmlproperty.setRootDirectory(workingDir);
+ xmlproperty.setKeeproot(keepRoot);
+ xmlproperty.setCollapseAttributes(collapse);
+ xmlproperty.setSemanticAttributes(semantic);
+ xmlproperty.setIncludeSemanticAttribute(include);
+ xmlproperty.setRootDirectory(workingDir);
- // Set a property on the project to make sure that loading
- // a property with the same name from an xml file will
- // *not* change it.
- p.setNewProperty("override.property.test", "foo");
+ // Set a property on the project to make sure that loading
+ // a property with the same name from an xml file will
+ // *not* change it.
+ p.setNewProperty("override.property.test", "foo");
- xmlproperty.execute();
+ xmlproperty.execute();
- Properties props = new Properties();
- props.load(new FileInputStream(propertyFile));
+ Properties props = new Properties();
+ props.load(new FileInputStream(propertyFile));
- //printProperties(p.getProperties());
+ //printProperties(p.getProperties());
- ensureProperties(msg, inputFile, workingDir, p, props);
- ensureReferences(msg, inputFile, p.getReferences());
+ ensureProperties(msg, inputFile, workingDir, p, props);
+ ensureReferences(msg, inputFile, p.getReferences());
- } catch (IOException ex) {
- fail(ex.toString());
- }
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/XmlnsTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/XmlnsTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/XmlnsTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/XmlnsTest.java Fri Apr 18 21:00:38 2014
@@ -18,44 +18,65 @@
package org.apache.tools.ant.taskdefs;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.Task;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
-/**
- */
-public class XmlnsTest extends BuildFileTest {
- public XmlnsTest(String name) {
- super(name);
- }
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+
+public class XmlnsTest {
+ @Rule
+ public final BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/taskdefs/xmlns.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/xmlns.xml");
}
+ @Test
public void testXmlns() {
- expectLog("xmlns", "MyTask called");
+ buildRule.executeTarget("xmlns");
+ assertEquals("MyTask called", buildRule.getLog());
}
+ @Test
public void testXmlnsFile() {
- expectLog("xmlns.file", "MyTask called");
+ buildRule.executeTarget("xmlns.file");
+ assertEquals("MyTask called", buildRule.getLog());
}
+ @Test
public void testCore() {
- expectLog("core", "MyTask called");
+ buildRule.executeTarget("core");
+ assertEquals("MyTask called", buildRule.getLog());
}
+ @Test
public void testExcluded() {
- expectBuildExceptionContaining(
- "excluded", "excluded uri",
- "Attempt to use a reserved URI ant:notallowed");
+ try {
+ buildRule.executeTarget("excluded");
+ fail("BuildException expected: excluded uri");
+ } catch (BuildException ex) {
+ assertEquals("Attempt to use a reserved URI ant:notallowed", ex.getMessage());
+ }
}
+ @Test
public void testOther() {
- expectLog("other", "a message");
+ buildRule.executeTarget("other");
+ assertEquals("a message", buildRule.getLog());
}
+ @Test
public void testNsAttributes() {
- expectLog("ns.attributes", "hello world");
+ buildRule.executeTarget("ns.attributes");
+ assertEquals("hello world", buildRule.getLog());
}
public static class MyTask extends Task {
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/ZipExtraFieldTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/ZipExtraFieldTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/ZipExtraFieldTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/ZipExtraFieldTest.java Fri Apr 18 21:00:38 2014
@@ -22,11 +22,9 @@ import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
-import junit.framework.TestCase;
import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.ResourceCollection;
@@ -36,9 +34,15 @@ import org.apache.tools.zip.Zip64Extende
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipExtraField;
import org.apache.tools.zip.ZipFile;
+import org.junit.Test;
-public class ZipExtraFieldTest extends TestCase {
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+public class ZipExtraFieldTest {
+
+ @Test
public void testPreservesExtraFields() throws IOException {
testExtraField(new Zip(), true);
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java Fri Apr 18 21:00:38 2014
@@ -24,39 +24,81 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.zip.UnixStat;
-
-/**
- */
-public class ZipTest extends BuildFileTest {
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.apache.tools.ant.AntAssert.assertContains;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
+
+
+public class ZipTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
//instance variable to allow cleanup
ZipFile zfPrefixAddsDir = null;
- public ZipTest(String name) {
- super(name);
- }
+
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/taskdefs/zip.xml");
- executeTarget("setUp");
+ buildRule.configureProject("src/etc/testcases/taskdefs/zip.xml");
+ buildRule.executeTarget("setUp");
}
+ @Test
public void test1() {
- expectBuildException("test1", "required argument not specified");
+ try {
+ buildRule.executeTarget("test1");
+ fail("BuildException expected: required argument not specified");
+ } catch (BuildException ex) {
+ //TODO assert value
+ }
}
+ @Test
public void test2() {
- expectBuildException("test2", "required argument not specified");
+ try {
+ buildRule.executeTarget("test2");
+ fail("BuildException expected: required argument not specified");
+ } catch (BuildException ex) {
+ //TODO assert value
+ }
}
+ @Test
public void test3() {
- expectBuildException("test3", "zip cannot include itself");
+ try {
+ buildRule.executeTarget("test3");
+ fail("BuildException expected: zip cannot include itself");
+ } catch (BuildException ex) {
+ //TODO assert value
+ }
}
- // public void test4() {
- // expectBuildException("test4", "zip cannot include itself");
- // }
+ @Test
+ @Ignore("Previously commented out")
+ public void test4() {
+ try {
+ buildRule.executeTarget("test4");
+ fail("BuildException expected: zip cannot include itself");
+ } catch (BuildException ex) {
+ //TODO assert value
+ }
+ }
+ @After
public void tearDown() {
try {
if ( zfPrefixAddsDir != null) {
@@ -66,35 +108,35 @@ public class ZipTest extends BuildFileTe
} catch (IOException e) {
//ignored
}
- try {
- super.tearDown();
- } catch (Exception exc) {
- System.err.println(exc.getMessage());
- }
}
+ @Test
public void test5() {
- executeTarget("test5");
+ buildRule.executeTarget("test5");
}
+ @Test
public void test6() {
- executeTarget("test6");
+ buildRule.executeTarget("test6");
}
+ @Test
public void test7() {
- executeTarget("test7");
+ buildRule.executeTarget("test7");
}
+ @Test
public void test8() {
- executeTarget("test8");
+ buildRule.executeTarget("test8");
}
+ @Test
public void testZipgroupfileset() throws IOException {
- executeTarget("testZipgroupfileset");
+ buildRule.executeTarget("testZipgroupfileset");
- ZipFile zipFile = new ZipFile(new File(getProject().getProperty("output"), "zipgroupfileset.zip"));
+ ZipFile zipFile = new ZipFile(new File(buildRule.getProject().getProperty("output"), "zipgroupfileset.zip"));
assertTrue(zipFile.getEntry("ant.xml") != null);
assertTrue(zipFile.getEntry("optional/jspc.xml") != null);
@@ -106,19 +148,23 @@ public class ZipTest extends BuildFileTe
zipFile.close();
}
+ @Test
public void testUpdateNotNecessary() {
- executeTarget("testUpdateNotNecessary");
- assertEquals(-1, getLog().indexOf("Updating"));
+ buildRule.executeTarget("testUpdateNotNecessary");
+ assertEquals(-1, buildRule.getLog().indexOf("Updating"));
}
+ @Test
public void testUpdateIsNecessary() {
- expectLogContaining("testUpdateIsNecessary", "Updating");
+ buildRule.executeTarget("testUpdateIsNecessary");
+ assertContains("Updating", buildRule.getLog());
}
// Bugzilla Report 18403
+ @Test
public void testPrefixAddsDir() throws IOException {
- executeTarget("testPrefixAddsDir");
- File archive = new File(getProject().getProperty("output"), "test3.zip");
+ buildRule.executeTarget("testPrefixAddsDir");
+ File archive = new File(buildRule.getProject().getProperty("output"), "test3.zip");
zfPrefixAddsDir = new ZipFile(archive);
ZipEntry ze = zfPrefixAddsDir.getEntry("test/");
assertNotNull("test/ has been added", ze);
@@ -126,42 +172,52 @@ public class ZipTest extends BuildFileTe
}
// Bugzilla Report 19449
- public void testFilesOnlyDoesntCauseRecreate()
- throws InterruptedException {
- executeTarget("testFilesOnlyDoesntCauseRecreateSetup");
- long l = new File(getProject().getProperty("output"), "test3.zip").lastModified();
- Thread.sleep(3000);
- executeTarget("testFilesOnlyDoesntCauseRecreate");
- assertEquals(l, new File(getProject().getProperty("output"), "test3.zip").lastModified());
+ @Test
+ public void testFilesOnlyDoesntCauseRecreate() {
+ buildRule.executeTarget("testFilesOnlyDoesntCauseRecreateSetup");
+ File testFile = new File(buildRule.getOutputDir(), "test3.zip");
+ assumeTrue("Could not change file modification time",
+ testFile.setLastModified(testFile.lastModified() - (FileUtils.getFileUtils().getFileTimestampGranularity() * 5)));
+ long l = testFile.lastModified();
+
+ buildRule.executeTarget("testFilesOnlyDoesntCauseRecreate");
+ assertEquals(l, testFile.lastModified());
}
// Bugzilla Report 22865
+ @Test
public void testEmptySkip() {
- executeTarget("testEmptySkip");
+ buildRule.executeTarget("testEmptySkip");
}
// Bugzilla Report 30365
+ @Test
public void testZipEmptyDir() {
- executeTarget("zipEmptyDir");
+ buildRule.executeTarget("zipEmptyDir");
}
// Bugzilla Report 40258
+ @Test
public void testZipEmptyDirFilesOnly() {
- executeTarget("zipEmptyDirFilesOnly");
+ buildRule.executeTarget("zipEmptyDirFilesOnly");
}
+ @Test
public void testZipEmptyCreate() {
- expectLogContaining("zipEmptyCreate", "Note: creating empty");
+ buildRule.executeTarget("zipEmptyCreate");
+ assertContains("Note: creating empty", buildRule.getLog());
}
// Bugzilla Report 25513
+ @Test
public void testCompressionLevel() {
- executeTarget("testCompressionLevel");
+ buildRule.executeTarget("testCompressionLevel");
}
// Bugzilla Report 33412
- public void testDefaultExcludesAndUpdate()
+ @Test
+ public void testDefaultExcludesAndUpdate()
throws ZipException, IOException {
- executeTarget("testDefaultExcludesAndUpdate");
+ buildRule.executeTarget("testDefaultExcludesAndUpdate");
ZipFile f = null;
try {
- f = new ZipFile(new File(getProject().getProperty("output"), "test3.zip"));
+ f = new ZipFile(new File(buildRule.getProject().getProperty("output"), "test3.zip"));
assertNotNull("ziptest~ should be included",
f.getEntry("ziptest~"));
} finally {
@@ -171,19 +227,22 @@ public class ZipTest extends BuildFileTe
}
}
+ @Test
public void testFileResource() {
- executeTarget("testFileResource");
+ buildRule.executeTarget("testFileResource");
}
+ @Test
public void testNonFileResource() {
- executeTarget("testNonFileResource");
+ buildRule.executeTarget("testNonFileResource");
}
+ @Test
public void testTarFileSet() throws IOException {
- executeTarget("testTarFileSet");
+ buildRule.executeTarget("testTarFileSet");
org.apache.tools.zip.ZipFile zf = null;
try {
- zf = new org.apache.tools.zip.ZipFile(new File(getProject().getProperty("output"), "test3.zip"));
+ zf = new org.apache.tools.zip.ZipFile(new File(buildRule.getProject().getProperty("output"), "test3.zip"));
org.apache.tools.zip.ZipEntry ze = zf.getEntry("asf-logo.gif");
assertEquals(UnixStat.FILE_FLAG | 0446, ze.getUnixMode());
} finally {
@@ -193,11 +252,12 @@ public class ZipTest extends BuildFileTe
}
}
+ @Test
public void testRewriteZeroPermissions() throws IOException {
- executeTarget("rewriteZeroPermissions");
+ buildRule.executeTarget("rewriteZeroPermissions");
org.apache.tools.zip.ZipFile zf = null;
try {
- zf = new org.apache.tools.zip.ZipFile(new File(getProject().getProperty("output"), "test3.zip"));
+ zf = new org.apache.tools.zip.ZipFile(new File(buildRule.getProject().getProperty("output"), "test3.zip"));
org.apache.tools.zip.ZipEntry ze = zf.getEntry("testdir/test.txt");
assertEquals(UnixStat.FILE_FLAG | 0644, ze.getUnixMode());
} finally {
@@ -207,11 +267,12 @@ public class ZipTest extends BuildFileTe
}
}
+ @Test
public void testAcceptZeroPermissions() throws IOException {
- executeTarget("acceptZeroPermissions");
+ buildRule.executeTarget("acceptZeroPermissions");
org.apache.tools.zip.ZipFile zf = null;
try {
- zf = new org.apache.tools.zip.ZipFile(new File(getProject().getProperty("output"), "test3.zip"));
+ zf = new org.apache.tools.zip.ZipFile(new File(buildRule.getProject().getProperty("output"), "test3.zip"));
org.apache.tools.zip.ZipEntry ze = zf.getEntry("testdir/test.txt");
assertEquals(0000, ze.getUnixMode());
} finally {
@@ -221,11 +282,12 @@ public class ZipTest extends BuildFileTe
}
}
+ @Test
public void testForBugzilla34764() throws IOException {
- executeTarget("testForBugzilla34764");
+ buildRule.executeTarget("testForBugzilla34764");
org.apache.tools.zip.ZipFile zf = null;
try {
- zf = new org.apache.tools.zip.ZipFile(new File(getProject().getProperty("output"), "test3.zip"));
+ zf = new org.apache.tools.zip.ZipFile(new File(buildRule.getProject().getProperty("output"), "test3.zip"));
org.apache.tools.zip.ZipEntry ze = zf.getEntry("file1");
assertEquals(UnixStat.FILE_FLAG | 0644, ze.getUnixMode());
} finally {
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java Fri Apr 18 21:00:38 2014
@@ -21,9 +21,12 @@ package org.apache.tools.ant.taskdefs.co
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Javac;
import org.apache.tools.ant.types.Commandline;
-import junit.framework.TestCase;
+import org.junit.Test;
-public class DefaultCompilerAdapterTest extends TestCase {
+import static org.apache.tools.ant.AntAssert.assertContains;
+import static org.junit.Assert.assertEquals;
+
+public class DefaultCompilerAdapterTest {
private static class LogCapturingJavac extends Javac {
private StringBuffer sb = new StringBuffer();
@@ -54,6 +57,7 @@ public class DefaultCompilerAdapterTest
}
}
+ @Test
public void testSourceIsIgnoredForJavac13() {
testSource(null, "javac1.3", "", null, "1.1");
testSource(null, "javac1.3", "", null, "1.2");
@@ -61,6 +65,7 @@ public class DefaultCompilerAdapterTest
testSource(null, "javac1.3", "", null, "1.4");
}
+ @Test
public void testSource11IsUpgradedTo13() {
testSource("1.3", "javac1.4", "", null, "1.1");
testSource("1.3", "javac1.5", "", null, "1.1");
@@ -69,6 +74,7 @@ public class DefaultCompilerAdapterTest
testSource("1.3", "javac1.8", "", null, "1.1");
}
+ @Test
public void testSource12IsUpgradedTo13() {
testSource("1.3", "javac1.4", "", null, "1.2");
testSource("1.3", "javac1.5", "", null, "1.2");
@@ -77,12 +83,14 @@ public class DefaultCompilerAdapterTest
testSource("1.3", "javac1.8", "", null, "1.2");
}
+ @Test
public void testImplicitSourceForJava15() {
commonSourceDowngrades("javac1.5");
testSource(null, "javac1.5", "", "1.5");
testSource(null, "javac1.5", "", "5");
}
+ @Test
public void testImplicitSourceForJava16() {
commonSourceDowngrades("javac1.6");
testSource(null, "javac1.6", "", "1.5");
@@ -91,6 +99,7 @@ public class DefaultCompilerAdapterTest
testSource(null, "javac1.6", "", "6");
}
+ @Test
public void testImplicitSourceForJava17() {
commonSourceDowngrades("javac1.7");
testSource("1.5", "javac1.7",
@@ -109,6 +118,7 @@ public class DefaultCompilerAdapterTest
testSource(null, "javac1.7", "", "7");
}
+ @Test
public void testImplicitSourceForJava18() {
commonSourceDowngrades("javac1.8");
testSource("1.5", "javac1.8",
@@ -133,6 +143,7 @@ public class DefaultCompilerAdapterTest
testSource(null, "javac1.8", "", "8");
}
+ @Test
public void testImplicitSourceForJava19() {
commonSourceDowngrades("javac1.9");
testSource("1.5", "javac1.9",
@@ -204,8 +215,7 @@ public class DefaultCompilerAdapterTest
assertEquals("", javac.getLog());
} else {
String l = javac.getLog();
- assertTrue("expected to find '" + expectedLog + "' in '" + l + "'",
- l.indexOf(expectedLog) > -1);
+ assertContains(expectedLog, l);
}
String[] args = cmd.getCommandline();
assertEquals(expectedSource == null ? 0 : 2, args.length);
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/AntVersionTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/AntVersionTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/AntVersionTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/AntVersionTest.java Fri Apr 18 21:00:38 2014
@@ -17,27 +17,32 @@
*/
package org.apache.tools.ant.taskdefs.condition;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
/**
* Testcases for the <antversion> condition.
*
*/
-public class AntVersionTest extends BuildFileTest {
-
- public AntVersionTest(String name) {
- super(name);
- }
-
+public class AntVersionTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
public void setUp() throws Exception {
- configureProject("src/etc/testcases/taskdefs/conditions/antversion.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/conditions/antversion.xml");
}
-
+
+ @Test
public void testAtLeast() {
- executeTarget("testatleast");
+ buildRule.executeTarget("testatleast");
}
-
+
+ @Test
public void testExactly() {
- executeTarget("testexactly");
+ buildRule.executeTarget("testexactly");
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/ContainsTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/ContainsTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/ContainsTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/ContainsTest.java Fri Apr 18 21:00:38 2014
@@ -18,18 +18,17 @@
package org.apache.tools.ant.taskdefs.condition;
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
/**
* Testcase for the <contains> condition.
*
*/
-public class ContainsTest extends TestCase {
-
- public ContainsTest(String name) {
- super(name);
- }
+public class ContainsTest {
+ @Test
public void testCaseSensitive() {
Contains con = new Contains();
con.setString("abc");
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/EqualsTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/EqualsTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/EqualsTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/EqualsTest.java Fri Apr 18 21:00:38 2014
@@ -18,18 +18,17 @@
package org.apache.tools.ant.taskdefs.condition;
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
/**
* Testcase for the <equals> condition.
*
*/
-public class EqualsTest extends TestCase {
-
- public EqualsTest(String name) {
- super(name);
- }
+public class EqualsTest {
+ @Test
public void testTrim() {
Equals eq = new Equals();
eq.setArg1("a");
@@ -43,6 +42,7 @@ public class EqualsTest extends TestCase
assertTrue(eq.eval());
}
+ @Test
public void testCaseSensitive() {
Equals eq = new Equals();
eq.setArg1("a");
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/HttpTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/HttpTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/HttpTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/HttpTest.java Fri Apr 18 21:00:38 2014
@@ -17,45 +17,60 @@
*/
package org.apache.tools.ant.taskdefs.condition;
-import org.apache.tools.ant.BuildFileTest;
+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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
/**
* Testcases for the <http> condition. All these tests require
* us to be online as they attempt to get the status of various pages
* on the Ant Apache web site.
*/
-public class HttpTest extends BuildFileTest {
+public class HttpTest {
- public HttpTest(String name) {
- super(name);
- }
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
- /**
- * The JUnit setup method
- */
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/taskdefs/conditions/http.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/conditions/http.xml");
}
+ @Test
public void testNoMethod() {
- expectPropertySet("basic-no-method", "basic-no-method");
- assertPropertyUnset("basic-no-method-bad-url");
+ buildRule.executeTarget("basic-no-method");
+ assertEquals("true", buildRule.getProject().getProperty("basic-no-method"));
+ assertNull(buildRule.getProject().getProperty("basic-no-method-bad-url"));
}
+ @Test
public void testHeadRequest() {
- expectPropertySet("test-head-request", "test-head-request");
- assertPropertyUnset("test-head-request-bad-url");
+ buildRule.executeTarget("test-head-request");
+ assertEquals("true", buildRule.getProject().getProperty("test-head-request"));
+ assertNull(buildRule.getProject().getProperty("test-head-request-bad-url"));
}
+ @Test
public void testGetRequest() {
- expectPropertySet("test-get-request", "test-get-request");
- assertPropertyUnset("test-get-request-bad-url");
+ buildRule.executeTarget("test-get-request");
+ assertEquals("true", buildRule.getProject().getProperty("test-get-request"));
+ assertNull(buildRule.getProject().getProperty("test-get-request-bad-url"));
}
+ @Test
public void testBadRequestMethod() {
- expectSpecificBuildException("bad-request-method",
- "invalid HTTP request method specified",
- null);
+ try {
+ buildRule.executeTarget("bad-request-method");
+ fail("Exception should have been thrown as invalid HTTP request method specified");
+ } catch (BuildException ex) {
+ //TODO we should assert the correct build exception was thrown
+ }
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsFailureTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsFailureTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsFailureTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsFailureTest.java Fri Apr 18 21:00:38 2014
@@ -17,27 +17,28 @@
*/
package org.apache.tools.ant.taskdefs.condition;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
/**
* Testcases for the <isfailure> condition.
*
*/
-public class IsFailureTest extends BuildFileTest {
+public class IsFailureTest {
- public IsFailureTest(String name) {
- super(name);
- }
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
- /**
- * The JUnit setup method
- */
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/taskdefs/conditions/isfailure.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/conditions/isfailure.xml");
}
+ @Test
public void testIsFailure() {
- executeTarget("testisfailure");
+ buildRule.executeTarget("testisfailure");
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsFileSelectedTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsFileSelectedTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsFileSelectedTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsFileSelectedTest.java Fri Apr 18 21:00:38 2014
@@ -18,36 +18,57 @@
package org.apache.tools.ant.taskdefs.condition;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.AntAssert;
+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 static org.junit.Assert.fail;
/**
* Testcase for the <isfileselected> condition.
*
*/
-public class IsFileSelectedTest extends BuildFileTest {
+public class IsFileSelectedTest {
- public IsFileSelectedTest(String name) {
- super(name);
- }
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/taskdefs/conditions/isfileselected.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/conditions/isfileselected.xml");
}
+ @Test
public void testSimple() {
- executeTarget("simple");
+ buildRule.executeTarget("simple");
}
+
+ @Test
public void testName() {
- executeTarget("name");
+ buildRule.executeTarget("name");
}
+
+ @Test
public void testBaseDir() {
- executeTarget("basedir");
+ buildRule.executeTarget("basedir");
}
+
+ @Test
public void testType() {
- executeTarget("type");
+ buildRule.executeTarget("type");
}
+
+ @Test
public void testNotSelector() {
- expectBuildExceptionContaining(
- "not.selector", "checking for use as a selector (not allowed)",
- "fileset doesn't support the nested \"isfile");
+ try {
+ buildRule.executeTarget("not.selector");
+ fail("Exception should have been thrown: checking for use as a selector (not allowed)");
+ } catch(BuildException ex) {
+ AntAssert.assertContains("fileset doesn't support the nested \"isfile",
+ ex.getMessage());
+ }
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReachableTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReachableTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReachableTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReachableTest.java Fri Apr 18 21:00:38 2014
@@ -17,66 +17,100 @@
*/
package org.apache.tools.ant.taskdefs.condition;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.AntAssert;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
* test for reachable things
*/
-public class IsReachableTest extends BuildFileTest {
+public class IsReachableTest {
- public IsReachableTest(String name) {
- super(name);
- }
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+ @Before
public void setUp() {
- configureProject(
+ buildRule.configureProject(
"src/etc/testcases/taskdefs/conditions/isreachable.xml");
}
+ @Test
public void testLocalhost() throws Exception {
- executeTarget("testLocalhost");
+ buildRule.executeTarget("testLocalhost");
}
+ @Test
public void testLocalhostURL() throws Exception {
- executeTarget("testLocalhostURL");
+ buildRule.executeTarget("testLocalhostURL");
}
+ @Test
public void testIpv4localhost() throws Exception {
- executeTarget("testIpv4localhost");
+ buildRule.executeTarget("testIpv4localhost");
}
+ @Test
public void testFTPURL() throws Exception {
- executeTarget("testFTPURL");
+ buildRule.executeTarget("testFTPURL");
}
+ @Test
public void testBoth() throws Exception {
- expectBuildExceptionContaining("testBoth",
- "error on two targets",
- IsReachable.ERROR_BOTH_TARGETS);
+ try {
+ buildRule.executeTarget("testBoth");
+ fail("Build exception expected: error on two targets");
+ } catch(BuildException ex) {
+ assertEquals(IsReachable.ERROR_BOTH_TARGETS, ex.getMessage());
+ }
}
+ @Test
public void testNoTargets() throws Exception {
- expectBuildExceptionContaining("testNoTargets",
- "no params",
- IsReachable.ERROR_NO_HOSTNAME);
+ try {
+ buildRule.executeTarget("testNoTargets");
+ fail("Build exception expected: no params");
+ } catch(BuildException ex) {
+ assertEquals(IsReachable.ERROR_NO_HOSTNAME, ex.getMessage());
+ }
}
+ @Test
public void testBadTimeout() throws Exception {
- expectBuildExceptionContaining("testBadTimeout",
- "error on -ve timeout",
- IsReachable.ERROR_BAD_TIMEOUT);
+ try {
+ buildRule.executeTarget("testBadTimeout");
+ fail("Build exception expected: error on -ve timeout");
+ } catch(BuildException ex) {
+ assertEquals(IsReachable.ERROR_BAD_TIMEOUT, ex.getMessage());
+ }
}
+ @Test
+ @Ignore("Previously named in a way to prevent execution")
public void NotestFile() throws Exception {
- expectBuildExceptionContaining("testFile",
- "error on file URL",
- IsReachable.ERROR_NO_HOST_IN_URL);
+ try {
+ buildRule.executeTarget("testFile");
+ fail("Build exception expected: error on file URL");
+ } catch(BuildException ex) {
+ assertEquals(IsReachable.ERROR_NO_HOST_IN_URL, ex.getMessage());
+ }
}
+ @Test
public void testBadURL() throws Exception {
- expectBuildExceptionContaining("testBadURL",
- "error in URL",
- IsReachable.ERROR_BAD_URL);
+ try {
+ buildRule.executeTarget("testBadURL");
+ fail("Build exception expected: error in URL");
+ } catch(BuildException ex) {
+ AntAssert.assertContains(IsReachable.ERROR_BAD_URL, ex.getMessage());
+ }
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReferenceTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReferenceTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReferenceTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReferenceTest.java Fri Apr 18 21:00:38 2014
@@ -17,43 +17,55 @@
*/
package org.apache.tools.ant.taskdefs.condition;
-import org.apache.tools.ant.BuildFileTest;
+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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertNull;
/**
* Testcases for the <isreference> condition.
*
*/
-public class IsReferenceTest extends BuildFileTest {
+public class IsReferenceTest {
- public IsReferenceTest(String name) {
- super(name);
- }
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
- /**
- * The JUnit setup method
- */
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/taskdefs/conditions/isreference.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/conditions/isreference.xml");
}
+ @Test
public void testBasic() {
- expectPropertySet("basic", "global-path");
- assertPropertySet("target-path");
- assertPropertyUnset("undefined");
+ buildRule.executeTarget("basic");
+ assertEquals("true", buildRule.getProject().getProperty("global-path"));
+ assertEquals("true", buildRule.getProject().getProperty("target-path"));
+ assertNull(buildRule.getProject().getProperty("undefined"));
}
+ @Test
public void testNotEnoughArgs() {
- expectSpecificBuildException("isreference-incomplete",
- "refid attribute has been omitted",
- "No reference specified for isreference "
- + "condition");
+ try {
+ buildRule.executeTarget("isreference-incomplete");
+ fail("Build exception expected: refid attirbute has been omitted");
+ } catch(BuildException ex) {
+ assertEquals("No reference specified for isreference condition", ex.getMessage());
+ }
}
+ @Test
public void testType() {
- expectPropertySet("type", "global-path");
- assertPropertyUnset("global-path-as-fileset");
- assertPropertyUnset("global-path-as-foo");
- assertPropertySet("global-echo");
+ buildRule.executeTarget("type");
+ assertEquals("true", buildRule.getProject().getProperty("global-path"));
+ assertNull(buildRule.getProject().getProperty("global-path-as-fileset"));
+ assertNull(buildRule.getProject().getProperty("global-path-as-foo"));
+ assertEquals("true", buildRule.getProject().getProperty("global-echo"));
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsSignedTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsSignedTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsSignedTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsSignedTest.java Fri Apr 18 21:00:38 2014
@@ -18,31 +18,42 @@
package org.apache.tools.ant.taskdefs.condition;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
/**
* Testcase for the <issigned> condition.
*
*/
-public class IsSignedTest extends BuildFileTest {
+public class IsSignedTest {
- public IsSignedTest(String name) {
- super(name);
- }
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/taskdefs/conditions/issigned.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/conditions/issigned.xml");
}
+ @Test
public void testPass() {
- executeTarget("pass");
+ buildRule.executeTarget("pass");
}
+
+ @Test
public void testPassword() {
- executeTarget("password");
+ buildRule.executeTarget("password");
}
+
+ @Test
public void testAPassword() {
- executeTarget("apassword");
+ buildRule.executeTarget("apassword");
}
+
+ @Test
public void testAllSigned() {
- executeTarget("allsigned");
+ buildRule.executeTarget("allsigned");
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/ParserSupportsTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/ParserSupportsTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/ParserSupportsTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/ParserSupportsTest.java Fri Apr 18 21:00:38 2014
@@ -18,53 +18,78 @@
package org.apache.tools.ant.taskdefs.condition;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
*/
-public class ParserSupportsTest extends BuildFileTest {
+public class ParserSupportsTest {
- public ParserSupportsTest(String name) {
- super(name);
- }
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
- /**
- * The JUnit setup method
- */
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/taskdefs/conditions/parsersupports.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/conditions/parsersupports.xml");
}
- public void testEmpty() throws Exception {
- expectBuildExceptionContaining("testEmpty",
- ParserSupports.ERROR_NO_ATTRIBUTES,
- ParserSupports.ERROR_NO_ATTRIBUTES);
+ @Test
+ public void testEmpty() {
+ try {
+ buildRule.executeTarget("testEmpty");
+ fail("Build exception expected: " + ParserSupports.ERROR_NO_ATTRIBUTES);
+ } catch(BuildException ex) {
+ assertEquals(ParserSupports.ERROR_NO_ATTRIBUTES, ex.getMessage());
+ }
}
- public void testBoth() throws Exception {
- expectBuildExceptionContaining("testBoth",
- ParserSupports.ERROR_BOTH_ATTRIBUTES,
- ParserSupports.ERROR_BOTH_ATTRIBUTES);
+ @Test
+ public void testBoth() {
+ try {
+ buildRule.executeTarget("testBoth");
+ fail("Build exception expected: " + ParserSupports.ERROR_BOTH_ATTRIBUTES);
+ } catch(BuildException ex) {
+ assertEquals(ParserSupports.ERROR_BOTH_ATTRIBUTES, ex.getMessage());
+ }
}
- public void testNamespaces() throws Exception {
- executeTarget("testNamespaces");
+ @Test
+ public void testNamespaces() {
+ buildRule.executeTarget("testNamespaces");
}
- public void testPropertyNoValue() throws Exception {
- expectBuildExceptionContaining("testPropertyNoValue",
- ParserSupports.ERROR_NO_VALUE,
- ParserSupports.ERROR_NO_VALUE);
+ @Test
+ public void testPropertyNoValue() {
+ try {
+ buildRule.executeTarget("testPropertyNoValue");
+ fail("Build exception expected: " + ParserSupports.ERROR_NO_VALUE);
+ } catch(BuildException ex) {
+ assertEquals(ParserSupports.ERROR_NO_VALUE, ex.getMessage());
+ }
}
- public void testUnknownProperty() throws Exception {
- executeTarget("testUnknownProperty");
+ @Test
+ public void testUnknownProperty() {
+ buildRule.executeTarget("testUnknownProperty");
}
- public void NotestPropertyInvalid() throws Exception {
- executeTarget("testPropertyInvalid");
+
+ @Test
+ @Ignore("Previously named in a manner to prevent execution")
+ public void NotestPropertyInvalid() {
+ buildRule.executeTarget("testPropertyInvalid");
}
- public void NotestXercesProperty() throws Exception {
- executeTarget("testXercesProperty");
+
+ @Test
+ @Ignore("Previously named in a manner to prevent execution")
+ public void NotestXercesProperty() {
+ buildRule.executeTarget("testXercesProperty");
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/TypeFoundTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/TypeFoundTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/TypeFoundTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/TypeFoundTest.java Fri Apr 18 21:00:38 2014
@@ -17,50 +17,74 @@
*/
package org.apache.tools.ant.taskdefs.condition;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.AntAssert;
+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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertNull;
/**
* test the typeexists condition
*/
-public class TypeFoundTest extends BuildFileTest {
+public class TypeFoundTest {
- public TypeFoundTest(String name) {
- super(name);
- }
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
- /**
- * The JUnit setup method
- */
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/taskdefs/conditions/typefound.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/conditions/typefound.xml");
}
+ @Test
public void testTask() {
- expectPropertySet("testTask", "testTask");
+ buildRule.executeTarget("testTask");
+ assertEquals("true", buildRule.getProject().getProperty("testTask"));
}
+ @Test
public void testUndefined() {
- expectBuildExceptionContaining("testUndefined","left out the name attribute", "No type specified");
+ try {
+ buildRule.executeTarget("testUndefined");
+ fail("Build exception expected: left out the name attribute");
+ } catch(BuildException ex) {
+ AntAssert.assertContains("No type specified", ex.getMessage());
+ }
}
+ @Test
public void testTaskThatIsntDefined() {
- expectPropertyUnset("testTaskThatIsntDefined", "testTaskThatIsntDefined");
+ buildRule.executeTarget("testTaskThatIsntDefined");
+ assertNull(buildRule.getProject().getProperty("testTaskThatIsntDefined"));
}
+ @Test
public void testTaskThatDoesntReallyExist() {
- expectPropertyUnset("testTaskThatDoesntReallyExist", "testTaskThatDoesntReallyExist");
+ buildRule.executeTarget("testTaskThatDoesntReallyExist");
+ assertNull(buildRule.getProject().getProperty("testTaskThatDoesntReallyExist"));
}
+ @Test
public void testType() {
- expectPropertySet("testType", "testType");
+ buildRule.executeTarget("testType");
+ assertEquals("true", buildRule.getProject().getProperty("testType"));
}
+ @Test
public void testPreset() {
- expectPropertySet("testPreset", "testPreset");
+ buildRule.executeTarget("testPreset");
+ assertEquals("true", buildRule.getProject().getProperty("testPreset"));
}
+ @Test
public void testMacro() {
- expectPropertySet("testMacro", "testMacro");
+ buildRule.executeTarget("testMacro");
+ assertEquals("true", buildRule.getProject().getProperty("testMacro"));
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/XorTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/XorTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/XorTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/XorTest.java Fri Apr 18 21:00:38 2014
@@ -17,52 +17,59 @@
*/
package org.apache.tools.ant.taskdefs.condition;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
/**
* Test that Xor follows the conventional boolean logic semantics
* (a ^ b) === (a||b)&!(a&&b)
*/
-public class XorTest extends BuildFileTest {
+public class XorTest {
- public XorTest(String name) {
- super(name);
- }
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
- /**
- * The JUnit setup method
- */
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/taskdefs/conditions/xor.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/conditions/xor.xml");
}
+ @Test
public void testEmpty() {
- executeTarget("testEmpty");
+ buildRule.executeTarget("testEmpty");
}
+ @Test
public void test0() {
- executeTarget("test0");
+ buildRule.executeTarget("test0");
}
+ @Test
public void test1() {
- executeTarget("test1");
+ buildRule.executeTarget("test1");
}
+ @Test
public void test00() {
- executeTarget("test00");
+ buildRule.executeTarget("test00");
}
+ @Test
public void test10() {
- executeTarget("test10");
+ buildRule.executeTarget("test10");
}
+ @Test
public void test01() {
- executeTarget("test01");
+ buildRule.executeTarget("test01");
}
+ @Test
public void test11() {
- executeTarget("test11");
+ buildRule.executeTarget("test11");
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParserTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParserTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParserTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParserTest.java Fri Apr 18 21:00:38 2014
@@ -17,20 +17,23 @@
*/
package org.apache.tools.ant.taskdefs.cvslib;
-import junit.framework.TestCase;
+import org.junit.Test;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
import java.util.Date;
+import static org.junit.Assert.assertEquals;
+
/**
* Minimal test of the parser implementation
*/
-public class ChangeLogParserTest extends TestCase {
+public class ChangeLogParserTest {
protected ChangeLogParser parser = new ChangeLogParser();
+ @Test
public void testOldCvsFormat() throws Exception {
parser.stdout("Working file: build.xml");
parser.stdout("revision 1.475");
@@ -46,6 +49,7 @@ public class ChangeLogParserTest extends
assertEquals(date, entries[0].getDate());
}
+ @Test
public void testCvs112Format() throws Exception {
parser.stdout("Working file: build.xml");
parser.stdout("revision 1.475");
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriterTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriterTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriterTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriterTest.java Fri Apr 18 21:00:38 2014
@@ -17,8 +17,6 @@
*/
package org.apache.tools.ant.taskdefs.cvslib;
-import junit.framework.TestCase;
-
import java.util.Date;
import java.io.PrintWriter;
import java.io.OutputStreamWriter;
@@ -27,6 +25,7 @@ import java.io.ByteArrayInputStream;
import java.io.InputStream;
import org.apache.tools.ant.util.JAXPUtils;
+import org.junit.Test;
import org.xml.sax.XMLReader;
import org.xml.sax.InputSource;
import org.xml.sax.ContentHandler;
@@ -37,10 +36,11 @@ import org.xml.sax.Attributes;
/**
* Test for the cvslib ChangeLogWriter
*/
-public class ChangeLogWriterTest extends TestCase {
+public class ChangeLogWriterTest {
private ChangeLogWriter writer = new ChangeLogWriter();
+ @Test
public void testNonUTF8Characters() throws Exception {
CVSEntry entry = new CVSEntry(new Date(), "Se\u00f1orita", "2003 < 2004 && 3 > 5");
entry.addFile("Medicare & review.doc", "1.1");
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailAddressTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailAddressTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailAddressTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailAddressTest.java Fri Apr 18 21:00:38 2014
@@ -18,68 +18,77 @@
package org.apache.tools.ant.taskdefs.email;
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
/**
* @since Ant 1.6
*/
-public class EmailAddressTest extends TestCase {
-
- public EmailAddressTest(String name) {
- super(name);
- }
-
- public void setUp() {
- }
+public class EmailAddressTest {
+ @Test
public void test1() {
expectNameAddress( new EmailAddress("address (name)") );
}
+ @Test
public void test2() {
expectNameAddress( new EmailAddress("(name) address") );
}
+ @Test
public void test3() {
expectNameAddress( new EmailAddress("name <address>") );
}
+ @Test
public void test4() {
expectNameAddress( new EmailAddress("<address> name") );
}
+ @Test
public void test5() {
expectNameAddress( new EmailAddress("<address> (name)") );
}
+ @Test
public void test6() {
expectNameAddress( new EmailAddress("(name) <address>") );
}
+ @Test
public void test7() {
expectNameAddress2( new EmailAddress("address (<name>)") );
}
+ @Test
public void test8() {
expectNameAddress2( new EmailAddress("(<name>) address") );
}
+ @Test
public void test9() {
expectNameAddress3( new EmailAddress("address") );
}
+ @Test
public void testA() {
expectNameAddress3( new EmailAddress("<address>") );
}
+ @Test
public void testB() {
expectNameAddress3( new EmailAddress(" <address> ") );
}
+ @Test
public void testC() {
expectNameAddress3( new EmailAddress("< address >") );
}
+ @Test
public void testD() {
expectNameAddress3( new EmailAddress(" < address > ") );
}
@@ -97,8 +106,7 @@ public class EmailAddressTest extends Te
// where only an address is supplied
private void expectNameAddress3(EmailAddress e) {
- assertTrue( "Expected null, found <" + e.getName() + ">",
- e.getName() == null );
+ assertNull("Expected null, found <" + e.getName() + ">", e.getName());
assertEquals( "address", e.getAddress() );
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailTaskTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailTaskTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailTaskTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailTaskTest.java Fri Apr 18 21:00:38 2014
@@ -18,28 +18,46 @@
package org.apache.tools.ant.taskdefs.email;
-import org.apache.tools.ant.BuildFileTest;
+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 static org.junit.Assert.fail;
/**
* TODO : develop these testcases - the email task needs to have attributes allowing
* to simulate sending mail and to catch the output in text files or streams
*/
-public class EmailTaskTest extends BuildFileTest {
+public class EmailTaskTest {
- public EmailTaskTest(String name) {
- super(name);
- }
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/taskdefs/email/mail.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/email/mail.xml");
}
+ @Test
public void test1() {
- expectBuildException("test1", "SMTP auth only possible with MIME mail");
+ try {
+ buildRule.executeTarget("test1");
+ fail("Build exception expected: SMTP auth only possibly with MIME mail");
+ } catch(BuildException ex) {
+ //TODO assert exception message
+ }
}
+ @Test
public void test2() {
- expectBuildException("test2", "SSL only possible with MIME mail");
+ try {
+ buildRule.executeTarget("test2");
+ fail("Build exception expected: SSL only possibly with MIME mail");
+ } catch(BuildException ex) {
+ //TODO assert exception message
+ }
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/email/MessageTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/email/MessageTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/email/MessageTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/email/MessageTest.java Fri Apr 18 21:00:38 2014
@@ -23,18 +23,19 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
-import junit.framework.TestCase;
-
import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.FileUtils;
+import org.junit.After;
+import org.junit.Test;
-public class MessageTest extends TestCase {
- private File f = new File(System.getProperty("java.io.tmpdir"),
+public class MessageTest {
+ private static final File f = new File(System.getProperty("java.io.tmpdir"),
"message.txt");
/**
* test for bugzilla 48932
*/
- public void testPrintStreamDoesNotGetClosed() {
+ @Test
+ public void testPrintStreamDoesNotGetClosed() throws IOException {
Message ms = new Message();
Project p = new Project();
ms.setProject(p);
@@ -44,14 +45,13 @@ public class MessageTest extends TestCas
fis = new FileOutputStream(f);
ms.print(new PrintStream(fis));
fis.write(120);
- } catch (IOException ioe) {
- fail("we should not have issues writing after having called Message.print");
} finally {
FileUtils.close(fis);
}
}
+ @After
public void tearDown() {
if (f.exists()) {
FileUtils fu = FileUtils.getFileUtils();
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java Fri Apr 18 21:00:38 2014
@@ -18,8 +18,20 @@
package org.apache.tools.ant.taskdefs.optional;
-import java.io.*;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.FileUtilities;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FilenameFilter;
+
+import static org.apache.tools.ant.AntAssert.assertContains;
+import static org.apache.tools.ant.AntAssert.assertNotContains;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* If you want to run tests, it is highly recommended
@@ -32,70 +44,106 @@ import org.apache.tools.ant.BuildFileTes
* system classpath. (see ANTLR install.html)
*
*/
-public class ANTLRTest extends BuildFileTest {
+public class ANTLRTest {
private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/antlr/";
- public ANTLRTest(String name) {
- super(name);
- }
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+ @Before
public void setUp() {
- configureProject(TASKDEFS_DIR + "antlr.xml");
+ buildRule.configureProject(TASKDEFS_DIR + "antlr.xml");
}
+ @Test
public void test1() {
- expectBuildException("test1", "required argument, target, missing");
+ try {
+ buildRule.executeTarget("test1");
+ fail("required argument, target, missing");
+ } catch (BuildException ex) {
+ //TODO should check exception message
+ }
}
+ @Test
public void test2() {
- expectBuildException("test2", "Invalid output directory");
+ try {
+ buildRule.executeTarget("test2");
+ fail("Invalid output directory");
+ } catch (BuildException ex) {
+ //TODO should check exception message
+ }
}
+ @Test
public void test3() {
- executeTarget("test3");
+ buildRule.executeTarget("test3");
}
+ @Test
public void test4() {
- executeTarget("test4");
+ buildRule.executeTarget("test4");
}
+ @Test
public void test5() {
// should print "panic: Cannot find importVocab file 'JavaTokenTypes.txt'"
// since it needs to run java.g first before java.tree.g
- expectBuildException("test5", "ANTLR returned: 1");
+ try {
+ buildRule.executeTarget("test5");
+ fail("ANTLR returned: 1");
+ } catch (BuildException ex) {
+ //TODO should check exception message
+ }
}
+ @Test
public void test6() {
- executeTarget("test6");
+ buildRule.executeTarget("test6");
}
+ @Test
public void test7() {
- expectBuildException("test7", "Unable to determine generated class");
+ try {
+ buildRule.executeTarget("test7");
+ fail("Unable to determine generated class");
+ } catch (BuildException ex) {
+ //TODO should check exception message
+ }
}
/**
* This is a negative test for the super grammar (glib) option.
*/
+ @Test
public void test8() {
- expectBuildException("test8", "Invalid super grammar file");
+ try {
+ buildRule.executeTarget("test8");
+ fail("Invalid super grammar file");
+ } catch (BuildException ex) {
+ //TODO should check exception message
+ }
}
/**
* This is a positive test for the super grammar (glib) option. ANTLR
* will throw an error if everything is not correct.
*/
+ @Test
public void test9() {
- executeTarget("test9");
+ buildRule.executeTarget("test9");
}
/**
* This test creates an html-ized version of the calculator grammar.
* The sanity check is simply whether or not an html file was generated.
*/
+ @Test
public void test10() {
- executeTarget("test10");
- String[] calcFiles = getOutputDir().list(new HTMLFilter());
+ buildRule.executeTarget("test10");
+ File outputDirectory = new File(buildRule.getProject().getProperty("output"));
+ String[] calcFiles = outputDirectory.list(new HTMLFilter());
assertTrue(calcFiles.length > 0);
}
@@ -103,16 +151,18 @@ public class ANTLRTest extends BuildFile
* This is just a quick sanity check to run the diagnostic option and
* make sure that it doesn't throw any funny exceptions.
*/
+ @Test
public void test11() {
- executeTarget("test11");
+ buildRule.executeTarget("test11");
}
/**
* This is just a quick sanity check to run the trace option and
* make sure that it doesn't throw any funny exceptions.
*/
+ @Test
public void test12() {
- executeTarget("test12");
+ buildRule.executeTarget("test12");
}
/**
@@ -120,37 +170,43 @@ public class ANTLRTest extends BuildFile
* trace options (traceLexer, traceParser, and traceTreeWalker) to
* make sure that they don't throw any funny exceptions.
*/
+ @Test
public void test13() {
- executeTarget("test13");
+ buildRule.executeTarget("test13");
}
+ @Test
public void testNoRecompile() {
- executeTarget("test9");
- assertEquals(-1, getFullLog().indexOf("Skipped grammar file."));
- executeTarget("noRecompile");
- assertTrue(-1 != getFullLog().indexOf("Skipped grammar file."));
+ buildRule.executeTarget("test9");
+ assertNotContains("Skipped grammar file.", buildRule.getFullLog());
+ buildRule.executeTarget("noRecompile");
+ assertContains("Skipped grammar file.", buildRule.getFullLog());
}
+ @Test
public void testNormalRecompile() {
- executeTarget("test9");
- assertEquals(-1, getFullLog().indexOf("Skipped grammar file."));
- executeTarget("normalRecompile");
- assertEquals(-1, getFullLog().indexOf("Skipped grammar file."));
+ buildRule.executeTarget("test9");
+ assertNotContains("Skipped grammar file.", buildRule.getFullLog());
+
+ FileUtilities.rollbackTimetamps(buildRule.getOutputDir(), 5);
+
+ buildRule.executeTarget("normalRecompile");
+ assertNotContains("Skipped grammar file.", buildRule.getFullLog());
}
+ @Test
// Bugzilla Report 12961
public void testSupergrammarChangeRecompile() {
- executeTarget("test9");
- assertEquals(-1, getFullLog().indexOf("Skipped grammar file."));
- executeTarget("supergrammarChangeRecompile");
- assertEquals(-1, getFullLog().indexOf("Skipped grammar file."));
- }
-}
+ buildRule.executeTarget("test9");
+ assertNotContains("Skipped grammar file.", buildRule.getFullLog());
+
+ FileUtilities.rollbackTimetamps(buildRule.getOutputDir(), 5);
+
+ buildRule.executeTarget("supergrammarChangeRecompile");
+ assertNotContains("Skipped grammar file.", buildRule.getFullLog());
-class CalcFileFilter implements FilenameFilter {
- public boolean accept(File dir, String name) {
- return name.startsWith("Calc");
}
+
}
class HTMLFilter implements FilenameFilter {
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java Fri Apr 18 21:00:38 2014
@@ -18,14 +18,19 @@
package org.apache.tools.ant.taskdefs.optional;
+import static org.junit.Assert.assertEquals;
+
import java.io.File;
import java.io.FileNotFoundException;
import java.net.URL;
+
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-import junit.framework.TestCase;
+
import org.apache.tools.ant.taskdefs.XSLTLiaison;
import org.apache.tools.ant.util.FileUtils;
+import org.junit.Before;
+import org.junit.Test;
import org.w3c.dom.Document;
/**
@@ -34,17 +39,14 @@ import org.w3c.dom.Document;
*
* <a href="sbailliez@apache.org">Stephane Bailliez</a>
*/
-public abstract class AbstractXSLTLiaisonTest extends TestCase {
+public abstract class AbstractXSLTLiaisonTest {
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
protected XSLTLiaison liaison;
- protected AbstractXSLTLiaisonTest(String name){
- super(name);
- }
-
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
liaison = createLiaison();
}
@@ -61,6 +63,7 @@ public abstract class AbstractXSLTLiaiso
}
/** keep it simple stupid */
+ @Test
public void testTransform() throws Exception {
File xsl = getFile("/taskdefs/optional/xsltliaison-in.xsl");
liaison.setStylesheet(xsl);
@@ -75,6 +78,7 @@ public abstract class AbstractXSLTLiaiso
}
}
+ @Test
public void testEncoding() throws Exception {
File xsl = getFile("/taskdefs/optional/xsltliaison-encoding-in.xsl");
liaison.setStylesheet(xsl);
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/BeanShellScriptTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/BeanShellScriptTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/BeanShellScriptTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/BeanShellScriptTest.java Fri Apr 18 21:00:38 2014
@@ -17,28 +17,32 @@
*/
package org.apache.tools.ant.taskdefs.optional;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
/**
* Tests the examples of the <script> task docs.
*
* @since Ant 1.5.2
*/
-public class BeanShellScriptTest extends BuildFileTest {
+public class BeanShellScriptTest {
- public BeanShellScriptTest(String name) {
- super(name);
- }
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
- /**
- * The JUnit setup method
- */
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/taskdefs/optional/script.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/script.xml");
}
+ @Test
public void testCanLoad() {
- expectLog("useBeanshell", "I'm here");
+ buildRule.executeTarget("useBeanshell");
+ assertEquals("I'm here", buildRule.getLog());
}
}