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 [6/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/JarTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java Fri Apr 18 21:00:38 2014
@@ -28,29 +28,42 @@ import java.io.Reader;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
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.FileUtilities;
import org.apache.tools.ant.util.FileUtils;
+import org.junit.After;
+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.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
*/
-public class JarTest extends BuildFileTest {
-
- /** Utilities used for file operations */
- private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+public class JarTest {
+
+ @Rule
+ public final BuildFileRule buildRule = new BuildFileRule();
private static String tempJar = "tmp.jar";
private static String tempDir = "jartmp/";
private Reader r1, r2;
- public JarTest(String name) {
- super(name);
- }
-
+
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/taskdefs/jar.xml");
- executeTarget("setUp");
+ buildRule.configureProject("src/etc/testcases/taskdefs/jar.xml");
+ buildRule.executeTarget("setUp");
}
+ @After
public void tearDown() {
if (r1 != null) {
try {
@@ -64,152 +77,192 @@ public class JarTest extends BuildFileTe
} catch (IOException e) {
}
}
- try {
- super.tearDown();
- } catch (Exception exc) {
-
- }
}
+ @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", "manifest file does not exist");
+ try {
+ buildRule.executeTarget("test2");
+ fail("BuildException expected: manifest file does not exist");
+ } catch (BuildException ex) {
+ //TODO assert value
+ }
}
+ @Test
public void test3() {
- expectBuildException("test3", "Unrecognized whenempty attribute: format C: /y");
+ try {
+ buildRule.executeTarget("test3");
+ fail("BuildException expected: Unrecognized whenempty attribute: format C: /y");
+ } catch (BuildException ex) {
+ //TODO assert value
+ }
}
+ private File getOutputDir() {
+ return new File(buildRule.getProject().getProperty("output"));
+ }
+
+ @Test
public void test4() {
- executeTarget("test4");
+ buildRule.executeTarget("test4");
File jarFile = new File(getOutputDir(), tempJar);
+
assertTrue(jarFile.exists());
}
+ @Test
public void testNoRecreateWithoutUpdate() {
testNoRecreate("test4");
}
+ @Test
public void testNoRecreateWithUpdate() {
testNoRecreate("testNoRecreateWithUpdate");
}
private void testNoRecreate(String secondTarget) {
- executeTarget("test4");
+ buildRule.executeTarget("test4");
File jarFile = new File(getOutputDir(), tempJar);
+
+ // move the modified date back a couple of seconds rather than delay the test on each run
+ Assume.assumeTrue(jarFile.setLastModified(jarFile.lastModified()
+ - (FileUtils.getFileUtils().getFileTimestampGranularity() * 3)));
long jarModifiedDate = jarFile.lastModified();
- try {
- Thread.sleep(2500);
- } catch (InterruptedException e) {
- } // end of try-catch
- executeTarget(secondTarget);
+
+ buildRule.executeTarget(secondTarget);
assertEquals("jar has not been recreated in " + secondTarget,
jarModifiedDate, jarFile.lastModified());
}
+ @Test
public void testRecreateWithoutUpdateAdditionalFiles() {
testRecreate("test4", "testRecreateWithoutUpdateAdditionalFiles");
}
+ @Test
public void testRecreateWithUpdateAdditionalFiles() {
testRecreate("test4", "testRecreateWithUpdateAdditionalFiles");
}
+ @Test
public void testRecreateWithoutUpdateNewerFile() {
testRecreate("testRecreateNewerFileSetup",
"testRecreateWithoutUpdateNewerFile");
}
+ @Test
public void testRecreateWithUpdateNewerFile() {
testRecreate("testRecreateNewerFileSetup",
"testRecreateWithUpdateNewerFile");
}
private void testRecreate(String firstTarget, String secondTarget) {
- executeTarget(firstTarget);
- long sleeptime = 3000
- + FILE_UTILS.getFileTimestampGranularity();
- try {
- Thread.sleep(sleeptime);
- } catch (InterruptedException e) {
- } // end of try-catch
+ //Move the modified date on all input back a couple of seconds rather then delay the test to achieve a similar effect
+ FileUtilities.rollbackTimetamps(buildRule.getProject().getBaseDir(), 5);
+
+ buildRule.executeTarget(firstTarget);
File jarFile = new File(getOutputDir(), tempJar);
+
+ //Move the modified date back a couple of seconds rather then delay the test to achieve a similar effect
+ FileUtilities.rollbackTimetamps(buildRule.getOutputDir(), 5);
+
long jarModifiedDate = jarFile.lastModified();
- executeTarget(secondTarget);
+ buildRule.executeTarget(secondTarget);
jarFile = new File(getOutputDir(), tempJar);
assertTrue("jar has been recreated in " + secondTarget,
jarModifiedDate < jarFile.lastModified());
}
+ @Test
public void testManifestStaysIntact()
throws IOException, ManifestException {
- executeTarget("testManifestStaysIntact");
+ buildRule.executeTarget("testManifestStaysIntact");
r1 = new FileReader(new File(getOutputDir(),
tempDir + "manifest"));
r2 = new FileReader(new File(getOutputDir(),
tempDir + "META-INF/MANIFEST.MF"));
+
Manifest mf1 = new Manifest(r1);
Manifest mf2 = new Manifest(r2);
assertEquals(mf1, mf2);
}
+ @Test
public void testNoRecreateBasedirExcludesWithUpdate() {
testNoRecreate("testNoRecreateBasedirExcludesWithUpdate");
}
+ @Test
public void testNoRecreateBasedirExcludesWithoutUpdate() {
testNoRecreate("testNoRecreateBasedirExcludesWithoutUpdate");
}
+ @Test
public void testNoRecreateZipfilesetExcludesWithUpdate() {
testNoRecreate("testNoRecreateZipfilesetExcludesWithUpdate");
}
+ @Test
public void testNoRecreateZipfilesetExcludesWithoutUpdate() {
testNoRecreate("testNoRecreateZipfilesetExcludesWithoutUpdate");
}
+ @Test
public void testRecreateZipfilesetWithoutUpdateAdditionalFiles() {
testRecreate("test4",
"testRecreateZipfilesetWithoutUpdateAdditionalFiles");
}
+ @Test
public void testRecreateZipfilesetWithUpdateAdditionalFiles() {
testRecreate("test4",
"testRecreateZipfilesetWithUpdateAdditionalFiles");
}
+ @Test
public void testRecreateZipfilesetWithoutUpdateNewerFile() {
testRecreate("testRecreateNewerFileSetup",
"testRecreateZipfilesetWithoutUpdateNewerFile");
}
+ @Test
public void testRecreateZipfilesetWithUpdateNewerFile() {
testRecreate("testRecreateNewerFileSetup",
"testRecreateZipfilesetWithUpdateNewerFile");
}
+ @Test
public void testCreateWithEmptyFileset() {
- executeTarget("testCreateWithEmptyFilesetSetUp");
- executeTarget("testCreateWithEmptyFileset");
- executeTarget("testCreateWithEmptyFileset");
+ buildRule.executeTarget("testCreateWithEmptyFilesetSetUp");
+ buildRule.executeTarget("testCreateWithEmptyFileset");
+ buildRule.executeTarget("testCreateWithEmptyFileset");
}
+ @Test
public void testUpdateIfOnlyManifestHasChanged() {
- executeTarget("testUpdateIfOnlyManifestHasChanged");
+ buildRule.executeTarget("testUpdateIfOnlyManifestHasChanged");
File jarXml = new File(getOutputDir(), tempDir + "jar.xml");
assertTrue(jarXml.exists());
}
// bugzilla report 10262
+ @Test
public void testNoDuplicateIndex() throws IOException {
ZipFile archive = null;
try {
- executeTarget("testIndexTests");
+ buildRule.executeTarget("testIndexTests");
archive = new ZipFile(new File(getOutputDir(), tempJar));
Enumeration e = archive.entries();
int numberOfIndexLists = 0;
@@ -228,10 +281,11 @@ public class JarTest extends BuildFileTe
}
// bugzilla report 16972
+ @Test
public void testRootFilesInIndex() throws IOException {
ZipFile archive = null;
try {
- executeTarget("testIndexTests");
+ buildRule.executeTarget("testIndexTests");
archive = new ZipFile(new File(getOutputDir(), tempJar));
ZipEntry ze = archive.getEntry("META-INF/INDEX.LIST");
InputStream is = archive.getInputStream(ze);
@@ -262,46 +316,60 @@ public class JarTest extends BuildFileTe
}
}
}
+ @Test
public void testManifestOnlyJar() {
- expectLogContaining("testManifestOnlyJar", "Building MANIFEST-only jar: ");
+
+ buildRule.executeTarget("testManifestOnlyJar");
+ assertContains("Building MANIFEST-only jar: ", buildRule.getLog());
File manifestFile = new File(getOutputDir(), tempDir + "META-INF" + File.separator + "MANIFEST.MF");
assertTrue(manifestFile.exists());
}
+ @Test
public void testIndexJarsPlusJarMarker() {
- executeTarget("testIndexJarsPlusJarMarker");
+ buildRule.executeTarget("testIndexJarsPlusJarMarker");
}
+ @Test
public void testNoVersionInfoFail() {
- expectBuildExceptionContaining("testNoVersionInfoFail", "Manifest Implemention information missing.", "No Implementation-Title set.");
+ try {
+ buildRule.executeTarget("testNoVersionInfoFail");
+ fail("BuildException expected: Manifest Implemention information missing.");
+ } catch (BuildException ex) {
+ assertContains("No Implementation-Title set.", ex.getMessage());
+ }
}
+ @Test
public void testNoVersionInfoIgnore() {
- executeTarget("testNoVersionInfoIgnore");
- assertTrue( getFullLog().indexOf("No Implementation-Title set.") > -1 );
- assertTrue( getFullLog().indexOf("No Implementation-Version set.") > -1 );
- assertTrue( getFullLog().indexOf("No Implementation-Vendor set.") > -1 );
+ buildRule.executeTarget("testNoVersionInfoIgnore");
+ assertTrue(buildRule.getFullLog().indexOf("No Implementation-Title set.") > -1 );
+ assertTrue(buildRule.getFullLog().indexOf("No Implementation-Version set.") > -1 );
+ assertTrue(buildRule.getFullLog().indexOf("No Implementation-Vendor set.") > -1 );
}
+ @Test
public void testNoVersionInfoWarn() {
- executeTarget("testNoVersionInfoWarn");
- assertTrue( getLog().indexOf("No Implementation-Title set.") > -1 );
- assertTrue( getLog().indexOf("No Implementation-Version set.") > -1 );
- assertTrue( getLog().indexOf("No Implementation-Vendor set.") > -1 );
+ buildRule.executeTarget("testNoVersionInfoWarn");
+ assertTrue(buildRule.getLog().indexOf("No Implementation-Title set.") > -1 );
+ assertTrue(buildRule.getLog().indexOf("No Implementation-Version set.") > -1 );
+ assertTrue(buildRule.getLog().indexOf("No Implementation-Vendor set.") > -1 );
}
+ @Test
public void testNoVersionInfoNoStrict() {
- executeTarget("testNoVersionInfoNoStrict");
- assertFalse( getLog().indexOf("No Implementation-Title set.") > -1 );
- assertFalse( getLog().indexOf("No Implementation-Version set.") > -1 );
- assertFalse( getLog().indexOf("No Implementation-Vendor set.") > -1 );
+ buildRule.executeTarget("testNoVersionInfoNoStrict");
+ assertFalse(buildRule.getLog().indexOf("No Implementation-Title set.") > -1 );
+ assertFalse(buildRule.getLog().indexOf("No Implementation-Version set.") > -1 );
+ assertFalse(buildRule.getLog().indexOf("No Implementation-Vendor set.") > -1 );
}
+ @Test
public void testHasVersionInfo() {
- executeTarget("testHasVersionInfo");
- assertFalse( getLog().indexOf("No Implementation-Title set.") > -1 );
- assertFalse( getLog().indexOf("No Implementation-Version set.") > -1 );
- assertFalse( getLog().indexOf("No Implementation-Vendor set.") > -1 );
+ buildRule.executeTarget("testHasVersionInfo");
+ assertFalse(buildRule.getLog().indexOf("No Implementation-Title set.") > -1 );
+ assertFalse(buildRule.getLog().indexOf("No Implementation-Version set.") > -1 );
+ assertFalse(buildRule.getLog().indexOf("No Implementation-Vendor set.") > -1 );
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java Fri Apr 18 21:00:38 2014
@@ -29,15 +29,29 @@ import java.io.OutputStreamWriter;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.input.DefaultInputHandler;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.TeeOutputStream;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.internal.AssumptionViolatedException;
+
+import static org.apache.tools.ant.AntAssert.assertContains;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* stress out java task
* */
-public class JavaTest extends BuildFileTest {
+public class JavaTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
private static final int TIME_TO_WAIT = 1;
// wait 1 second extra to allow for java to start ...
@@ -49,18 +63,16 @@ public class JavaTest extends BuildFileT
private boolean runFatalTests=false;
- public JavaTest(String name) {
- super(name);
- }
/**
* configure the project.
* if the property junit.run.fatal.tests is set we run
* the fatal tests
*/
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/taskdefs/java.xml");
- project.executeTarget("setUp");
+ buildRule.configureProject("src/etc/testcases/taskdefs/java.xml");
+ buildRule.executeTarget("setUp");
//final String propname="tests-classpath.value";
//String testClasspath=System.getProperty(propname);
@@ -70,32 +82,49 @@ public class JavaTest extends BuildFileT
runFatalTests=true;
}
+ @Test
public void testNoJarNoClassname(){
- expectBuildExceptionContaining("testNoJarNoClassname",
- "parameter validation",
- "Classname must not be null.");
+ try {
+ buildRule.executeTarget("testNoJarNoClassname");
+ fail("Build exception should have been thrown - parameter validation");
+ } catch (BuildException ex) {
+ assertContains("Classname must not be null.", ex.getMessage());
+ }
}
+ @Test
public void testJarNoFork() {
- expectBuildExceptionContaining("testJarNoFork",
- "parameter validation",
- "Cannot execute a jar in non-forked mode. "
- + "Please set fork='true'. ");
+ try {
+ buildRule.executeTarget("testJarNoFork");
+ fail("Build exception should have been thrown - parameter validation");
+ } catch (BuildException ex) {
+ assertContains("Cannot execute a jar in non-forked mode. Please set fork='true'. ", ex.getMessage());
+ }
}
+ @Test
public void testJarAndClassName() {
- expectBuildException("testJarAndClassName",
- "Should not be able to set both classname AND jar");
+ try {
+ buildRule.executeTarget("testJarAndClassName");
+ fail("Build exception should have been thrown - both classname and JAR are not allowed");
+ } catch (BuildException ex) {
+ assertEquals("Cannot use 'jar' and 'classname' attributes in same command", ex.getMessage());
+ }
}
-
+ @Test
public void testClassnameAndJar() {
- expectBuildException("testClassnameAndJar",
- "Should not be able to set both classname AND jar");
+ try {
+ buildRule.executeTarget("testClassnameAndJar");
+ fail("Build exception should have been thrown - both classname and JAR are not allowed");
+ } catch (BuildException ex) {
+ assertEquals("Cannot use 'jar' and 'classname' attributes in same command.", ex.getMessage());
+ }
}
+ @Test
public void testRun() {
- executeTarget("testRun");
+ buildRule.executeTarget("testRun");
}
@@ -103,90 +132,117 @@ public class JavaTest extends BuildFileT
/** this test fails but we ignore the return value;
* we verify that failure only matters when failonerror is set
*/
+ @Test
public void testRunFail() {
- if(runFatalTests) {
- executeTarget("testRunFail");
- }
+ Assume.assumeTrue("Fatal tests have not been set to run", runFatalTests);
+ buildRule.executeTarget("testRunFail");
}
+ @Test
public void testRunFailFoe() {
- if(runFatalTests) {
- expectBuildExceptionContaining("testRunFailFoe",
- "java failures being propagated",
- "Java returned:");
+ Assume.assumeTrue("Fatal tests have not been set to run", runFatalTests);
+ try {
+ buildRule.executeTarget("testRunFailFoe");
+ fail("Build exception should have been thrown - " + "java failures being propagated");
+ } catch (BuildException ex) {
+ assertContains("Java returned:", ex.getMessage());
}
-}
+ }
+ @Test
public void testRunFailFoeFork() {
- expectBuildExceptionContaining("testRunFailFoeFork",
- "java failures being propagated",
- "Java returned:");
+ try {
+ buildRule.executeTarget("testRunFailFoeFork");
+ fail("Build exception should have been thrown - " + "java failures being propagated");
+ } catch (BuildException ex) {
+ assertContains("Java returned:", ex.getMessage());
+ }
}
+ @Test
public void testExcepting() {
- expectLogContaining("testExcepting",
- "Exception raised inside called program");
+ buildRule.executeTarget("testExcepting");
+ assertContains("Exception raised inside called program", buildRule.getLog());
}
+ @Test
public void testExceptingFork() {
- expectLogContaining("testExceptingFork",
- "Java Result:");
+ buildRule.executeTarget("testExceptingFork");
+ assertContains("Java Result:", buildRule.getLog());
}
+ @Test
public void testExceptingFoe() {
- expectBuildExceptionContaining("testExceptingFoe",
- "passes exception through",
- "Exception raised inside called program");
+ try {
+ buildRule.executeTarget("testExceptingFoe");
+ fail("Build exception should have been thrown - " + "passes exception through");
+ } catch (BuildException ex) {
+ assertContains("Exception raised inside called program", ex.getMessage());
+ }
}
+ @Test
public void testExceptingFoeFork() {
- expectBuildExceptionContaining("testExceptingFoeFork",
- "exceptions turned into error codes",
- "Java returned:");
+ try {
+ buildRule.executeTarget("testExceptingFoeFork");
+ fail("Build exception should have been thrown - " + "exceptions turned into error codes");
+ } catch (BuildException ex) {
+ assertContains("Java returned:", ex.getMessage());
+ }
}
+ @Test
public void testResultPropertyZero() {
- executeTarget("testResultPropertyZero");
- assertEquals("0",project.getProperty("exitcode"));
+ buildRule.executeTarget("testResultPropertyZero");
+ assertEquals("0", buildRule.getProject().getProperty("exitcode"));
}
+ @Test
public void testResultPropertyNonZero() {
- executeTarget("testResultPropertyNonZero");
- assertEquals("2",project.getProperty("exitcode"));
+ buildRule.executeTarget("testResultPropertyNonZero");
+ assertEquals("2", buildRule.getProject().getProperty("exitcode"));
}
+ @Test
public void testResultPropertyZeroNoFork() {
- executeTarget("testResultPropertyZeroNoFork");
- assertEquals("0",project.getProperty("exitcode"));
+ buildRule.executeTarget("testResultPropertyZeroNoFork");
+ assertEquals("0", buildRule.getProject().getProperty("exitcode"));
}
+ @Test
public void testResultPropertyNonZeroNoFork() {
- executeTarget("testResultPropertyNonZeroNoFork");
- assertEquals("-1",project.getProperty("exitcode"));
+ buildRule.executeTarget("testResultPropertyNonZeroNoFork");
+ assertEquals("-1", buildRule.getProject().getProperty("exitcode"));
}
+ @Test
public void testRunFailWithFailOnError() {
- expectBuildExceptionContaining("testRunFailWithFailOnError",
- "non zero return code",
- "Java returned:");
+ try {
+ buildRule.executeTarget("testRunFailWithFailOnError");
+ fail("Build exception should have been thrown - " + "non zero return code");
+ } catch (BuildException ex) {
+ assertContains("Java returned:", ex.getMessage());
+ }
}
+ @Test
public void testRunSuccessWithFailOnError() {
- executeTarget("testRunSuccessWithFailOnError");
+ buildRule.executeTarget("testRunSuccessWithFailOnError");
}
- public void testSpawn() {
- File logFile = FILE_UTILS.createTempFile("spawn","log", getOutputDir(), false, false);
+ @Test
+ public void testSpawn() throws InterruptedException {
+ File logFile = FILE_UTILS.createTempFile("spawn", "log",
+ new File(buildRule.getProject().getProperty("output")), false, false);
// this is guaranteed by FileUtils#createTempFile
assertTrue("log file not existing", !logFile.exists());
- project.setProperty("logFile", logFile.getAbsolutePath());
- project.setProperty("timeToWait", Long.toString(TIME_TO_WAIT));
- project.executeTarget("testSpawn");
- try {
- Thread.sleep(TIME_TO_WAIT * 1000 + SECURITY_MARGIN);
- } catch (Exception ex) {
- System.out.println("my sleep was interrupted");
- }
+ buildRule.getProject().setProperty("logFile", logFile.getAbsolutePath());
+ buildRule.getProject().setProperty("timeToWait", Long.toString(TIME_TO_WAIT));
+ buildRule.getProject().executeTarget("testSpawn");
+
+ Thread.sleep(TIME_TO_WAIT * 1000 + SECURITY_MARGIN);
+
+
// let's be nice with the next generation of developers
if (!logFile.exists()) {
System.out.println("suggestion: increase the constant"
@@ -195,38 +251,44 @@ public class JavaTest extends BuildFileT
assertTrue("log file exists", logFile.exists());
}
+ @Test
public void testRedirect1() {
- executeTarget("redirect1");
+ buildRule.executeTarget("redirect1");
}
+ @Test
public void testRedirect2() {
- executeTarget("redirect2");
+ buildRule.executeTarget("redirect2");
}
+ @Test
public void testRedirect3() {
- executeTarget("redirect3");
+ buildRule.executeTarget("redirect3");
}
+ @Test
public void testRedirector1() {
- executeTarget("redirector1");
+ buildRule.executeTarget("redirector1");
}
+ @Test
public void testRedirector2() {
- executeTarget("redirector2");
+ buildRule.executeTarget("redirector2");
}
+ @Test
public void testReleasedInput() throws Exception {
PipedOutputStream out = new PipedOutputStream();
final PipedInputStream in = new PipedInputStream(out);
- project.setInputHandler(new DefaultInputHandler() {
+ buildRule.getProject().setInputHandler(new DefaultInputHandler() {
protected InputStream getInputStream() {
return in;
}
});
- project.setDefaultInputStream(in);
+ buildRule.getProject().setDefaultInputStream(in);
Java java = new Java();
- java.setProject(project);
+ java.setProject(buildRule.getProject());
java.setClassname("org.apache.tools.ant.Main");
java.setArgs("-version");
java.setFork(true);
@@ -237,7 +299,7 @@ public class JavaTest extends BuildFileT
Thread inputThread = new Thread(new Runnable() {
public void run() {
Input input = new Input();
- input.setProject(project);
+ input.setProject(buildRule.getProject());
input.setAddproperty("input.value");
input.execute();
}
@@ -259,18 +321,19 @@ public class JavaTest extends BuildFileT
inputThread.join(2000);
- assertEquals("foo", project.getProperty("input.value"));
+ assertEquals("foo", buildRule.getProject().getProperty("input.value"));
}
+ @Test
public void testFlushedInput() throws Exception {
final PipedOutputStream out = new PipedOutputStream();
final PipedInputStream in = new PipedInputStream(out);
- project.setInputHandler(new DefaultInputHandler() {
+ buildRule.getProject().setInputHandler(new DefaultInputHandler() {
protected InputStream getInputStream() {
return in;
}
});
- project.setDefaultInputStream(in);
+ buildRule.getProject().setDefaultInputStream(in);
final boolean[] timeout = new boolean[1];
timeout[0] = false;
@@ -281,7 +344,7 @@ public class JavaTest extends BuildFileT
// wait a little bit to have the target executed
Thread.sleep(500);
} catch (InterruptedException e) {
- // don't care
+ throw new AssumptionViolatedException("Thread interrupted", e);
}
try {
out.write("foo-FlushedInput\n".getBytes());
@@ -293,7 +356,7 @@ public class JavaTest extends BuildFileT
writingThread.setDaemon(true);
writingThread.start();
- executeTarget("flushedInput");
+ buildRule.executeTarget("flushedInput");
}
/**
@@ -348,7 +411,7 @@ public class JavaTest extends BuildFileT
* test class for spawn
*/
public static class SpawnEntryPoint {
- public static void main(String [] argv) {
+ public static void main(String [] argv) throws InterruptedException {
int sleepTime = 10;
String logFile = "spawn.log";
if (argv.length >= 1) {
@@ -359,11 +422,7 @@ public class JavaTest extends BuildFileT
logFile = argv[1];
}
OutputStreamWriter out = null;
- try {
- Thread.sleep(sleepTime * 1000);
- } catch (InterruptedException ex) {
- System.out.println("my sleep was interrupted");
- }
+ Thread.sleep(sleepTime * 1000);
try {
File dest = new File(logFile);
@@ -386,7 +445,7 @@ public class JavaTest extends BuildFileT
/**
* pipe input to specified output
*/
- public static void main(String[] args) {
+ public static void main(String[] args) throws InterruptedException {
OutputStream os = null;
if (args.length > 0) {
if ("out".equalsIgnoreCase(args[0])) {
@@ -401,10 +460,7 @@ public class JavaTest extends BuildFileT
Thread t = new Thread(new StreamPumper(System.in, os, true));
t.setName("PipeEntryPoint " + args[0]);
t.start();
- try {
- t.join();
- } catch (InterruptedException eyeEx) {
- }
+ t.join();
}
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java Fri Apr 18 21:00:38 2014
@@ -18,35 +18,31 @@
package org.apache.tools.ant.taskdefs;
-import java.io.File;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-
-import junit.framework.TestCase;
-
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter;
import org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory;
import org.apache.tools.ant.taskdefs.compilers.Javac13;
import org.apache.tools.ant.taskdefs.compilers.JavacExternal;
-import org.apache.tools.ant.types.Path;
+
+import org.junit.Before;
+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.assertNull;
+import static org.junit.Assert.assertTrue;
/**
* Testcase for <javac>.
*
*/
-public class JavacTest extends TestCase {
+public class JavacTest {
private Project project;
private Javac javac;
- public JavacTest(String name) {
- super(name);
- }
-
+ @Before
public void setUp() {
project = new Project();
project.init();
@@ -57,6 +53,7 @@ public class JavacTest extends TestCase
/**
* Test setting the name of the javac executable.
*/
+ @Test
public void testForkedExecutableName() {
assertNull("no fork means no executable", javac.getJavacExecutable());
@@ -65,14 +62,13 @@ public class JavacTest extends TestCase
javac.setFork(true);
assertNotNull("normal fork", javac.getJavacExecutable());
- assertTrue("name should contain \"javac\"",
- javac.getJavacExecutable().indexOf("javac") > -1);
+ assertContains("name should contain \"javac\"", "javac",
+ javac.getJavacExecutable());
project.setProperty("build.compiler", "extJavac");
javac.setFork(false);
assertNotNull("fork via property", javac.getJavacExecutable());
- assertTrue("name should contain \"javac\"",
- javac.getJavacExecutable().indexOf("javac") > -1);
+ assertContains("name should contain \"javac\"", "javac", javac.getJavacExecutable());
project.setProperty("build.compiler", "whatever");
assertNull("no fork and not extJavac means no executable",
@@ -87,6 +83,7 @@ public class JavacTest extends TestCase
/**
* Test nested compiler args.
*/
+ @Test
public void testCompilerArg() {
String[] args = javac.getCurrentCompilerArgs();
assertNotNull(args);
@@ -129,6 +126,7 @@ public class JavacTest extends TestCase
* Test nested compiler args in the fork="true" and
* implementation="extJavac" case.
*/
+ @Test
public void testCompilerArgForForkAndExtJavac() {
Javac.ImplementationSpecificArgument arg = javac.createCompilerArg();
String ford = "Ford";
@@ -145,6 +143,7 @@ public class JavacTest extends TestCase
/**
* Test compiler attribute.
*/
+ @Test
public void testCompilerAttribute() {
// check defaults
String compiler = javac.getCompiler();
@@ -194,6 +193,7 @@ public class JavacTest extends TestCase
assertEquals("jvc", compiler);
}
+ @Test
public void testCompilerAdapter() {
javac.setCompiler("javac1.4");
@@ -209,30 +209,36 @@ public class JavacTest extends TestCase
assertTrue(adapter instanceof JavacExternal);
}
+ @Test
public void testSourceNoDefault() {
assertNull(javac.getSource());
}
+ @Test
public void testSourceWithDefault() {
project.setNewProperty("ant.build.javac.source", "1.4");
assertEquals("1.4", javac.getSource());
}
+ @Test
public void testSourceOverridesDefault() {
project.setNewProperty("ant.build.javac.source", "1.4");
javac.setSource("1.5");
assertEquals("1.5", javac.getSource());
}
+ @Test
public void testTargetNoDefault() {
assertNull(javac.getTarget());
}
+ @Test
public void testTargetWithDefault() {
project.setNewProperty("ant.build.javac.target", "1.4");
assertEquals("1.4", javac.getTarget());
}
+ @Test
public void testTargetOverridesDefault() {
project.setNewProperty("ant.build.javac.target", "1.4");
javac.setTarget("1.5");
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JavadocTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JavadocTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JavadocTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JavadocTest.java Fri Apr 18 21:00:38 2014
@@ -18,122 +18,115 @@
package org.apache.tools.ant.taskdefs;
-import org.apache.tools.ant.BuildException;
-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 JavadocTest extends BuildFileTest {
+public class JavadocTest {
- public JavadocTest(String name) {
- super(name);
- }
+ @Rule
+ public final BuildFileRule buildRule = new BuildFileRule();
private static final String BUILD_PATH = "src/etc/testcases/taskdefs/javadoc/";
private static final String BUILD_FILENAME = "javadoc.xml";
private static final String BUILD_FILE = BUILD_PATH + BUILD_FILENAME;
- protected void setUp() throws Exception {
- super.setUp();
- configureProject(BUILD_FILE);
+ @Before
+ public void setUp() {
+ buildRule.configureProject(BUILD_FILE);
}
// PR 38370
- public void testDirsetPath() throws Exception {
- executeTarget("dirsetPath");
+ @Test
+ public void testDirsetPath() {
+ buildRule.executeTarget("dirsetPath");
}
// PR 38370
- public void testDirsetPathWithoutPackagenames() throws Exception {
- try {
- executeTarget("dirsetPathWithoutPackagenames");
- } catch (BuildException e) {
- fail("Contents of path should be picked up without specifying package names: " + e);
- }
+ @Test
+ public void testDirsetPathWithoutPackagenames() {
+ buildRule.executeTarget("dirsetPathWithoutPackagenames");
}
// PR 38370
- public void testNestedDirsetPath() throws Exception {
- executeTarget("nestedDirsetPath");
+ @Test
+ public void testNestedDirsetPath() {
+ buildRule.executeTarget("nestedDirsetPath");
}
// PR 38370
- public void testFilesetPath() throws Exception {
- try {
- executeTarget("filesetPath");
- } catch (BuildException e) {
- fail("A path can contain filesets: " + e);
- }
+ @Test
+ public void testFilesetPath() {
+ buildRule.executeTarget("filesetPath");
}
// PR 38370
- public void testNestedFilesetPath() throws Exception {
- try {
- executeTarget("nestedFilesetPath");
- } catch (BuildException e) {
- fail("A path can contain nested filesets: " + e);
- }
+ @Test
+ public void testNestedFilesetPath() {
+ buildRule.executeTarget("nestedFilesetPath");
}
// PR 38370
- public void testFilelistPath() throws Exception {
- try {
- executeTarget("filelistPath");
- } catch (BuildException e) {
- fail("A path can contain filelists: " + e);
- }
+ @Test
+ public void testFilelistPath() {
+ buildRule.executeTarget("filelistPath");
}
// PR 38370
- public void testNestedFilelistPath() throws Exception {
- try {
- executeTarget("nestedFilelistPath");
- } catch (BuildException e) {
- fail("A path can contain nested filelists: " + e);
- }
+ @Test
+ public void testNestedFilelistPath() {
+ buildRule.executeTarget("nestedFilelistPath");
}
// PR 38370
- public void testPathelementPath() throws Exception {
- executeTarget("pathelementPath");
+ @Test
+ public void testPathelementPath() {
+ buildRule.executeTarget("pathelementPath");
}
// PR 38370
- public void testPathelementLocationPath() throws Exception {
- try {
- executeTarget("pathelementLocationPath");
- } catch (BuildException e) {
- fail("A path can contain pathelements pointing to a file: " + e);
- }
+ @Test
+ public void testPathelementLocationPath() {
+ buildRule.executeTarget("pathelementLocationPath");
}
// PR 38370
- public void testNestedSource() throws Exception {
- executeTarget("nestedSource");
+ @Test
+ public void testNestedSource() {
+ buildRule.executeTarget("nestedSource");
}
// PR 38370
- public void testNestedFilesetRef() throws Exception {
- executeTarget("nestedFilesetRef");
+ @Test
+ public void testNestedFilesetRef() {
+ buildRule.executeTarget("nestedFilesetRef");
}
// PR 38370
- public void testNestedFilesetRefInPath() throws Exception {
- executeTarget("nestedFilesetRefInPath");
+ @Test
+ public void testNestedFilesetRefInPath() {
+ buildRule.executeTarget("nestedFilesetRefInPath");
}
- public void testNestedFilesetNoPatterns() throws Exception {
- executeTarget("nestedFilesetNoPatterns");
+ @Test
+ public void testNestedFilesetNoPatterns() {
+ buildRule.executeTarget("nestedFilesetNoPatterns");
}
- public void testDoublyNestedFileset() throws Exception {
- executeTarget("doublyNestedFileset");
+ @Test
+ public void testDoublyNestedFileset() {
+ buildRule.executeTarget("doublyNestedFileset");
}
- public void testDoublyNestedFilesetNoPatterns() throws Exception {
- executeTarget("doublyNestedFilesetNoPatterns");
+ @Test
+ public void testDoublyNestedFilesetNoPatterns() {
+ buildRule.executeTarget("doublyNestedFilesetNoPatterns");
}
- public void testNonJavaIncludes() throws Exception { // #41264
- executeTarget("nonJavaIncludes");
+ @Test
+ public void testNonJavaIncludes() { // #41264
+ buildRule.executeTarget("nonJavaIncludes");
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/LoadFileTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/LoadFileTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/LoadFileTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/LoadFileTest.java Fri Apr 18 21:00:38 2014
@@ -18,83 +18,99 @@
package org.apache.tools.ant.taskdefs;
import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.After;
+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.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
/**
* Test the load file task
- *
- * @created 10 December 2001
*/
-public class LoadFileTest extends BuildFileTest {
-
- /**
- * Constructor for the LoadFileTest object
- *
- * @param name Description of Parameter
- */
- public LoadFileTest(String name) {
- super(name);
- }
+public class LoadFileTest {
+ @Rule
+ public final BuildFileRule buildRule = new BuildFileRule();
+
- /**
- * The JUnit setup method
- */
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/taskdefs/loadfile.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/loadfile.xml");
}
- /**
- * The teardown method for JUnit
- */
+ @After
public void tearDown() {
- executeTarget("cleanup");
+ buildRule.executeTarget("cleanup");
}
/**
* A unit test for JUnit
*/
+ @Test
public void testNoSourcefileDefined() {
- expectBuildException("testNoSourcefileDefined",
- "source file not defined");
+ try {
+ buildRule.executeTarget("testNoSourcefileDefined");
+ fail("BuildException expected: source file not defined");
+ } catch (BuildException ex) {
+ //TODO assert value
+ }
}
/**
* A unit test for JUnit
*/
+ @Test
public void testNoPropertyDefined() {
- expectBuildException("testNoPropertyDefined",
- "output property not defined");
+ try {
+ buildRule.executeTarget("testNoPropertyDefined");
+ fail("BuildException expected: output property not defined");
+ } catch (BuildException ex) {
+ //TODO assert value
+ }
}
/**
* A unit test for JUnit
*/
+ @Test
public void testNoSourcefilefound() {
- expectBuildExceptionContaining("testNoSourcefilefound",
- "File not found", " doesn't exist");
+ try {
+ buildRule.executeTarget("testNoSourcefilefound");
+ fail("BuildException expected: File not found");
+ } catch (BuildException ex) {
+ assertContains(" doesn't exist", ex.getMessage());
+ }
}
/**
* A unit test for JUnit
*/
+ @Test
public void testFailOnError()
throws BuildException {
- expectPropertyUnset("testFailOnError","testFailOnError");
+ buildRule.executeTarget("testFailOnError");
+ assertNull(buildRule.getProject().getProperty("testFailOnError"));
}
/**
* A unit test for JUnit
*/
+ @Test
public void testLoadAFile()
throws BuildException {
- executeTarget("testLoadAFile");
- if(project.getProperty("testLoadAFile").indexOf("eh?")<0) {
+ buildRule.executeTarget("testLoadAFile");
+ if(buildRule.getProject().getProperty("testLoadAFile").indexOf("eh?")<0) {
fail("property is not all in the file");
}
}
@@ -103,21 +119,21 @@ public class LoadFileTest extends BuildF
/**
* A unit test for JUnit
*/
+ @Test
public void testLoadAFileEnc()
throws BuildException {
- executeTarget("testLoadAFileEnc");
- if(project.getProperty("testLoadAFileEnc")==null) {
- fail("file load failed");
- }
+ buildRule.executeTarget("testLoadAFileEnc");
+ assertNotNull("file load files", buildRule.getProject().getProperty("testLoadAFileEnc"));
}
/**
* A unit test for JUnit
*/
+ @Test
public void testEvalProps()
throws BuildException {
- executeTarget("testEvalProps");
- if(project.getProperty("testEvalProps").indexOf("rain")<0) {
+ buildRule.executeTarget("testEvalProps");
+ if(buildRule.getProject().getProperty("testEvalProps").indexOf("rain")<0) {
fail("property eval broken");
}
}
@@ -125,10 +141,11 @@ public class LoadFileTest extends BuildF
/**
* Test FilterChain and FilterReaders
*/
+ @Test
public void testFilterChain()
throws BuildException {
- executeTarget("testFilterChain");
- if(project.getProperty("testFilterChain").indexOf("World!")<0) {
+ buildRule.executeTarget("testFilterChain");
+ if(buildRule.getProject().getProperty("testFilterChain").indexOf("World!")<0) {
fail("Filter Chain broken");
}
}
@@ -136,20 +153,18 @@ public class LoadFileTest extends BuildF
/**
* Test StripJavaComments filterreader functionality.
*/
+ @Test
public final void testStripJavaComments()
throws BuildException {
- executeTarget("testStripJavaComments");
- final String expected = project.getProperty("expected");
- final String generated = project.getProperty("testStripJavaComments");
+ buildRule.executeTarget("testStripJavaComments");
+ final String expected = buildRule.getProject().getProperty("expected");
+ final String generated = buildRule.getProject().getProperty("testStripJavaComments");
assertEquals(expected, generated);
}
- /**
- * A unit test for JUnit
- */
- public void testOneLine()
- throws BuildException {
- expectPropertySet("testOneLine","testOneLine","1,2,3,4");
-
+ @Test
+ public void testOneLine() {
+ buildRule.executeTarget("testOneLine");
+ assertEquals("1,2,3,4", buildRule.getProject().getProperty("testOneLine"));
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/MacroDefTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/MacroDefTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/MacroDefTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/MacroDefTest.java Fri Apr 18 21:00:38 2014
@@ -19,124 +19,167 @@
package org.apache.tools.ant.taskdefs;
import org.apache.tools.ant.BuildException;
-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.apache.tools.ant.AntAssert.assertContains;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
*/
-public class MacroDefTest extends BuildFileTest {
- public MacroDefTest(String name) {
- super(name);
- }
+public class MacroDefTest {
+
+ @Rule
+ public final BuildFileRule buildRule = new BuildFileRule();
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/taskdefs/macrodef.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/macrodef.xml");
}
+ @Test
public void testSimple() {
- expectLog("simple", "Hello World");
+ buildRule.executeTarget("simple");
+ assertEquals("Hello World", buildRule.getLog());
}
+ @Test
public void testText() {
- expectLog("text", "Inner Text");
+ buildRule.executeTarget("text");
+ assertEquals("Inner Text", buildRule.getLog());
}
+ @Test
public void testDuplicateAttribute() {
- expectBuildException(
- "duplicate.attribute",
- "the attribute text has already been specified");
+ try {
+ buildRule.executeTarget("duplicate.attribute");
+ fail("BuildException expected: the attribute text has already been specified");
+ } catch (BuildException ex) {
+ //TODO assert value
+ }
}
+ @Test
public void testDuplicateElement() {
- expectBuildException(
- "duplicate.element",
- "the element text has already been specified");
+ try {
+ buildRule.executeTarget("duplicate.element");
+ fail("BuildException expected: the element text has already been specified");
+ } catch (BuildException ex) {
+ //TODO assert value
+ }
}
+ @Test
public void testUri() {
- expectLog("uri", "Hello World");
+ buildRule.executeTarget("uri");
+ assertEquals("Hello World", buildRule.getLog());
}
+ @Test
public void testNested() {
- expectLog("nested", "A nested element");
+ buildRule.executeTarget("nested");
+ assertEquals("A nested element", buildRule.getLog());
}
+ @Test
public void testDouble() {
- expectLog(
- "double",
- "@{prop} is 'property', value of ${property} is 'A property value'");
+ buildRule.executeTarget("double");
+ assertEquals("@{prop} is 'property', value of ${property} is 'A property value'", buildRule.getLog());
}
+ @Test
public void testIgnoreCase() {
- expectLog(
- "ignorecase",
- "a is ab is b");
+ buildRule.executeTarget("ignorecase");
+ assertEquals("a is ab is b", buildRule.getLog());
}
+ @Test
public void testIgnoreElementCase() {
- expectLog(
- "ignore-element-case",
- "nested elementnested element");
+ buildRule.executeTarget("ignore-element-case");
+ assertEquals("nested elementnested element", buildRule.getLog());
}
+ @Test
public void testTextElement() {
- expectLogContaining(
- "textelement", "Hello world");
+ buildRule.executeTarget("textelement");
+ assertContains("Hello world", buildRule.getLog());
}
+ @Test
public void testTextTrim() {
- expectLogContaining(
- "text.trim", "[Hello world]");
+ buildRule.executeTarget("text.trim");
+ assertContains("[Hello world]", buildRule.getLog());
}
+ @Test
public void testDuplicateTextName() {
- expectBuildException(
- "duplicatetextname",
- "the name \"text\" is already used as an attribute");
+ try {
+ buildRule.executeTarget("duplicatetextname");
+ fail("BuildException expected: the name \"text\" is already used as an attribute");
+ } catch (BuildException ex) {
+ //TODO assert value
+ }
}
+ @Test
public void testDuplicateTextName2() {
- expectBuildException(
- "duplicatetextname2",
- "the attribute name \"text\" has already been used by the text element");
+ try {
+ buildRule.executeTarget("duplicatetextname2");
+ fail("BuildException expected: the attribute name \"text\" has already been used by the text element");
+ } catch (BuildException ex) {
+ //TODO assert value
+ }
}
+ @Test
public void testEscape() {
- expectLog(
- "escape",
- "a@b or a@b is avalue@bvalue");
+ buildRule.executeTarget("escape");
+ assertEquals("a@b or a@b is avalue@bvalue", buildRule.getLog());
}
+ @Test
public void testAttributeDescription() {
- expectLog(
- "attribute.description",
- "description is hello world");
+ buildRule.executeTarget("attribute.description");
+ assertEquals("description is hello world", buildRule.getLog());
}
+ @Test
public void testOverrideDefault() {
- expectLog(
- "override.default",
- "value is new");
+ buildRule.executeTarget("override.default");
+ assertEquals("value is new", buildRule.getLog());
}
+ @Test
public void testImplicit() {
- expectLog(
- "implicit", "Before implicitIn implicitAfter implicit");
+ buildRule.executeTarget("implicit");
+ assertEquals("Before implicitIn implicitAfter implicit", buildRule.getLog());
}
+ @Test
public void testImplicitNotOptional() {
- expectSpecificBuildException(
- "implicit.notoptional",
- "Missing nested elements for implicit element implicit",
- "Missing nested elements for implicit element implicit");
+ try {
+ buildRule.executeTarget("implicit.notoptional");
+ fail("BuildException expected: Missing nested elements for implicit element implicit");
+ } catch (BuildException ex) {
+ assertEquals("Missing nested elements for implicit element implicit", ex.getMessage());
+ }
}
+ @Test
public void testImplicitOptional() {
- expectLog(
- "implicit.optional", "Before implicitAfter implicit");
+ buildRule.executeTarget("implicit.optional");
+ assertEquals("Before implicitAfter implicit", buildRule.getLog());
}
+ @Test
public void testImplicitExplicit() {
- expectSpecificBuildException(
- "implicit.explicit",
- "Only one element allowed when using implicit elements",
- "Only one element allowed when using implicit elements");
+ try {
+ buildRule.executeTarget("implicit.explicit");
+ fail("BuildException expected: Only one element allowed when using implicit elements");
+ } catch (BuildException ex) {
+ assertEquals("Only one element allowed when using implicit elements", ex.getMessage());
+ }
}
+ @Test
public void testBackTraceOff() {
try {
- executeTarget("backtraceoff");
+ buildRule.executeTarget("backtraceoff");
} catch (BuildException ex) {
if (ex.getMessage().indexOf("following error occurred") != -1) {
fail("error message contained backtrace - " + ex.getMessage());
@@ -144,15 +187,20 @@ public class MacroDefTest extends BuildF
}
}
+ @Test
public void testBackTrace() {
- expectBuildExceptionContaining(
- "backtraceon",
- "Checking if a back trace is created",
- "following error occurred");
+ try {
+ buildRule.executeTarget("backtraceon");
+ fail("BuildException expected: Checking if a back trace is created");
+ } catch (BuildException ex) {
+ assertContains("following error occurred", ex.getMessage());
+ }
}
+ @Test
public void testTopLevelText() {
- expectLogContaining("top-level-text", "Hello World");
+ buildRule.executeTarget("top-level-text");
+ assertContains("Hello World", buildRule.getLog());
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/MakeUrlTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/MakeUrlTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/MakeUrlTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/MakeUrlTest.java Fri Apr 18 21:00:38 2014
@@ -17,47 +17,82 @@
*/
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.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
import java.io.InputStream;
import java.io.IOException;
import java.net.URL;
+import static org.apache.tools.ant.AntAssert.assertContains;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
-public class MakeUrlTest extends BuildFileTest {
- public MakeUrlTest(String s) {
- super(s);
- }
+public class MakeUrlTest {
+
+ @Rule
+ public final BuildFileRule buildRule = new BuildFileRule();
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/taskdefs/makeurl.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/makeurl.xml");
}
+ @Test
public void testEmpty() {
- expectBuildExceptionContaining("testEmpty", "missing property", "property");
+ try {
+ buildRule.executeTarget("testEmpty");
+ fail("BuildException expected: missing property");
+ } catch (BuildException ex) {
+ assertContains("property", ex.getMessage());
+ }
}
+ @Test
public void testNoProperty() {
- expectBuildExceptionContaining("testNoProperty", "missing property", "property");
+ try {
+ buildRule.executeTarget("testNoProperty");
+ fail("BuildException expected: missing property");
+ } catch (BuildException ex) {
+ assertContains("property", ex.getMessage());
+ }
}
+ @Test
public void testNoFile() {
- expectBuildExceptionContaining("testNoFile", "missing file", "file");
+ try {
+ buildRule.executeTarget("testNoFile");
+ fail("BuildException expected: missing file");
+ } catch (BuildException ex) {
+ assertContains("file", ex.getMessage());
+ }
}
+ @Test
public void testValidation() {
- expectBuildExceptionContaining("testValidation", MakeUrl.ERROR_MISSING_FILE, "file");
+ try {
+ buildRule.executeTarget("testValidation");
+ fail("BuildException expected: " + MakeUrl.ERROR_MISSING_FILE);
+ } catch (BuildException ex) {
+ assertContains("file", ex.getMessage());
+ }
}
+ @Test
public void testWorks() {
- executeTarget("testWorks");
+ buildRule.executeTarget("testWorks");
assertPropertyContains("testWorks", "file:");
assertPropertyContains("testWorks", "/foo");
}
+ @Test
public void testIllegalChars() {
- executeTarget("testIllegalChars");
+ buildRule.executeTarget("testIllegalChars");
assertPropertyContains("testIllegalChars", "file:");
assertPropertyContains("testIllegalChars", "fo%20o%25");
}
@@ -67,8 +102,9 @@ public class MakeUrlTest extends BuildFi
*
* @throws IOException
*/
+ @Test
public void testRoundTrip() throws IOException {
- executeTarget("testRoundTrip");
+ buildRule.executeTarget("testRoundTrip");
assertPropertyContains("testRoundTrip", "file:");
String property = getProperty("testRoundTrip");
URL url = new URL(property);
@@ -76,26 +112,30 @@ public class MakeUrlTest extends BuildFi
instream.close();
}
+ @Test
public void testIllegalCombinations() {
- executeTarget("testIllegalCombinations");
+ buildRule.executeTarget("testIllegalCombinations");
assertPropertyContains("testIllegalCombinations", "/foo");
assertPropertyContains("testIllegalCombinations", ".xml");
}
+ @Test
public void testFileset() {
- executeTarget("testFileset");
+ buildRule.executeTarget("testFileset");
assertPropertyContains("testFileset", ".xml ");
assertPropertyEndsWith("testFileset", ".xml");
}
+ @Test
public void testFilesetSeparator() {
- executeTarget("testFilesetSeparator");
+ buildRule.executeTarget("testFilesetSeparator");
assertPropertyContains("testFilesetSeparator", ".xml\",\"");
assertPropertyEndsWith("testFilesetSeparator", ".xml");
}
+ @Test
public void testPath() {
- executeTarget("testPath");
+ buildRule.executeTarget("testPath");
assertPropertyContains("testPath", "makeurl.xml");
}
@@ -131,6 +171,6 @@ public class MakeUrlTest extends BuildFi
* @return
*/
protected String getProperty(String property) {
- return project.getProperty(property);
+ return buildRule.getProject().getProperty(property);
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestClassPathTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestClassPathTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestClassPathTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestClassPathTest.java Fri Apr 18 21:00:38 2014
@@ -18,57 +18,96 @@
package org.apache.tools.ant.taskdefs;
-import org.apache.tools.ant.BuildFileTest;
-import org.apache.tools.ant.taskdefs.condition.Os;
-import org.apache.tools.ant.util.regexp.RegexpMatcherFactory;
+import static org.apache.tools.ant.AntAssert.assertContains;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.taskdefs.condition.Os;
+import org.apache.tools.ant.util.regexp.RegexpMatcherFactory;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
/**
* Tests <bm:manifestclasspath>.
*/
-public class ManifestClassPathTest
- extends BuildFileTest {
+public class ManifestClassPathTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/taskdefs/manifestclasspath.xml");
+ buildRule.configureProject("src/etc/testcases/taskdefs/manifestclasspath.xml");
}
+ @Test
public void testBadDirectory() {
- expectBuildExceptionContaining("test-bad-directory", "bad-jar-dir",
- "Jar's directory not found:");
- assertPropertyUnset("jar.classpath");
+ try {
+ buildRule.executeTarget("test-bad-directory");
+ fail("Build exception should have been thrown on bad directory");
+ } catch (BuildException ex) {
+ assertContains("Jar's directory not found:", ex.getMessage());
+ }
+ assertNull(buildRule.getProject().getProperty("jar.classpath"));
}
+ @Test
public void testBadNoProperty() {
- expectBuildExceptionContaining("test-bad-no-property", "no-property",
- "Missing 'property' attribute!");
- assertPropertyUnset("jar.classpath");
+ try {
+ buildRule.executeTarget("test-bad-no-property");
+ fail("Build exception should have been thrown on no property");
+ } catch (BuildException ex) {
+ assertContains("Missing 'property' attribute!", ex.getMessage());
+ }
+ assertNull(buildRule.getProject().getProperty("jar.classpath"));
}
+ @Test
public void testBadPropertyExists() {
- expectBuildExceptionContaining("test-bad-property-exists",
- "property-exits", "Property 'jar.classpath' already set!");
- assertPropertyEquals("jar.classpath", "exists");
+ try {
+ buildRule.executeTarget("test-bad-property-exists");
+ fail("Build exception should have been thrown on bad property");
+ } catch (BuildException ex) {
+ assertContains("Property 'jar.classpath' already set!", ex.getMessage());
+ }
+ assertEquals(buildRule.getProject().getProperty("jar.classpath"), "exists");
}
+ @Test
public void testBadNoJarfile() {
- expectBuildExceptionContaining("test-bad-no-jarfile", "no-jarfile",
- "Missing 'jarfile' attribute!");
- assertPropertyUnset("jar.classpath");
+ try {
+ buildRule.executeTarget("test-bad-no-jarfile");
+ fail("Build exception should have been thrown on bad jar file");
+ } catch (BuildException ex) {
+ assertContains("Missing 'jarfile' attribute!", ex.getMessage());
+ }
+ assertNull(buildRule.getProject().getProperty("jar.classpath"));
}
+ @Test
public void testBadNoClassPath() {
- expectBuildExceptionContaining("test-bad-no-classpath", "no-classpath",
- "Missing nested <classpath>!");
- assertPropertyUnset("jar.classpath");
+ try {
+ buildRule.executeTarget("test-bad-no-classpath");
+ fail("Build exception should have been thrown on no classpath");
+ } catch (BuildException ex) {
+ assertContains("Missing nested <classpath>!", ex.getMessage());
+ }
+ assertNull(buildRule.getProject().getProperty("jar.classpath"));
}
+ @Test
public void testParentLevel1() {
- executeTarget("test-parent-level1");
+ buildRule.executeTarget("test-parent-level1");
- assertPropertyEquals("jar.classpath", "dsp-core/ " +
+ assertEquals(buildRule.getProject().getProperty("jar.classpath"), "dsp-core/ " +
"dsp-pres/ " +
"dsp-void/ " +
"../generated/dsp-core/ " +
@@ -79,10 +118,11 @@ public class ManifestClassPathTest
"../resources/dsp-void/");
}
+ @Test
public void testParentLevel2() {
- executeTarget("test-parent-level2");
+ buildRule.executeTarget("test-parent-level2");
- assertPropertyEquals("jar.classpath", "../dsp-core/ " +
+ assertEquals(buildRule.getProject().getProperty("jar.classpath"), "../dsp-core/ " +
"../dsp-pres/ " +
"../dsp-void/ " +
"../../generated/dsp-core/ " +
@@ -93,19 +133,23 @@ public class ManifestClassPathTest
"../../resources/dsp-void/");
}
+ @Test
public void testParentLevel2TooDeep() {
- expectBuildExceptionContaining("test-parent-level2-too-deep", "nopath",
- "No suitable relative path from ");
- assertPropertyUnset("jar.classpath");
+ try {
+ buildRule.executeTarget("test-parent-level2-too-deep");
+ fail("Build exception should have been thrown on no suitable path");
+ } catch (BuildException ex) {
+ assertContains("No suitable relative path from ", ex.getMessage());
+ }
+ assertNull(buildRule.getProject().getProperty("jar.classpath"));
}
+ @Test
public void testPseudoTahoeRefid() {
- if (!RegexpMatcherFactory.regexpMatcherPresent(project)) {
- System.out.println("Test 'testPseudoTahoeRefid' skipped because no regexp matcher is present.");
- return;
- }
- executeTarget("test-pseudo-tahoe-refid");
- assertPropertyEquals("jar.classpath", "classes/dsp-core/ " +
+ Assume.assumeTrue("No regexp matcher is present", RegexpMatcherFactory.regexpMatcherPresent(buildRule.getProject()));
+
+ buildRule.executeTarget("test-pseudo-tahoe-refid");
+ assertEquals(buildRule.getProject().getProperty("jar.classpath"), "classes/dsp-core/ " +
"classes/dsp-pres/ " +
"classes/dsp-void/ " +
"generated/dsp-core/ " +
@@ -113,13 +157,12 @@ public class ManifestClassPathTest
"resources/dsp-pres/");
}
+ @Test
public void testPseudoTahoeNested() {
- if (!RegexpMatcherFactory.regexpMatcherPresent(project)) {
- System.out.println("Test 'testPseudoTahoeNested' skipped because no regexp matcher is present.");
- return;
- }
- executeTarget("test-pseudo-tahoe-nested");
- assertPropertyEquals("jar.classpath", "classes/dsp-core/ " +
+ Assume.assumeTrue("No regexp matcher is present", RegexpMatcherFactory.regexpMatcherPresent(buildRule.getProject()));
+
+ buildRule.executeTarget("test-pseudo-tahoe-nested");
+ assertEquals(buildRule.getProject().getProperty("jar.classpath"), "classes/dsp-core/ " +
"classes/dsp-pres/ " +
"classes/dsp-void/ " +
"generated/dsp-core/ " +
@@ -127,10 +170,11 @@ public class ManifestClassPathTest
"resources/dsp-pres/");
}
+ @Test
public void testParentLevel2WithJars() {
- executeTarget("test-parent-level2-with-jars");
+ buildRule.executeTarget("test-parent-level2-with-jars");
- assertPropertyEquals("jar.classpath", "../../lib/acme-core.jar " +
+ assertEquals(buildRule.getProject().getProperty("jar.classpath"), "../../lib/acme-core.jar " +
"../../lib/acme-pres.jar " +
"../dsp-core/ " +
"../dsp-pres/ " +
@@ -142,64 +186,64 @@ public class ManifestClassPathTest
"../../resources/dsp-pres/ " +
"../../resources/dsp-void/");
}
+
+ @Test
public void testInternationalGerman() {
- executeTarget("international-german");
- expectLogContaining("run-two-jars", "beta alpha");
+ buildRule.executeTarget("international-german");
+ buildRule.executeTarget("run-two-jars");
+ assertContains("beta alpha", buildRule.getLog());
}
+
+ @Test
public void testInternationalHebrew() {
- if (!Os.isFamily("windows")) {
- executeTarget("international-hebrew");
- expectLogContaining("run-two-jars", "beta alpha");
- } else {
- System.out.println("Test with hebrew path not attempted under Windows");
- }
-
+ Assume.assumeFalse("Test with hebrew path not attempted under Windows", Os.isFamily("windows"));
+ buildRule.executeTarget("international-hebrew");
+ buildRule.executeTarget("run-two-jars");
+ assertContains("beta alpha", buildRule.getLog());
}
+ @Test
public void testSameWindowsDrive() {
- if (!Os.isFamily("windows")) {
- System.out.println("Test with drive letters only run on windows");
- } else {
- executeTarget("testSameDrive");
- assertPropertyEquals("cp", "../a/b/x.jar");
- }
+ Assume.assumeTrue("Test with drive letters only run on windows", Os.isFamily("windows"));
+ buildRule.executeTarget("testSameDrive");
+ assertEquals(buildRule.getProject().getProperty("cp"), "../a/b/x.jar");
}
+ @Test
public void testDifferentWindowsDrive() {
- if (!Os.isFamily("windows")) {
- System.out.println("Test with drive letters only run on windows");
- } else {
- // the lines below try to find a drive name different than the one containing the temp dir
- // if the temp dir is C will try to use D
- // if the temp dir is on D or other will try to use C
- File tmpdir = new File(System.getProperty("java.io.tmpdir"));
- String driveLetter = "C";
- try {
- String tmpCanonicalPath = tmpdir.getCanonicalPath();
- driveLetter = tmpCanonicalPath.substring(1).toUpperCase();
- } catch (IOException ioe) {
- System.out.println("exception happened getting canonical path of java.io.tmpdir : " + ioe.getMessage());
- }
- String altDriveLetter = null;
- try {
- if ("C".equals(driveLetter)) {
- altDriveLetter = "D";
- } else {
- altDriveLetter = "C";
- }
- new java.io.File(altDriveLetter + ":/foo.txt").getCanonicalPath();
- } catch (java.io.IOException e) {
- System.out.println("drive " + altDriveLetter + ": doesn't exist or is not ready,"
- + " skipping test");
- return;
+ Assume.assumeTrue("Test with drive letters only run on windows", Os.isFamily("windows"));
+ // the lines below try to find a drive name different than the one containing the temp dir
+ // if the temp dir is C will try to use D
+ // if the temp dir is on D or other will try to use C
+ File tmpdir = new File(System.getProperty("java.io.tmpdir"));
+ String driveLetter = "C";
+ try {
+ String tmpCanonicalPath = tmpdir.getCanonicalPath();
+ driveLetter = tmpCanonicalPath.substring(0, 1).toUpperCase();
+ } catch (IOException ioe) {
+ System.out.println("exception happened getting canonical path of java.io.tmpdir : " + ioe.getMessage());
+ }
+ String altDriveLetter = null;
+ try {
+ if ("C".equals(driveLetter)) {
+ altDriveLetter = "D";
+ } else {
+ altDriveLetter = "C";
}
- project.setProperty("altDriveLetter", altDriveLetter);
- expectBuildExceptionContaining("testDifferentDrive",
- "different drive",
- "No suitable relative path from ");
- assertPropertyUnset("cp");
+ new java.io.File(altDriveLetter + ":/foo.txt").getCanonicalPath();
+ } catch (java.io.IOException e) {
+ Assume.assumeNoException("Drive " + altDriveLetter + ": doesn't exist or is not ready", e);
}
+ buildRule.getProject().setProperty("altDriveLetter", altDriveLetter);
+
+ try {
+ buildRule.executeTarget("testDifferentDrive");
+ fail("Build exception should have been thrown on no alternative drive");
+ } catch (BuildException ex) {
+ assertContains("No suitable relative path from ", ex.getMessage());
+ }
+
+ assertNull(buildRule.getProject().getProperty("cp"));
}
} // END class ManifestClassPathTest
-