Browse Source

Expected exceptions galore

master
Gintas Grigelionis 7 years ago
parent
commit
ad98e27d0c
50 changed files with 844 additions and 1098 deletions
  1. +1
    -8
      src/tests/junit/org/apache/tools/ant/DispatchTaskTest.java
  2. +27
    -24
      src/tests/junit/org/apache/tools/ant/ExecutorTest.java
  3. +13
    -24
      src/tests/junit/org/apache/tools/ant/taskdefs/AntLikeTasksAtTopLevelTest.java
  4. +5
    -8
      src/tests/junit/org/apache/tools/ant/taskdefs/AntStructureTest.java
  5. +107
    -67
      src/tests/junit/org/apache/tools/ant/taskdefs/AvailableTest.java
  6. +9
    -22
      src/tests/junit/org/apache/tools/ant/taskdefs/BasenameTest.java
  7. +10
    -14
      src/tests/junit/org/apache/tools/ant/taskdefs/CVSPassTest.java
  8. +5
    -8
      src/tests/junit/org/apache/tools/ant/taskdefs/CallTargetTest.java
  9. +8
    -27
      src/tests/junit/org/apache/tools/ant/taskdefs/ConcatTest.java
  10. +31
    -57
      src/tests/junit/org/apache/tools/ant/taskdefs/ConditionTest.java
  11. +24
    -29
      src/tests/junit/org/apache/tools/ant/taskdefs/CopydirTest.java
  12. +15
    -34
      src/tests/junit/org/apache/tools/ant/taskdefs/CopyfileTest.java
  13. +20
    -9
      src/tests/junit/org/apache/tools/ant/taskdefs/DeleteTest.java
  14. +6
    -9
      src/tests/junit/org/apache/tools/ant/taskdefs/DeltreeTest.java
  15. +17
    -25
      src/tests/junit/org/apache/tools/ant/taskdefs/DirnameTest.java
  16. +44
    -79
      src/tests/junit/org/apache/tools/ant/taskdefs/FailTest.java
  17. +18
    -39
      src/tests/junit/org/apache/tools/ant/taskdefs/FilterTest.java
  18. +12
    -15
      src/tests/junit/org/apache/tools/ant/taskdefs/GUnzipTest.java
  19. +9
    -14
      src/tests/junit/org/apache/tools/ant/taskdefs/InputTest.java
  20. +14
    -21
      src/tests/junit/org/apache/tools/ant/taskdefs/MkdirTest.java
  21. +22
    -30
      src/tests/junit/org/apache/tools/ant/taskdefs/RenameTest.java
  22. +36
    -45
      src/tests/junit/org/apache/tools/ant/taskdefs/ReplaceTest.java
  23. +7
    -7
      src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java
  24. +8
    -10
      src/tests/junit/org/apache/tools/ant/taskdefs/SleepTest.java
  25. +18
    -17
      src/tests/junit/org/apache/tools/ant/taskdefs/StyleTest.java
  26. +36
    -43
      src/tests/junit/org/apache/tools/ant/taskdefs/TarTest.java
  27. +30
    -37
      src/tests/junit/org/apache/tools/ant/taskdefs/TaskdefTest.java
  28. +3
    -9
      src/tests/junit/org/apache/tools/ant/taskdefs/UntarTest.java
  29. +24
    -32
      src/tests/junit/org/apache/tools/ant/taskdefs/UnzipTest.java
  30. +9
    -9
      src/tests/junit/org/apache/tools/ant/taskdefs/XmlnsTest.java
  31. +5
    -8
      src/tests/junit/org/apache/tools/ant/taskdefs/condition/HttpTest.java
  32. +10
    -7
      src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReferenceTest.java
  33. +13
    -21
      src/tests/junit/org/apache/tools/ant/taskdefs/condition/ParserSupportsTest.java
  34. +12
    -16
      src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailTaskTest.java
  35. +30
    -40
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java
  36. +7
    -7
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java
  37. +10
    -16
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/PvcsTest.java
  38. +2
    -9
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTaskTest.java
  39. +6
    -26
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java
  40. +8
    -7
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java
  41. +10
    -14
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java
  42. +23
    -15
      src/tests/junit/org/apache/tools/ant/types/CommandlineTest.java
  43. +24
    -29
      src/tests/junit/org/apache/tools/ant/types/EnumeratedAttributeTest.java
  44. +3
    -8
      src/tests/junit/org/apache/tools/ant/types/FilterSetTest.java
  45. +10
    -15
      src/tests/junit/org/apache/tools/ant/types/RedirectorElementTest.java
  46. +49
    -34
      src/tests/junit/org/apache/tools/ant/types/ResourceOutputTest.java
  47. +8
    -18
      src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java
  48. +4
    -17
      src/tests/junit/org/apache/tools/ant/util/VectorSetTest.java
  49. +14
    -12
      src/tests/junit/org/apache/tools/zip/ExtraFieldUtilsTest.java
  50. +8
    -7
      src/tests/junit/org/apache/tools/zip/ZipEntryTest.java

+ 1
- 8
src/tests/junit/org/apache/tools/ant/DispatchTaskTest.java View File

@@ -18,8 +18,6 @@


package org.apache.tools.ant; package org.apache.tools.ant;


import static org.junit.Assert.fail;

import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@@ -34,13 +32,8 @@ public class DispatchTaskTest {
buildRule.configureProject("src/etc/testcases/core/dispatch/dispatch.xml"); buildRule.configureProject("src/etc/testcases/core/dispatch/dispatch.xml");
} }


@Test
@Test(expected = BuildException.class)
public void testDisp() { public void testDisp() {
try {
buildRule.executeTarget("disp"); buildRule.executeTarget("disp");
fail("BuildException should have been thrown");
} catch (BuildException ex) {
//FIXME the previous method used here ignored the build exception - what are we trying to test
}
} }
} }

+ 27
- 24
src/tests/junit/org/apache/tools/ant/ExecutorTest.java View File

@@ -19,23 +19,29 @@
package org.apache.tools.ant; package org.apache.tools.ant;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;


import java.util.Vector; import java.util.Vector;


import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;


/** /**
* Executor tests * Executor tests
*/ */
public class ExecutorTest implements BuildListener { public class ExecutorTest implements BuildListener {


@Rule
public BuildFileRule buildRule = new BuildFileRule();

@Rule
public ExpectedException thrown = ExpectedException.none();

private static final String SINGLE_CHECK private static final String SINGLE_CHECK
= "org.apache.tools.ant.helper.SingleCheckExecutor";
= "org.apache.tools.ant.helper.SingleCheckExecutor";
private static final String IGNORE_DEPS private static final String IGNORE_DEPS
= "org.apache.tools.ant.helper.IgnoreDependenciesExecutor";
= "org.apache.tools.ant.helper.IgnoreDependenciesExecutor";


private static final Vector<String> TARGET_NAMES; private static final Vector<String> TARGET_NAMES;
static { static {
@@ -44,9 +50,6 @@ public class ExecutorTest implements BuildListener {
TARGET_NAMES.add("b"); TARGET_NAMES.add("b");
} }


@Rule
public BuildFileRule buildRule = new BuildFileRule();

private int targetCount; private int targetCount;


/* BuildListener stuff */ /* BuildListener stuff */
@@ -117,22 +120,22 @@ public class ExecutorTest implements BuildListener {


@Test @Test
public void testDefaultFailure() { public void testDefaultFailure() {
thrown.expect(BuildException.class);
thrown.expectMessage("failfoo");
try { try {
getProject(null, true).executeTargets(TARGET_NAMES); getProject(null, true).executeTargets(TARGET_NAMES);
fail("should fail");
} catch (BuildException e) {
assertEquals("failfoo", e.getMessage());
} finally {
assertEquals(1, targetCount); assertEquals(1, targetCount);
} }
} }


@Test @Test
public void testSingleCheckFailure() { public void testSingleCheckFailure() {
thrown.expect(BuildException.class);
thrown.expectMessage("failfoo");
try { try {
getProject(SINGLE_CHECK, true).executeTargets(TARGET_NAMES); getProject(SINGLE_CHECK, true).executeTargets(TARGET_NAMES);
fail("should fail");
} catch (BuildException e) {
assertEquals("failfoo", e.getMessage());
} finally {
assertEquals(1, targetCount); assertEquals(1, targetCount);
} }
} }
@@ -145,36 +148,36 @@ public class ExecutorTest implements BuildListener {


@Test @Test
public void testKeepGoingDefault() { public void testKeepGoingDefault() {
thrown.expect(BuildException.class);
thrown.expectMessage("failfoo");
try { try {
getProject(null, true, true).executeTargets(TARGET_NAMES); getProject(null, true, true).executeTargets(TARGET_NAMES);
fail("should fail");
} catch (BuildException e) {
assertEquals("failfoo", e.getMessage());
} finally {
assertEquals(2, targetCount); assertEquals(2, targetCount);
} }
} }


@Test @Test
public void testKeepGoingSingleCheck() { public void testKeepGoingSingleCheck() {
thrown.expect(BuildException.class);
thrown.expectMessage("failfoo");
try { try {
getProject(SINGLE_CHECK, true, true).executeTargets(TARGET_NAMES); getProject(SINGLE_CHECK, true, true).executeTargets(TARGET_NAMES);
fail("should fail");
} catch (BuildException e) {
assertEquals("failfoo", e.getMessage());
} finally {
assertEquals(1, targetCount); assertEquals(1, targetCount);
} }
} }


@Test @Test
public void testKeepGoingIgnoreDependencies() { public void testKeepGoingIgnoreDependencies() {
thrown.expect(BuildException.class);
thrown.expectMessage("failfoo");
Vector<String> targetNames = new Vector<>(TARGET_NAMES);
// explicitly add foo for failure
targetNames.add(0, "foo");
try { try {
//explicitly add foo for failure
Vector<String> targetNames = new Vector<>(TARGET_NAMES);
targetNames.add(0, "foo");
getProject(IGNORE_DEPS, true, true).executeTargets(targetNames); getProject(IGNORE_DEPS, true, true).executeTargets(targetNames);
fail("should fail");
} catch (BuildException e) {
assertEquals("failfoo", e.getMessage());
} finally {
assertEquals(3, targetCount); assertEquals(3, targetCount);
} }
} }


+ 13
- 24
src/tests/junit/org/apache/tools/ant/taskdefs/AntLikeTasksAtTopLevelTest.java View File

@@ -22,9 +22,7 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildFileRule; import org.apache.tools.ant.BuildFileRule;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.rules.ExpectedException;


/** /**
* @since Ant 1.6 * @since Ant 1.6
@@ -34,37 +32,28 @@ public class AntLikeTasksAtTopLevelTest {
@Rule @Rule
public BuildFileRule buildRule = new BuildFileRule(); public BuildFileRule buildRule = new BuildFileRule();


@Rule
public ExpectedException thrown = ExpectedException.none();

@Test @Test
public void testAnt() { public void testAnt() {
try {
buildRule.configureProject("src/etc/testcases/taskdefs/toplevelant.xml");
fail("no exception thrown");
} catch (BuildException e) {
assertEquals("ant task at the top level must not invoke its own"
+ " build file.", e.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("ant task at the top level must not invoke its own build file.");
buildRule.configureProject("src/etc/testcases/taskdefs/toplevelant.xml");
} }


@Test @Test
public void testSubant() { public void testSubant() {
try {
buildRule.configureProject("src/etc/testcases/taskdefs/toplevelsubant.xml");
fail("no exception thrown");
} catch (BuildException e) {
assertEquals("subant task at the top level must not invoke its own"
+ " build file.", e.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("subant task at the top level must not invoke its own build file.");
buildRule.configureProject("src/etc/testcases/taskdefs/toplevelsubant.xml");
} }


@Test @Test
public void testAntcall() { public void testAntcall() {
try {
buildRule.configureProject("src/etc/testcases/taskdefs/toplevelantcall.xml");
fail("no exception thrown");
} catch (BuildException e) {
assertEquals("antcall must not be used at the top level.",
e.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("antcall must not be used at the top level.");
buildRule.configureProject("src/etc/testcases/taskdefs/toplevelantcall.xml");
} }


} }

+ 5
- 8
src/tests/junit/org/apache/tools/ant/taskdefs/AntStructureTest.java View File

@@ -34,7 +34,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;


/** /**
*/ */
@@ -53,14 +52,12 @@ public class AntStructureTest {
buildRule.executeTarget("tearDown"); buildRule.executeTarget("tearDown");
} }


@Test
/**
* Expected failure due lacking a required argument
*/
@Test(expected = BuildException.class)
public void test1() { public void test1() {
try {
buildRule.executeTarget("test1");
fail("required argument not specified");
} catch (BuildException ex) {
//TODO assert exception message
}
buildRule.executeTarget("test1");
} }


@Test @Test


+ 107
- 67
src/tests/junit/org/apache/tools/ant/taskdefs/AvailableTest.java View File

@@ -21,12 +21,12 @@ package org.apache.tools.ant.taskdefs;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildFileRule; import org.apache.tools.ant.BuildFileRule;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;


/** /**
* JUnit test for the Available task/condition. * JUnit test for the Available task/condition.
@@ -43,95 +43,104 @@ public class AvailableTest {
buildRule.executeTarget("setUp"); buildRule.executeTarget("setUp");
} }


// Nothing specified -> Fail
@Test
/**
* Nothing specified -&gt; Fail
*/
@Test(expected = BuildException.class)
public void test1() { public void test1() {
try {
buildRule.executeTarget("test1");
fail("Required argument not specified");
} catch (BuildException ex) {
//TODO assert exception message
}
buildRule.executeTarget("test1");
} }


// Only property specified -> Fail
@Test
/**
* Only property specified -&gt; Fail
*/
@Test(expected = BuildException.class)
public void test2() { public void test2() {
try {
buildRule.executeTarget("test2");
fail("Required argument not specified");
} catch (BuildException ex) {
//TODO assert exception message
}
buildRule.executeTarget("test2");
} }


// Only file specified -> Fail
@Test
/**
* Only file specified -&gt; Fail
*/
@Test(expected = BuildException.class)
public void test3() { public void test3() {
try {
buildRule.executeTarget("test3");
fail("Required argument not specified");
} catch (BuildException ex) {
//TODO assert exception message
}
buildRule.executeTarget("test3");
} }


// file doesn't exist -> property 'test' == null
/**
* File doesn't exist -&gt; property 'test' == null
*/
@Test @Test
public void test4() { public void test4() {
buildRule.executeTarget("test4"); buildRule.executeTarget("test4");
assertNull(buildRule.getProject().getProperty("test")); assertNull(buildRule.getProject().getProperty("test"));
} }


// file does exist -> property 'test' == 'true'
/**
* File does exist -&gt; property 'test' == 'true'
*/
public void test5() { public void test5() {
buildRule.executeTarget("test5"); buildRule.executeTarget("test5");
assertEquals("true", buildRule.getProject().getProperty("test")); assertEquals("true", buildRule.getProject().getProperty("test"));
} }


// resource doesn't exist -> property 'test' == null
/**
* Resource doesn't exist -&gt; property 'test' == null
*/
@Test @Test
public void test6() { public void test6() {
buildRule.executeTarget("test6"); buildRule.executeTarget("test6");
assertNull(buildRule.getProject().getProperty("test")); assertNull(buildRule.getProject().getProperty("test"));
} }


// resource does exist -> property 'test' == 'true'
/**
* Resource does exist -&gt; property 'test' == 'true'
*/
@Test @Test
public void test7() { public void test7() {
buildRule.executeTarget("test7"); buildRule.executeTarget("test7");
assertEquals("true", buildRule.getProject().getProperty("test")); assertEquals("true", buildRule.getProject().getProperty("test"));
} }


// class doesn't exist -> property 'test' == null
/**
* Class doesn't exist -&gt; property 'test' == null
*/
@Test @Test
public void test8() { public void test8() {
buildRule.executeTarget("test8"); buildRule.executeTarget("test8");
assertNull(buildRule.getProject().getProperty("test")); assertNull(buildRule.getProject().getProperty("test"));
} }


// class does exist -> property 'test' == 'true'
/**
* class does exist -&gt; property 'test' == 'true'
*/
@Test @Test
public void test9() { public void test9() {
buildRule.executeTarget("test9"); buildRule.executeTarget("test9");
assertEquals("true", buildRule.getProject().getProperty("test")); assertEquals("true", buildRule.getProject().getProperty("test"));
} }


// All three specified and all three exist -> true
/**
* All three specified and all three exist -&gt; true
*/
@Test @Test
public void test10() { public void test10() {
buildRule.executeTarget("test10"); buildRule.executeTarget("test10");
assertEquals("true", buildRule.getProject().getProperty("test")); assertEquals("true", buildRule.getProject().getProperty("test"));
} }


// All three specified but class missing -> null
/**
* All three specified but class missing -&gt; null
*/
@Test @Test
public void test11() { public void test11() {
buildRule.executeTarget("test11"); buildRule.executeTarget("test11");
assertNull(buildRule.getProject().getProperty("test")); assertNull(buildRule.getProject().getProperty("test"));
} }


// Specified property-name is "" -> true
/**
* Specified property-name is "" -&gt; true
*/
@Test @Test
public void test12() { public void test12() {
buildRule.executeTarget("test12"); buildRule.executeTarget("test12");
@@ -139,131 +148,162 @@ public class AvailableTest {
assertEquals("true", buildRule.getProject().getProperty("")); assertEquals("true", buildRule.getProject().getProperty(""));
} }


// Specified file is "" -> invalid files do not exist
/**
* Specified file is "" -&gt; invalid files do not exist
*/
@Test @Test
public void test13() { public void test13() {
buildRule.executeTarget("test13"); buildRule.executeTarget("test13");
assertNull(buildRule.getProject().getProperty("test")); assertNull(buildRule.getProject().getProperty("test"));
} }


// Specified file is "" actually a directory, so it should pass
/**
* Specified file is "" actually a directory, so it should pass
*/
@Test @Test
public void test13b() { public void test13b() {
buildRule.executeTarget("test13b"); buildRule.executeTarget("test13b");
assertEquals("true", buildRule.getProject().getProperty("test")); assertEquals("true", buildRule.getProject().getProperty("test"));
} }


// Specified resource is "" -> can such a thing exist?
/*
* returns non null IBM JDK 1.3 Linux
/**
* Specified resource is "" -gt; can such a thing exist?
*/ */
// public void test14() {
// buildRule.executeTarget("test14");
// assertEquals(buildRule.getProject().getProperty("test"), null);
// }
@Ignore("returns non null IBM JDK 1.3 Linux")
@Test
public void test14() {
buildRule.executeTarget("test14");
assertEquals(buildRule.getProject().getProperty("test"), null);
}


// Specified class is "" -> can not exist
/**
* Specified class is "" -&gt; can not exist
*/
@Test @Test
public void test15() { public void test15() {
buildRule.executeTarget("test15"); buildRule.executeTarget("test15");
assertNull(buildRule.getProject().getProperty("test")); assertNull(buildRule.getProject().getProperty("test"));
} }


// Specified dir is "" -> this is the current directory and should
// always exist
/**
* Specified dir is "" -&gt; this is the current directory and should always exist
*/
@Test @Test
public void test16() { public void test16() {
buildRule.executeTarget("test16"); buildRule.executeTarget("test16");
assertEquals("true", buildRule.getProject().getProperty("test")); assertEquals("true", buildRule.getProject().getProperty("test"));
} }


// Specified dir is "../taskdefs" -> should exist since it's the
// location of the buildfile used...
/**
* Specified dir is "../taskdefs" -&gt; should exist since it's the location
* of the buildfile used...
*/
@Test @Test
public void test17() { public void test17() {
buildRule.executeTarget("test17"); buildRule.executeTarget("test17");
assertEquals("true", buildRule.getProject().getProperty("test")); assertEquals("true", buildRule.getProject().getProperty("test"));
} }


// Specified dir is "../this_dir_should_never_exist" -> null
/**
* Specified dir is "../this_dir_should_never_exist" -&gt; null
*/
@Test @Test
public void test18() { public void test18() {
buildRule.executeTarget("test18"); buildRule.executeTarget("test18");
assertNull(buildRule.getProject().getProperty("test")); assertNull(buildRule.getProject().getProperty("test"));
} }


// Invalid type specified
@Test
/**
* Invalid type specified
*/
@Test(expected = BuildException.class)
public void test19() { public void test19() {
try {
buildRule.executeTarget("test19");
fail("Invalid value for type attribute");
} catch (BuildException ex) {
//TODO assert exception message
}
buildRule.executeTarget("test19");
} }


// Core class that exists in system classpath is ignored
/**
* Core class that exists in system classpath is ignored
*/
@Test @Test
public void test20() { public void test20() {
buildRule.executeTarget("test20"); buildRule.executeTarget("test20");
assertNull(buildRule.getProject().getProperty("test")); assertNull(buildRule.getProject().getProperty("test"));
} }


// Core class that exists in system classpath is ignored, but found in specified classpath
/**
* Core class that exists in system classpath is ignored, but found in specified classpath
*/
@Test @Test
public void test21() { public void test21() {
buildRule.executeTarget("test21"); buildRule.executeTarget("test21");
assertEquals("true", buildRule.getProject().getProperty("test")); assertEquals("true", buildRule.getProject().getProperty("test"));
} }


// Core class that exists in system classpath is not ignored with ignoresystemclass="false"
/**
* Core class that exists in system classpath is not ignored with ignoresystemclass="false"
*/
@Test @Test
public void test22() { public void test22() {
buildRule.executeTarget("test22"); buildRule.executeTarget("test22");
assertEquals("true", buildRule.getProject().getProperty("test")); assertEquals("true", buildRule.getProject().getProperty("test"));
} }


// Core class that exists in system classpath is not ignored with default ignoresystemclasses value
/**
* Core class that exists in system classpath is not ignored with default
* ignoresystemclasses value
*/
@Test @Test
public void test23() { public void test23() {
buildRule.executeTarget("test23"); buildRule.executeTarget("test23");
assertEquals("true", buildRule.getProject().getProperty("test")); assertEquals("true", buildRule.getProject().getProperty("test"));
} }


// Class is found in specified classpath
/**
* Class is found in specified classpath
*/
@Test @Test
public void test24() { public void test24() {
buildRule.executeTarget("test24"); buildRule.executeTarget("test24");
assertEquals("true", buildRule.getProject().getProperty("test")); assertEquals("true", buildRule.getProject().getProperty("test"));
} }


// File is not found in specified filepath
/**
* File is not found in specified filepath
*/
@Test @Test
public void testSearchInPathNotThere() { public void testSearchInPathNotThere() {
buildRule.executeTarget("searchInPathNotThere"); buildRule.executeTarget("searchInPathNotThere");
assertNull(buildRule.getProject().getProperty("test")); assertNull(buildRule.getProject().getProperty("test"));
} }


// File is not found in specified filepath
/**
* File is not found in specified filepath
*/
@Test @Test
public void testSearchInPathIsThere() { public void testSearchInPathIsThere() {
buildRule.executeTarget("searchInPathIsThere"); buildRule.executeTarget("searchInPathIsThere");
assertEquals("true", buildRule.getProject().getProperty("test")); assertEquals("true", buildRule.getProject().getProperty("test"));
} }


// test when file begins with basedir twice
/**
* File begins with basedir twice
*/
@Test @Test
public void testDoubleBasedir() { public void testDoubleBasedir() {
buildRule.executeTarget("testDoubleBasedir"); buildRule.executeTarget("testDoubleBasedir");
} }


// test for searching parents
/**
* Search parents
*/
@Test @Test
public void testSearchParents() { public void testSearchParents() {
buildRule.executeTarget("search-parents"); buildRule.executeTarget("search-parents");
} }
// test for not searching parents

/**
* Do not search parents
*/
@Test @Test
public void testSearchParentsNot() { public void testSearchParentsNot() {
buildRule.executeTarget("search-parents-not"); buildRule.executeTarget("search-parents-not");


+ 9
- 22
src/tests/junit/org/apache/tools/ant/taskdefs/BasenameTest.java View File

@@ -25,7 +25,6 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;


/** /**
*/ */
@@ -39,34 +38,22 @@ public class BasenameTest {
buildRule.configureProject("src/etc/testcases/taskdefs/basename.xml"); buildRule.configureProject("src/etc/testcases/taskdefs/basename.xml");
} }


@Test
@Test(expected = BuildException.class)
public void test1() { public void test1() {
try {
buildRule.executeTarget("test1");
fail("Required attribute missing");
} catch (BuildException ex) {
//TODO assert exception message
}
buildRule.executeTarget("test1");
// TODO assert exception message
} }


@Test
@Test(expected = BuildException.class)
public void test2() { public void test2() {
try {
buildRule.executeTarget("test2");
fail("Required attribute missing");
} catch (BuildException ex) {
//TODO assert exception message
}
buildRule.executeTarget("test2");
// TODO assert exception message
} }


@Test
@Test(expected = BuildException.class)
public void test3() { public void test3() {
try {
buildRule.executeTarget("test3");
fail("Required attribute missing");
} catch (BuildException ex) {
//TODO assert exception message
}
buildRule.executeTarget("test3");
// TODO assert exception message
} }


@Test @Test


+ 10
- 14
src/tests/junit/org/apache/tools/ant/taskdefs/CVSPassTest.java View File

@@ -27,10 +27,10 @@ import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;


/** /**
* Tests CVSLogin task. * Tests CVSLogin task.
@@ -46,8 +46,10 @@ public class CVSPassTest {
":pserver:guest@cvs.tigris.org:/cvs AIbdZ,"; ":pserver:guest@cvs.tigris.org:/cvs AIbdZ,";


@Rule @Rule
public final BuildFileRule buildRule = new BuildFileRule();
public ExpectedException thrown = ExpectedException.none();


@Rule
public final BuildFileRule buildRule = new BuildFileRule();


@Before @Before
public void setUp() { public void setUp() {
@@ -56,22 +58,16 @@ public class CVSPassTest {


@Test @Test
public void testNoCVSRoot() { public void testNoCVSRoot() {
try {
buildRule.executeTarget("test1");
fail("BuildException not thrown");
} catch (BuildException e) {
assertEquals("cvsroot is required", e.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("cvsroot is required");
buildRule.executeTarget("test1");
} }


@Test @Test
public void testNoPassword() { public void testNoPassword() {
try {
buildRule.executeTarget("test2");
fail("BuildException not thrown");
} catch (BuildException e) {
assertEquals("password is required", e.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("password is required");
buildRule.executeTarget("test2");
} }


@After @After


+ 5
- 8
src/tests/junit/org/apache/tools/ant/taskdefs/CallTargetTest.java View File

@@ -29,7 +29,6 @@ import java.util.Vector;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;


/** /**
*/ */
@@ -68,14 +67,12 @@ public class CallTargetTest {
assertThat(buildRule.getLog(), containsString("multi is SETmulti is SET")); assertThat(buildRule.getLog(), containsString("multi is SETmulti is SET"));
} }


@Test
/**
* Expected failure due to empty target name
*/
@Test(expected = BuildException.class)
public void testBlankTarget() { public void testBlankTarget() {
try {
buildRule.executeTarget("blank-target");
fail("target name must not be empty");
} catch (BuildException ex) {
//TODO assert exception contents
}
buildRule.executeTarget("blank-target");
} }


@Test @Test


+ 8
- 27
src/tests/junit/org/apache/tools/ant/taskdefs/ConcatTest.java View File

@@ -34,7 +34,6 @@ import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;


/** /**
* A test class for the 'concat' task, used to concatenate a series of * A test class for the 'concat' task, used to concatenate a series of
@@ -79,28 +78,19 @@ public class ConcatTest {
/** /**
* Expect an exception when insufficient information is provided. * Expect an exception when insufficient information is provided.
*/ */
@Test
@Test(expected = BuildException.class)
public void test1() { public void test1() {
try {
buildRule.executeTarget("test1");
fail("BuildException should have been thrown - Insufficient information");
} catch (BuildException ex) {
//TODO assert value
}

buildRule.executeTarget("test1");
// TODO assert value
} }


/** /**
* Expect an exception when the destination file is invalid. * Expect an exception when the destination file is invalid.
*/ */
@Test
@Test(expected = BuildException.class)
public void test2() { public void test2() {
try {
buildRule.executeTarget("test2");
fail("BuildException should have been thrown - Invalid destination file");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test2");
// TODO assert value
} }


/** /**
@@ -108,14 +98,12 @@ public class ConcatTest {
*/ */
@Test @Test
public void test3() { public void test3() {

File file = new File(buildRule.getProject().getBaseDir(), tempFile); File file = new File(buildRule.getProject().getBaseDir(), tempFile);
if (file.exists()) { if (file.exists()) {
file.delete(); file.delete();
} }


buildRule.executeTarget("test3"); buildRule.executeTarget("test3");

assertTrue(file.exists()); assertTrue(file.exists());
} }


@@ -179,7 +167,6 @@ public class ConcatTest {
final long newSize = file2.length(); final long newSize = file2.length();


assertEquals(origSize, newSize); assertEquals(origSize, newSize);

} }


@Test @Test
@@ -195,7 +182,6 @@ public class ConcatTest {
final long newSize = file2.length(); final long newSize = file2.length();


assertEquals(origSize * 2, newSize); assertEquals(origSize * 2, newSize);

} }


@Test @Test
@@ -237,14 +223,9 @@ public class ConcatTest {
/** /**
* Expect an exception when attempting to cat an file to itself * Expect an exception when attempting to cat an file to itself
*/ */
@Test
@Test(expected = BuildException.class)
public void testsame() { public void testsame() {
try {
buildRule.executeTarget("samefile");
fail("Build exception should have been thrown - output file same as input");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("samefile");
} }


/** /**


+ 31
- 57
src/tests/junit/org/apache/tools/ant/taskdefs/ConditionTest.java View File

@@ -23,16 +23,18 @@ import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;


public class ConditionTest { public class ConditionTest {


@Rule @Rule
public BuildFileRule buildRule = new BuildFileRule();
public ExpectedException thrown = ExpectedException.none();


@Rule
public BuildFileRule buildRule = new BuildFileRule();


/** /**
* The JUnit setup method * The JUnit setup method
@@ -59,22 +61,16 @@ public class ConditionTest {


@Test @Test
public void testConditionIncomplete() { public void testConditionIncomplete() {
try {
buildRule.executeTarget("condition-incomplete");
fail("BuildException should have been thrown - property attribute has been omitted");
} catch (BuildException ex) {
assertEquals("The property attribute is required.", ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("The property attribute is required.");
buildRule.executeTarget("condition-incomplete");
} }


@Test @Test
public void testConditionEmpty() { public void testConditionEmpty() {
try {
buildRule.executeTarget("condition-empty");
fail("BuildException should have been thrown - no conditions");
} catch (BuildException ex) {
assertEquals("You must nest a condition into <condition>", ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("You must nest a condition into <condition>");
buildRule.executeTarget("condition-empty");
} }


@Test @Test
@@ -109,12 +105,9 @@ public class ConditionTest {


@Test @Test
public void testNegationIncomplete() { public void testNegationIncomplete() {
try {
buildRule.executeTarget("negationincomplete");
fail("BuildException should have been thrown - no conditions in <not>");
} catch (BuildException ex) {
assertEquals("You must nest a condition into <not>", ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("You must nest a condition into <not>");
buildRule.executeTarget("negationincomplete");
} }


@Test @Test
@@ -173,12 +166,9 @@ public class ConditionTest {


@Test @Test
public void testFilesmatchIncomplete() { public void testFilesmatchIncomplete() {
try {
buildRule.executeTarget("filesmatch-incomplete");
fail("Build exception should have been thrown - Missing file2 attirbute");
} catch (BuildException ex) {
assertEquals("both file1 and file2 are required in filesmatch", ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("both file1 and file2 are required in filesmatch");
buildRule.executeTarget("filesmatch-incomplete");
} }


@Test @Test
@@ -252,22 +242,16 @@ public class ConditionTest {


@Test @Test
public void testContainsIncomplete1() { public void testContainsIncomplete1() {
try {
buildRule.executeTarget("contains-incomplete1");
fail("BuildException should have been thrown - Missing contains attribute");
} catch (BuildException ex) {
assertEquals("both string and substring are required in contains", ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("both string and substring are required in contains");
buildRule.executeTarget("contains-incomplete1");
} }


@Test @Test
public void testContainsIncomplete2() { public void testContainsIncomplete2() {
try {
buildRule.executeTarget("contains-incomplete2");
fail("BuildException should have been thrown - Missing contains attribute");
} catch (BuildException ex) {
assertEquals("both string and substring are required in contains", ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("both string and substring are required in contains");
buildRule.executeTarget("contains-incomplete2");
} }


@Test @Test
@@ -290,12 +274,9 @@ public class ConditionTest {


@Test @Test
public void testIstrueIncomplete1() { public void testIstrueIncomplete1() {
try {
buildRule.executeTarget("istrue-incomplete");
fail("BuildException should have been thrown - Missing attribute");
} catch (BuildException ex) {
assertEquals("Nothing to test for truth", ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("Nothing to test for truth");
buildRule.executeTarget("istrue-incomplete");
} }


@Test @Test
@@ -319,12 +300,9 @@ public class ConditionTest {


@Test @Test
public void testIsfalseIncomplete1() { public void testIsfalseIncomplete1() {
try {
buildRule.executeTarget("isfalse-incomplete");
fail("BuildException should have been thrown - Missing attribute");
} catch (BuildException ex) {
assertEquals("Nothing to test for falsehood", ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("Nothing to test for falsehood");
buildRule.executeTarget("isfalse-incomplete");
} }


@Test @Test
@@ -332,14 +310,10 @@ public class ConditionTest {
buildRule.executeTarget("testElse"); buildRule.executeTarget("testElse");
} }


@Test
@Test(expected = BuildException.class)
public void testResourcesmatchError() { public void testResourcesmatchError() {
try {
buildRule.executeTarget("resourcematch-error");
fail("BuildException should have been thrown - no resources specified");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("resourcematch-error");
// TODO assert value
} }


@Test @Test


+ 24
- 29
src/tests/junit/org/apache/tools/ant/taskdefs/CopydirTest.java View File

@@ -26,7 +26,6 @@ import org.junit.Test;
import java.io.File; import java.io.File;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;




@@ -40,34 +39,31 @@ public class CopydirTest {
buildRule.executeTarget("setUp"); buildRule.executeTarget("setUp");
} }


@Test
/**
* Expected failure due to required argument not specified
*/
@Test(expected = BuildException.class)
public void test1() { public void test1() {
try {
buildRule.executeTarget("test1");
fail("Required argument not specified");
} catch (BuildException ex) {
// TODO assert value
}
buildRule.executeTarget("test1");
// TODO Assert exception message
} }


@Test
/**
* Expected failure due to required argument not specified
*/
@Test(expected = BuildException.class)
public void test2() { public void test2() {
try {
buildRule.executeTarget("test2");
fail("Required argument not specified");
} catch (BuildException ex) {
// TODO assert value
}
buildRule.executeTarget("test2");
// TODO Assert exception message
} }


@Test
/**
* Expected failure due to required argument not specified
*/
@Test(expected = BuildException.class)
public void test3() { public void test3() {
try {
buildRule.executeTarget("test3");
fail("Required argument not specified");
} catch (BuildException ex) {
// TODO assert value
}
buildRule.executeTarget("test3");
// TODO Assert exception message
} }


@Test @Test
@@ -86,14 +82,13 @@ public class CopydirTest {
// We keep this, so we have something to delete in later tests :-) // We keep this, so we have something to delete in later tests :-)
} }


@Test
/**
* expected failure because target is file
*/
@Test(expected = BuildException.class)
public void test6() { public void test6() {
try {
buildRule.executeTarget("test6");
fail("target is file");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test6");
// TODO Assert exception message
} }


} }

+ 15
- 34
src/tests/junit/org/apache/tools/ant/taskdefs/CopyfileTest.java View File

@@ -26,7 +26,7 @@ import org.junit.Test;
import java.io.File; import java.io.File;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertTrue;


/** /**
*/ */
@@ -40,34 +40,22 @@ public class CopyfileTest {
buildRule.executeTarget("setUp"); buildRule.executeTarget("setUp");
} }


@Test
@Test(expected = BuildException.class)
public void test1() { public void test1() {
try {
buildRule.executeTarget("test1");
fail("Required argument not specified");
} catch (BuildException ex) {
// TODO assert value
}
buildRule.executeTarget("test1");
// TODO assert value
} }


@Test
@Test(expected = BuildException.class)
public void test2() { public void test2() {
try {
buildRule.executeTarget("test2");
fail("Required argument not specified");
} catch (BuildException ex) {
// TODO assert value
}
buildRule.executeTarget("test2");
// TODO assert value
} }


@Test
@Test(expected = BuildException.class)
public void test3() { public void test3() {
try {
buildRule.executeTarget("test3");
fail("Required argument not specified");
} catch (BuildException ex) {
// TODO assert value
}
buildRule.executeTarget("test3");
// TODO assert value
} }


@Test @Test
@@ -81,20 +69,13 @@ public class CopyfileTest {
public void test5() { public void test5() {
buildRule.executeTarget("test5"); buildRule.executeTarget("test5");
File f = new File(new File(buildRule.getProject().getProperty("output")), "copyfile.tmp"); File f = new File(new File(buildRule.getProject().getProperty("output")), "copyfile.tmp");
if (f.exists()) {
f.delete();
} else {
fail("Copy failed");
}
assertTrue("Copy failed", f.exists());
f.delete();
} }


@Test
@Test(expected = BuildException.class)
public void test6() { public void test6() {
try {
buildRule.executeTarget("test6");
fail("Required argument not specified");
} catch (BuildException ex) {
// TODO assert value
}
buildRule.executeTarget("test6");
// TODO assert value
} }
} }

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

@@ -24,8 +24,6 @@ import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;


import static org.junit.Assert.fail;

/** /**
*/ */
public class DeleteTest { public class DeleteTest {
@@ -38,73 +36,86 @@ public class DeleteTest {
buildRule.configureProject("src/etc/testcases/taskdefs/delete.xml"); buildRule.configureProject("src/etc/testcases/taskdefs/delete.xml");
} }


@Test
/**
* Expected failure due to required argument not specified
*/
@Test(expected = BuildException.class)
public void test1() { public void test1() {
try {
buildRule.executeTarget("test1");
fail("required argument not specified");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test1");
// TODO Assert exception message
} }


@Test @Test
public void test2() { public void test2() {
buildRule.executeTarget("test2"); buildRule.executeTarget("test2");
} }

//where oh where has my test case 3 gone? //where oh where has my test case 3 gone?
@Test @Test
public void test4() { public void test4() {
buildRule.executeTarget("test4"); buildRule.executeTarget("test4");
} }

@Test @Test
public void test5() { public void test5() {
buildRule.executeTarget("test5"); buildRule.executeTarget("test5");
} }

@Test @Test
public void test6() { public void test6() {
buildRule.executeTarget("test6"); buildRule.executeTarget("test6");
} }

@Test @Test
public void test7() { public void test7() {
buildRule.executeTarget("test7"); buildRule.executeTarget("test7");
} }

@Test @Test
public void test8() { public void test8() {
buildRule.executeTarget("test8"); buildRule.executeTarget("test8");
} }

@Test @Test
public void test9() { public void test9() {
buildRule.executeTarget("test9"); buildRule.executeTarget("test9");
} }

@Test @Test
public void test10() { public void test10() {
buildRule.executeTarget("test10"); buildRule.executeTarget("test10");
} }

@Test @Test
public void test11() { public void test11() {
buildRule.executeTarget("test11"); buildRule.executeTarget("test11");
} }

@Test @Test
public void test12() { public void test12() {
buildRule.executeTarget("test12"); buildRule.executeTarget("test12");
} }

@Test @Test
public void test13() { public void test13() {
buildRule.executeTarget("test13"); buildRule.executeTarget("test13");
} }

@Test @Test
public void test14() { public void test14() {
buildRule.executeTarget("test14"); buildRule.executeTarget("test14");
} }

@Test @Test
public void test15() { public void test15() {
buildRule.executeTarget("test15"); buildRule.executeTarget("test15");
} }

@Test @Test
public void test16() { public void test16() {
buildRule.executeTarget("test16"); buildRule.executeTarget("test16");
} }

@Test @Test
public void test17() { public void test17() {
buildRule.executeTarget("test17"); buildRule.executeTarget("test17");


+ 6
- 9
src/tests/junit/org/apache/tools/ant/taskdefs/DeltreeTest.java View File

@@ -24,8 +24,6 @@ import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;


import static org.junit.Assert.fail;

public class DeltreeTest { public class DeltreeTest {


@Rule @Rule
@@ -36,14 +34,13 @@ public class DeltreeTest {
buildRule.configureProject("src/etc/testcases/taskdefs/deltree.xml"); buildRule.configureProject("src/etc/testcases/taskdefs/deltree.xml");
} }


@Test
/**
* Expected failure due to missing required argument
*/
@Test(expected = BuildException.class)
public void test1() { public void test1() {
try {
buildRule.executeTarget("test1");
fail("required argument not specified");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test1");
// TODO Assert exception message
} }


@Test @Test


+ 17
- 25
src/tests/junit/org/apache/tools/ant/taskdefs/DirnameTest.java View File

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


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeFalse;


import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
@@ -28,6 +27,7 @@ import org.apache.tools.ant.taskdefs.condition.Os;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;


import java.io.File; import java.io.File;


@@ -35,6 +35,9 @@ import java.io.File;
*/ */
public class DirnameTest { public class DirnameTest {


@Rule
public ExpectedException thrown = ExpectedException.none();

@Rule @Rule
public BuildFileRule buildRule = new BuildFileRule(); public BuildFileRule buildRule = new BuildFileRule();


@@ -45,49 +48,38 @@ public class DirnameTest {


@Test @Test
public void test1() { public void test1() {
try {
buildRule.executeTarget("test1");
fail("Build exception should have been thrown as property attribute is required");
} catch (BuildException ex) {
assertEquals("property attribute required", ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("property attribute required");
buildRule.executeTarget("test1");
} }


@Test @Test
public void test2() { public void test2() {
try {
buildRule.executeTarget("test2");
fail("Build exception should have been thrown as file attribute is required");
} catch (BuildException ex) {
assertEquals("file attribute required", ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("file attribute required");
buildRule.executeTarget("test2");
} }


@Test @Test
public void test3() { public void test3() {
try {
buildRule.executeTarget("test3");
fail("Build exception should have been thrown as property attribute is required");
} catch (BuildException ex) {
assertEquals("property attribute required", ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("property attribute required");
buildRule.executeTarget("test3");
} }


@Test @Test
public void test4() { public void test4() {
assumeFalse("Test not possible on DOS or Netware family OS", Os.isFamily("netware") || Os.isFamily("dos")); assumeFalse("Test not possible on DOS or Netware family OS", Os.isFamily("netware") || Os.isFamily("dos"));
buildRule.executeTarget("test4"); buildRule.executeTarget("test4");
String expected = File.separator + "usr" + File.separator + "local";
String checkprop = buildRule.getProject().getProperty("local.dir");
assertEquals("dirname failed", expected, checkprop);
assertEquals("dirname failed", File.separator + "usr" + File.separator + "local",
buildRule.getProject().getProperty("local.dir"));
} }


@Test @Test
public void test5() { public void test5() {
buildRule.executeTarget("test5"); buildRule.executeTarget("test5");
String expected = buildRule.getProject().getProperty("basedir");
String checkprop = buildRule.getProject().getProperty("base.dir");
assertEquals("dirname failed", expected, checkprop);
assertEquals("dirname failed", buildRule.getProject().getProperty("basedir"),
buildRule.getProject().getProperty("base.dir"));
} }


} }

+ 44
- 79
src/tests/junit/org/apache/tools/ant/taskdefs/FailTest.java View File

@@ -23,16 +23,17 @@ import org.apache.tools.ant.BuildFileRule;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;


import java.util.Arrays; import java.util.Arrays;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

/** /**
*/ */
public class FailTest { public class FailTest {


@Rule
public ExpectedException thrown = ExpectedException.none();

@Rule @Rule
public final BuildFileRule buildRule = new BuildFileRule(); public final BuildFileRule buildRule = new BuildFileRule();


@@ -43,57 +44,42 @@ public class FailTest {


@Test @Test
public void test1() { public void test1() {
try {
buildRule.executeTarget("test1");
fail("it is required to fail :-)");
} catch (BuildException ex) {
assertEquals("No message", ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("No message");
buildRule.executeTarget("test1");
} }


@Test @Test
public void test2() { public void test2() {
try {
buildRule.executeTarget("test2");
fail("it is required to fail :-)");
} catch (BuildException ex) {
assertEquals("test2", ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("test2");
buildRule.executeTarget("test2");
} }


@Test @Test
public void testText() { public void testText() {
try {
buildRule.executeTarget("testText");
fail("it is required to fail :-)");
} catch (BuildException ex) {
assertEquals("testText", ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("testText");
buildRule.executeTarget("testText");
} }


@Test
@Test(expected = BuildException.class)
public void testIf() { public void testIf() {
buildRule.executeTarget("testIf"); buildRule.executeTarget("testIf");
buildRule.getProject().setProperty("foo", ""); buildRule.getProject().setProperty("foo", "");
try {
buildRule.executeTarget("testIf");
fail("testIf must fail if foo has been set");
} catch (BuildException ex) {
//TODO assert result
}
buildRule.executeTarget("testIf");
// TODO assert result
} }


@Test
@Test(expected = BuildException.class)
public void testUnless() { public void testUnless() {
try { try {
buildRule.executeTarget("testUnless"); buildRule.executeTarget("testUnless");
fail("testUnless must fail unless foo has been set");
} catch (BuildException ex) {
//TODO assert rules //TODO assert rules
} finally {
buildRule.getProject().setProperty("foo", "");
buildRule.executeTarget("testUnless");
} }
buildRule.getProject().setProperty("foo", "");
buildRule.executeTarget("testUnless");

} }


/** /**
@@ -103,18 +89,18 @@ public class FailTest {
*/ */
@Test @Test
public void testIfAndUnless() { public void testIfAndUnless() {
thrown.expect(BuildException.class);
thrown.expectMessage("if=if and unless=unless");
//neither //neither
buildRule.executeTarget("testIfAndUnless"); buildRule.executeTarget("testIfAndUnless");
buildRule.getProject().setProperty("if", ""); buildRule.getProject().setProperty("if", "");
try { try {
buildRule.executeTarget("testIfAndUnless"); buildRule.executeTarget("testIfAndUnless");
fail("expect fail on defined(if)");
} catch (BuildException ex) {
assertEquals("if=if and unless=unless", ex.getMessage());
} finally {
buildRule.getProject().setProperty("unless", "");
//this call should succeed as unless overrides if
buildRule.executeTarget("testIfAndUnless");
} }
buildRule.getProject().setProperty("unless", "");
//this call should succeed as unless overrides if
buildRule.executeTarget("testIfAndUnless");
} }
/** /**
* see that the different combinations work, and * see that the different combinations work, and
@@ -129,12 +115,9 @@ public class FailTest {


@Test @Test
public void testNested1() { public void testNested1() {
try {
buildRule.executeTarget("testNested1");
fail("it is required to fail :-)");
} catch (BuildException ex) {
assertEquals("condition satisfied", ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("condition satisfied");
buildRule.executeTarget("testNested1");
} }


@Test @Test
@@ -144,64 +127,46 @@ public class FailTest {


@Test @Test
public void testNested3() { public void testNested3() {
try {
buildRule.executeTarget("testNested3");
fail("it is required to fail :-)");
} catch (BuildException ex) {
assertEquals("testNested3", ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("testNested3");
buildRule.executeTarget("testNested3");
} }


@Test @Test
public void testNested4() { public void testNested4() {
String specificMessage = "Nested conditions "
+ "not permitted in conjunction with if/unless attributes";
thrown.expect(BuildException.class);
thrown.expectMessage("Nested conditions not permitted in conjunction with if/unless attributes");


StringBuilder target = new StringBuilder("testNested4x"); StringBuilder target = new StringBuilder("testNested4x");
for (char ch : Arrays.asList('a', 'b', 'c')) { for (char ch : Arrays.asList('a', 'b', 'c')) {
target.setCharAt(target.length() - 1, ch); target.setCharAt(target.length() - 1, ch);
try {
buildRule.executeTarget(target.toString());
fail("it is required to fail :-)");
} catch (BuildException ex) {
assertEquals(specificMessage, ex.getMessage());
}
buildRule.executeTarget(target.toString());
} }
} }


@Test @Test
public void testNested5() { public void testNested5() {
try {
buildRule.executeTarget("testNested5");
fail("it is required to fail :-)");
} catch (BuildException ex) {
assertEquals("Only one nested condition is allowed.", ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("Only one nested condition is allowed.");
buildRule.executeTarget("testNested5");
} }


@Test @Test
public void testNested6() { public void testNested6() {
try {
buildRule.executeTarget("testNested6");
fail("it is required to fail :-)");
} catch (BuildException ex) {
assertEquals("testNested6\ntestNested6\ntestNested6", ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("testNested6\ntestNested6\ntestNested6");
buildRule.executeTarget("testNested6");
} }


@Test @Test
public void testNested7() { public void testNested7() {
String specificMessage = "A single nested condition is required.";
thrown.expect(BuildException.class);
thrown.expectMessage("A single nested condition is required.");


StringBuilder target = new StringBuilder("testNested7x"); StringBuilder target = new StringBuilder("testNested7x");
for (char ch : Arrays.asList('a', 'b')) { for (char ch : Arrays.asList('a', 'b')) {
target.setCharAt(target.length() - 1, ch); target.setCharAt(target.length() - 1, ch);
try {
buildRule.executeTarget(target.toString());
fail("it is required to fail :-)");
} catch (BuildException ex) {
assertEquals(specificMessage, ex.getMessage());
}
buildRule.executeTarget(target.toString());
} }
} }




+ 18
- 39
src/tests/junit/org/apache/tools/ant/taskdefs/FilterTest.java View File

@@ -32,8 +32,8 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;


public class FilterTest { public class FilterTest {


@@ -50,34 +50,22 @@ public class FilterTest {
buildRule.executeTarget("cleanup"); buildRule.executeTarget("cleanup");
} }


@Test
@Test(expected = BuildException.class)
public void test1() { public void test1() {
try {
buildRule.executeTarget("test1");
fail("required argument missing");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test1");
// TODO assert value
} }


@Test
@Test(expected = BuildException.class)
public void test2() { public void test2() {
try {
buildRule.executeTarget("test2");
fail("required argument missing");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test2");
// TODO assert value
} }


@Test
@Test(expected = BuildException.class)
public void test3() { public void test3() {
try {
buildRule.executeTarget("test3");
fail("required argument missing");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test3");
// TODO assert value
} }


@Test @Test
@@ -122,24 +110,15 @@ public class FilterTest {
} }


private String getFilteredFile(String testNumber, String filteredFile) { private String getFilteredFile(String testNumber, String filteredFile) {

String line = null; String line = null;
File f = new File(buildRule.getProject().getBaseDir(), filteredFile); File f = new File(buildRule.getProject().getBaseDir(), filteredFile);
if (!f.exists()) {
fail("filter test" + testNumber + " failed");
} else {
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(f));
} catch (FileNotFoundException fnfe) {
fail("filter test" + testNumber + " failed, filtered file: " + f.toString() + " not found");
}
try {
line = in.readLine();
in.close();
} catch (IOException ioe) {
fail("filter test" + testNumber + " failed. IOException while reading filtered file: " + ioe);
}
assertTrue("filter test" + testNumber + " failed", f.exists());

try (BufferedReader in = new BufferedReader(new FileReader(f))) {
line = in.readLine();
} catch (IOException ioe) {
assertNotNull("filter test" + testNumber
+ " failed. IOException while reading filtered file: " + ioe, line);
} }
f.delete(); f.delete();
return line; return line;


+ 12
- 15
src/tests/junit/org/apache/tools/ant/taskdefs/GUnzipTest.java View File

@@ -28,7 +28,6 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;


public class GUnzipTest { public class GUnzipTest {


@@ -45,24 +44,22 @@ public class GUnzipTest {
buildRule.executeTarget("cleanup"); buildRule.executeTarget("cleanup");
} }


@Test
/**
* Expected failure due to missing required argument
*/
@Test(expected = BuildException.class)
public void test1() { public void test1() {
try {
buildRule.executeTarget("test1");
fail("required argument missing");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test1");
// TODO Assert exception message
} }


@Test
/**
* Expected failure due to invalid attribute
*/
@Test(expected = BuildException.class)
public void test2() { public void test2() {
try {
buildRule.executeTarget("test2");
fail("attribute src invalid");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test2");
// TODO Assert exception message
} }


@Test @Test


+ 9
- 14
src/tests/junit/org/apache/tools/ant/taskdefs/InputTest.java View File

@@ -29,26 +29,25 @@ import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;



public class InputTest { public class InputTest {


@Rule
public ExpectedException thrown = ExpectedException.none();

@Rule @Rule
public final BuildFileRule buildRule = new BuildFileRule(); public final BuildFileRule buildRule = new BuildFileRule();


private InputStream originalStdIn; private InputStream originalStdIn;



@Before @Before
public void setUp() { public void setUp() {
buildRule.configureProject("src/etc/testcases/taskdefs/input.xml"); buildRule.configureProject("src/etc/testcases/taskdefs/input.xml");
System.getProperties()
.put(PropertyFileInputHandler.FILE_NAME_KEY,
buildRule.getProject().resolveFile("input.properties")
.getAbsolutePath());
System.getProperties().put(PropertyFileInputHandler.FILE_NAME_KEY,
buildRule.getProject().resolveFile("input.properties").getAbsolutePath());
buildRule.getProject().setInputHandler(new PropertyFileInputHandler()); buildRule.getProject().setInputHandler(new PropertyFileInputHandler());
originalStdIn = System.in; originalStdIn = System.in;
} }
@@ -70,13 +69,9 @@ public class InputTest {


@Test @Test
public void test3() { public void test3() {
try {
buildRule.executeTarget("test3");
fail("BuildException expected: invalid input");
} catch (BuildException ex) {
assertEquals("Found invalid input test for 'All data is going to be deleted from DB continue?'",
ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("Found invalid input test for 'All data is going to be deleted from DB continue?'");
buildRule.executeTarget("test3");
} }


@Test @Test


+ 14
- 21
src/tests/junit/org/apache/tools/ant/taskdefs/MkdirTest.java View File

@@ -19,14 +19,14 @@ package org.apache.tools.ant.taskdefs;


import java.io.File; import java.io.File;


import static org.junit.Assert.assertTrue;

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


import static org.junit.Assert.fail;

/** /**
*/ */
public class MkdirTest { public class MkdirTest {
@@ -39,34 +39,27 @@ public class MkdirTest {
buildRule.configureProject("src/etc/testcases/taskdefs/mkdir.xml"); buildRule.configureProject("src/etc/testcases/taskdefs/mkdir.xml");
} }


@Test
/**
* Expected failure due to required argument missing
*/
@Test(expected = BuildException.class)
public void test1() { public void test1() {
try {
buildRule.executeTarget("test1");
fail("BuildException expected: required argument missing");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test1");
} }


@Test
/**
* Expected failure due to directory already existing as a file
*/
@Test(expected = BuildException.class)
public void test2() { public void test2() {
try {
buildRule.executeTarget("test2");
fail("BuildException expected: directory already exists as a file");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test2");
} }


@Test @Test
public void test3() { public void test3() {
buildRule.executeTarget("test3"); buildRule.executeTarget("test3");
File f = new File(buildRule.getProject().getProperty("output"), "testdir.tmp"); File f = new File(buildRule.getProject().getProperty("output"), "testdir.tmp");
if (!f.exists() || !f.isDirectory()) {
fail("mkdir failed");
} else {
f.delete();
}
assertTrue("mkdir failed", f.exists() && f.isDirectory());
f.delete();
} }
} }

+ 22
- 30
src/tests/junit/org/apache/tools/ant/taskdefs/RenameTest.java View File

@@ -24,8 +24,6 @@ import org.junit.Ignore;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;


import static org.junit.Assert.fail;

public class RenameTest { public class RenameTest {


@Rule @Rule
@@ -36,43 +34,37 @@ public class RenameTest {
buildRule.configureProject("src/etc/testcases/taskdefs/rename.xml"); buildRule.configureProject("src/etc/testcases/taskdefs/rename.xml");
} }


@Test
/**
* Expected failure due to missing required argument
*/
@Test(expected = BuildException.class)
public void test1() { public void test1() {
try {
buildRule.executeTarget("test1");
fail("BuildException should have been thrown: required argument missing");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test1");
} }
@Test

/**
* Expected failure due to missing required argument
*/
@Test(expected = BuildException.class)
public void test2() { public void test2() {
try {
buildRule.executeTarget("test2");
fail("BuildException should have been thrown: required argument missing");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test2");
} }
@Test

/**
* Expected failure due to missing required argument
*/
@Test(expected = BuildException.class)
public void test3() { public void test3() {
try {
buildRule.executeTarget("test3");
fail("BuildException should have been thrown: required argument missing");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test3");
} }


@Test
/**
* Expected failure due to source same as destination
*/
@Ignore("Previously commented out") @Ignore("Previously commented out")
@Test
public void test4() { public void test4() {
try {
buildRule.executeTarget("test4");
fail("BuildException should have been thrown: source and destination the same");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test4");
} }


@Test @Test


+ 36
- 45
src/tests/junit/org/apache/tools/ant/taskdefs/ReplaceTest.java View File

@@ -24,8 +24,6 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;


import junit.framework.AssertionFailedError;

import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildFileRule; import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;
@@ -35,7 +33,6 @@ import org.junit.Test;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;


/** /**
@@ -51,44 +48,40 @@ public class ReplaceTest {
buildRule.executeTarget("setUp"); buildRule.executeTarget("setUp");
} }


@Test
/**
* Fail: required argument not specified
*/
@Test(expected = BuildException.class)
public void test1() { public void test1() {
try {
buildRule.executeTarget("test1");
fail("BuildException expected: required argument not specified");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test1");
// TODO assert value
} }


@Test
/**
* Fail: required argument not specified
*/
@Test(expected = BuildException.class)
public void test2() { public void test2() {
try {
buildRule.executeTarget("test2");
fail("BuildException expected: required argument not specified");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test2");
// TODO assert value
} }


@Test
/**
* Fail: required argument not specified
*/
@Test(expected = BuildException.class)
public void test3() { public void test3() {
try {
buildRule.executeTarget("test3");
fail("BuildException expected: required argument not specified");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test3");
// TODO assert value
} }


@Test
/**
* Fail: empty token not allowed
*/
@Test(expected = BuildException.class)
public void test4() { public void test4() {
try {
buildRule.executeTarget("test4");
fail("BuildException expected: empty token not allowed");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test4");
// TODO assert value
} }


@Test @Test
@@ -96,24 +89,22 @@ public class ReplaceTest {
buildRule.executeTarget("test5"); buildRule.executeTarget("test5");
} }


@Test
/**
* Fail: required argument not specified
*/
@Test(expected = BuildException.class)
public void test6() { public void test6() {
try {
buildRule.executeTarget("test6");
fail("BuildException expected: required argument not specified");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test6");
// TODO assert value
} }


@Test
/**
* Fail: empty token not allowed
*/
@Test(expected = BuildException.class)
public void test7() { public void test7() {
try {
buildRule.executeTarget("test7");
fail("BuildException expected: empty token not allowed");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test7");
// TODO assert value
} }


@Test @Test


+ 7
- 7
src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java View File

@@ -25,12 +25,12 @@ import org.apache.tools.ant.BuildFileRule;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeFalse;


/** /**
@@ -42,6 +42,9 @@ public class SignJarTest {
@Rule @Rule
public BuildFileRule buildRule = new BuildFileRule(); public BuildFileRule buildRule = new BuildFileRule();


@Rule
public ExpectedException thrown = ExpectedException.none();

@Before @Before
public void setUp() { public void setUp() {
buildRule.configureProject("src/etc/testcases/taskdefs/signjar.xml"); buildRule.configureProject("src/etc/testcases/taskdefs/signjar.xml");
@@ -106,12 +109,9 @@ public class SignJarTest {


@Test @Test
public void testTsaLocalhost() { public void testTsaLocalhost() {
try {
buildRule.executeTarget("testTsaLocalhost");
fail("Should have thrown exception - no TSA at localhost:0");
} catch (BuildException ex) {
assertEquals("jarsigner returned: 1", ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("jarsigner returned: 1");
buildRule.executeTarget("testTsaLocalhost");
} }


/** /**


+ 8
- 10
src/tests/junit/org/apache/tools/ant/taskdefs/SleepTest.java View File

@@ -18,15 +18,14 @@


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


import static org.junit.Assert.assertTrue;

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


import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

public class SleepTest { public class SleepTest {


@Rule @Rule
@@ -72,14 +71,13 @@ public class SleepTest {
assertTrue(timer.time() >= (2000 - ERROR_RANGE) && timer.time() < 60000); assertTrue(timer.time() >= (2000 - ERROR_RANGE) && timer.time() < 60000);
} }


@Test
/**
* Expected failure: negative sleep periods are not supported
*/
@Test(expected = BuildException.class)
public void test5() { public void test5() {
try {
buildRule.executeTarget("test5");
fail("Negative sleep periods are not supported");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test5");
// TODO assert value
} }


@Test @Test


+ 18
- 17
src/tests/junit/org/apache/tools/ant/taskdefs/StyleTest.java View File

@@ -27,13 +27,12 @@ import org.apache.tools.ant.FileUtilities;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;


import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;




/** /**
@@ -46,21 +45,23 @@ public class StyleTest {
@Rule @Rule
public final BuildFileRule buildRule = new BuildFileRule(); public final BuildFileRule buildRule = new BuildFileRule();


@Rule
public ExpectedException thrown = ExpectedException.none();

@Before @Before
public void setUp() { public void setUp() {
buildRule.configureProject("src/etc/testcases/taskdefs/style/build.xml"); buildRule.configureProject("src/etc/testcases/taskdefs/style/build.xml");
} }


/**
* Expected failure: no stylesheet specified
*/
@Test @Test
public void testStyleIsSet() { public void testStyleIsSet() {

try {
buildRule.executeTarget("testStyleIsSet");
fail("Must throws a BuildException: no stylesheet specified");
} catch (BuildException ex) {
assertEquals("specify the stylesheet either as a filename in style attribute or as a nested resource",
ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("specify the stylesheet either as a filename in style attribute or "
+ "as a nested resource");
buildRule.executeTarget("testStyleIsSet");
} }


@Test @Test
@@ -145,15 +146,15 @@ public class StyleTest {
.exists()); .exists());
} }


/**
* Expected failure: stylesheet specified twice
*/
@Test @Test
public void testWithStyleAttrAndResource() { public void testWithStyleAttrAndResource() {
try {
buildRule.executeTarget("testWithStyleAttrAndResource");
fail("Must throws a BuildException");
} catch (BuildException ex) {
assertEquals("specify the stylesheet either as a filename in style attribute or as a "
+ "nested resource but not as both", ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("specify the stylesheet either as a filename in style attribute or "
+ "as a nested resource but not as both");
buildRule.executeTarget("testWithStyleAttrAndResource");
} }


@Test @Test


+ 36
- 43
src/tests/junit/org/apache/tools/ant/taskdefs/TarTest.java View File

@@ -29,7 +29,6 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;


public class TarTest { public class TarTest {
@@ -43,44 +42,40 @@ public class TarTest {
buildRule.executeTarget("setUp"); buildRule.executeTarget("setUp");
} }


@Test
/**
* Expected failure: required argument not specified
*/
@Test(expected = BuildException.class)
public void test1() { public void test1() {
try {
buildRule.executeTarget("test1");
fail("BuildException expected: required argument not specified");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test1");
// TODO assert value
} }


@Test
/**
* Expected failure: required argument not specified
*/
@Test(expected = BuildException.class)
public void test2() { public void test2() {
try {
buildRule.executeTarget("test2");
fail("BuildException expected: required argument not specified");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test2");
// TODO assert value
} }


@Test
/**
* Expected failure: required argument not specified
*/
@Test(expected = BuildException.class)
public void test3() { public void test3() {
try {
buildRule.executeTarget("test3");
fail("BuildException expected: required argument not specified");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test3");
// TODO assert value
} }


@Test
/**
* Expected failure: tar cannot include itself
*/
@Test(expected = BuildException.class)
public void test4() { public void test4() {
try {
buildRule.executeTarget("test4");
fail("BuildException expected: tar cannot include itself");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test4");
// TODO assert value
} }


@Test @Test
@@ -90,14 +85,13 @@ public class TarTest {
assertTrue("Tarring a directory failed", f.exists()); assertTrue("Tarring a directory failed", f.exists());
} }


@Test
/**
* Expected failure due to invalid value specified for longfile attribute.
*/
@Test(expected = BuildException.class)
public void test6() { public void test6() {
try {
buildRule.executeTarget("test6");
fail("BuildException expected: Invalid value specified for longfile attribute.");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test6");
// TODO assert value
} }


@Test @Test
@@ -156,14 +150,13 @@ public class TarTest {
f1.exists()); f1.exists());
} }


@Test
/**
* Expected failure due to invalid value specified for compression attribute.
*/
@Test(expected = BuildException.class)
public void test9() { public void test9() {
try {
buildRule.executeTarget("test9");
fail("BuildException expected: Invalid value specified for compression attribute.");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test9");
// TODO assert value
} }


@Test @Test


+ 30
- 37
src/tests/junit/org/apache/tools/ant/taskdefs/TaskdefTest.java View File

@@ -20,7 +20,6 @@ package org.apache.tools.ant.taskdefs;


import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildFileRule; import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.Project;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@@ -28,7 +27,6 @@ import org.junit.Test;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;


/** /**
*/ */
@@ -42,54 +40,49 @@ public class TaskdefTest {
buildRule.configureProject("src/etc/testcases/taskdefs/taskdef.xml"); buildRule.configureProject("src/etc/testcases/taskdefs/taskdef.xml");
} }


@Test
/**
* Expected failure due lacking a required argument
*/
@Test(expected = BuildException.class)
public void test1() { public void test1() {
try {
buildRule.executeTarget("test1");
fail("BuildException expected: required argument not specified");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test1");
// TODO Assert exception message
} }


@Test
/**
* Expected failure due lacking a required argument
*/
@Test(expected = BuildException.class)
public void test2() { public void test2() {
try {
buildRule.executeTarget("test2");
fail("BuildException expected: required argument not specified");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test2");
// TODO Assert exception message
} }


@Test
/**
* Expected failure due lacking a required argument
*/
@Test(expected = BuildException.class)
public void test3() { public void test3() {
try {
buildRule.executeTarget("test3");
fail("BuildException expected: required argument not specified");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test3");
// TODO Assert exception message
} }


@Test
/**
* Expected failure due to nonexistent class specified
*/
@Test(expected = BuildException.class)
public void test4() { public void test4() {
try {
buildRule.executeTarget("test4");
fail("BuildException expected: classname specified doesn't exist");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test4");
// TODO Assert exception message
} }


@Test
/**
* Expected failure due to non-public execute() method
*/
@Test(expected = BuildException.class)
public void test5() { public void test5() {
try {
buildRule.executeTarget("test5");
fail("BuildException expected: No public execute() in " + Project.class);
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test5");
// TODO Assert exception message
} }


@Test @Test


+ 3
- 9
src/tests/junit/org/apache/tools/ant/taskdefs/UntarTest.java View File

@@ -30,8 +30,6 @@ import java.io.IOException;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;



public class UntarTest { public class UntarTest {


@@ -73,14 +71,10 @@ public class UntarTest {
testLogoExtraction("testBzip2TarTask"); testLogoExtraction("testBzip2TarTask");
} }


@Test
@Test(expected = BuildException.class)
public void testSrcDirTest() { public void testSrcDirTest() {
try {
buildRule.executeTarget("srcDirTest");
fail("Src cannot be a directory.");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("srcDirTest");
// TODO assert value
} }


@Test @Test


+ 24
- 32
src/tests/junit/org/apache/tools/ant/taskdefs/UnzipTest.java View File

@@ -31,7 +31,6 @@ import java.io.IOException;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;


public class UnzipTest { public class UnzipTest {


@@ -43,37 +42,33 @@ public class UnzipTest {
buildRule.configureProject("src/etc/testcases/taskdefs/unzip.xml"); buildRule.configureProject("src/etc/testcases/taskdefs/unzip.xml");
} }


@Test
/**
* Expected failure due to required argument not specified
*/
@Test(expected = BuildException.class)
public void test1() { public void test1() {
try {
buildRule.executeTarget("test1");
fail("BuildException expected: required argument not specified");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test1");
// TODO Assert exception message
} }


@Test
/**
* Expected failure due to required argument not specified
*/
@Test(expected = BuildException.class)
public void test2() { public void test2() {
try {
buildRule.executeTarget("test2");
fail("BuildException expected: required argument not specified");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test2");
// TODO Assert exception message
} }


@Test
/**
* Expected failure due to required argument not specified
*/
@Test(expected = BuildException.class)
public void test3() { public void test3() {
try {
buildRule.executeTarget("test3");
fail("BuildException expected: required argument not specified");
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("test3");
// TODO Assert exception message
} }



@Test @Test
public void testRealTest() throws IOException { public void testRealTest() throws IOException {
buildRule.executeTarget("realTest"); buildRule.executeTarget("realTest");
@@ -173,7 +168,6 @@ public class UnzipTest {
buildRule.executeTarget("selfExtractingArchive"); buildRule.executeTarget("selfExtractingArchive");
} }



/* /*
* PR 20969 * PR 20969
*/ */
@@ -186,7 +180,6 @@ public class UnzipTest {
buildRule.getProject().getProperty("output") + "/unziptestout/2/bar"); buildRule.getProject().getProperty("output") + "/unziptestout/2/bar");
} }



/* /*
* PR 10504 * PR 10504
*/ */
@@ -240,14 +233,13 @@ public class UnzipTest {
buildRule.getProject().getProperty("output") + "/unziptestout/1/foo.txt"); buildRule.getProject().getProperty("output") + "/unziptestout/1/foo.txt");
} }


@Test
/**
* Expected failure due to multiple mappers
*/
@Test(expected = BuildException.class)
public void testTwoMappers() { public void testTwoMappers() {
try {
buildRule.executeTarget("testTwoMappers");
fail("BuildException expected: " + Expand.ERROR_MULTIPLE_MAPPERS);
} catch (BuildException ex) {
//TODO assert value
}
buildRule.executeTarget("testTwoMappers");
// TODO Assert exception message
} }


@Test @Test


+ 9
- 9
src/tests/junit/org/apache/tools/ant/taskdefs/XmlnsTest.java View File

@@ -18,15 +18,15 @@


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


import static org.junit.Assert.assertEquals;

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

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.rules.ExpectedException;




public class XmlnsTest { public class XmlnsTest {
@@ -34,6 +34,9 @@ public class XmlnsTest {
@Rule @Rule
public final BuildFileRule buildRule = new BuildFileRule(); public final BuildFileRule buildRule = new BuildFileRule();


@Rule
public ExpectedException thrown = ExpectedException.none();

@Before @Before
public void setUp() { public void setUp() {
buildRule.configureProject("src/etc/testcases/taskdefs/xmlns.xml"); buildRule.configureProject("src/etc/testcases/taskdefs/xmlns.xml");
@@ -59,12 +62,9 @@ public class XmlnsTest {


@Test @Test
public void testExcluded() { public void testExcluded() {
try {
buildRule.executeTarget("excluded");
fail("BuildException expected: excluded uri");
} catch (BuildException ex) {
assertEquals("Attempt to use a reserved URI ant:notallowed", ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("Attempt to use a reserved URI ant:notallowed");
buildRule.executeTarget("excluded");
} }


@Test @Test


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

@@ -25,7 +25,6 @@ import org.junit.Test;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;


/** /**
* Testcases for the &lt;http&gt; condition. All these tests require * Testcases for the &lt;http&gt; condition. All these tests require
@@ -63,14 +62,12 @@ public class HttpTest {
assertNull(buildRule.getProject().getProperty("test-get-request-bad-url")); assertNull(buildRule.getProject().getProperty("test-get-request-bad-url"));
} }


@Test
/**
* Expected failure due to invalid HTTP request method specified
*/
@Test(expected = BuildException.class)
public void testBadRequestMethod() { public void testBadRequestMethod() {
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
}
buildRule.executeTarget("bad-request-method");
} }


} }

+ 10
- 7
src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReferenceTest.java View File

@@ -22,9 +22,9 @@ import org.apache.tools.ant.BuildFileRule;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;


/** /**
@@ -36,6 +36,9 @@ public class IsReferenceTest {
@Rule @Rule
public BuildFileRule buildRule = new BuildFileRule(); public BuildFileRule buildRule = new BuildFileRule();


@Rule
public ExpectedException thrown = ExpectedException.none();

@Before @Before
public void setUp() { public void setUp() {
buildRule.configureProject("src/etc/testcases/taskdefs/conditions/isreference.xml"); buildRule.configureProject("src/etc/testcases/taskdefs/conditions/isreference.xml");
@@ -49,14 +52,14 @@ public class IsReferenceTest {
assertNull(buildRule.getProject().getProperty("undefined")); assertNull(buildRule.getProject().getProperty("undefined"));
} }


/**
* Expected failure due to omitted refid attribute
*/
@Test @Test
public void testNotEnoughArgs() { public void testNotEnoughArgs() {
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());
}
thrown.expect(BuildException .class) ;
thrown.expectMessage("No reference specified for isreference condition");
buildRule.executeTarget("isreference-incomplete");
} }


@Test @Test


+ 13
- 21
src/tests/junit/org/apache/tools/ant/taskdefs/condition/ParserSupportsTest.java View File

@@ -24,9 +24,7 @@ import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.rules.ExpectedException;


/** /**


@@ -36,6 +34,9 @@ public class ParserSupportsTest {
@Rule @Rule
public BuildFileRule buildRule = new BuildFileRule(); public BuildFileRule buildRule = new BuildFileRule();


@Rule
public ExpectedException thrown = ExpectedException.none();

@Before @Before
public void setUp() { public void setUp() {
buildRule.configureProject("src/etc/testcases/taskdefs/conditions/parsersupports.xml"); buildRule.configureProject("src/etc/testcases/taskdefs/conditions/parsersupports.xml");
@@ -43,22 +44,16 @@ public class ParserSupportsTest {


@Test @Test
public void testEmpty() { 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());
}
thrown.expect(BuildException .class) ;
thrown.expectMessage(ParserSupports.ERROR_NO_ATTRIBUTES);
buildRule.executeTarget("testEmpty");
} }


@Test @Test
public void testBoth() { 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());
}
thrown.expect(BuildException .class) ;
thrown.expectMessage(ParserSupports.ERROR_BOTH_ATTRIBUTES);
buildRule.executeTarget("testBoth");
} }


@Test @Test
@@ -68,12 +63,9 @@ public class ParserSupportsTest {


@Test @Test
public void testPropertyNoValue() { 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());
}
thrown.expect(BuildException .class) ;
thrown.expectMessage(ParserSupports.ERROR_NO_VALUE);
buildRule.executeTarget("testPropertyNoValue");
} }


@Test @Test


+ 12
- 16
src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailTaskTest.java View File

@@ -24,8 +24,6 @@ import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;


import static org.junit.Assert.fail;

/** /**
* TODO : develop these testcases - the email task needs to have attributes allowing * 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 * to simulate sending mail and to catch the output in text files or streams
@@ -40,24 +38,22 @@ public class EmailTaskTest {
buildRule.configureProject("src/etc/testcases/taskdefs/email/mail.xml"); buildRule.configureProject("src/etc/testcases/taskdefs/email/mail.xml");
} }


@Test
/**
* Expected failure attempting SMTP auth without MIME
*/
@Test(expected = BuildException.class)
public void test1() { public void test1() {
try {
buildRule.executeTarget("test1");
fail("Build exception expected: SMTP auth only possibly with MIME mail");
} catch (BuildException ex) {
//TODO assert exception message
}
buildRule.executeTarget("test1");
// TODO Assert exception message
} }


@Test
/**
* Expected failure attempting SSL without MIME
*/
@Test(expected = BuildException.class)
public void test2() { public void test2() {
try {
buildRule.executeTarget("test2");
fail("Build exception expected: SSL only possibly with MIME mail");
} catch (BuildException ex) {
//TODO assert exception message
}
buildRule.executeTarget("test2");
// TODO Assert exception message
} }


} }

+ 30
- 40
src/tests/junit/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java View File

@@ -30,9 +30,8 @@ import java.io.FilenameFilter;


import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;


/** /**
* If you want to run tests, it is highly recommended * If you want to run tests, it is highly recommended
@@ -57,25 +56,23 @@ public class ANTLRTest {
buildRule.configureProject(TASKDEFS_DIR + "antlr.xml"); buildRule.configureProject(TASKDEFS_DIR + "antlr.xml");
} }


@Test
/**
* Expected failure due to missing required argument, target
*/
@Test(expected = BuildException.class)
public void test1() { public void test1() {
try {
buildRule.executeTarget("test1");
fail("required argument, target, missing");
} catch (BuildException ex) {
//TODO should check exception message
}
buildRule.executeTarget("test1");
// TODO Check exception message
} }


@Test
/**
* Expected failure due to invalid output directory
*/
@Test(expected = BuildException.class)
public void test2() { public void test2() {
try {
buildRule.executeTarget("test2");
fail("Invalid output directory");
} catch (BuildException ex) {
//TODO should check exception message
}
}
buildRule.executeTarget("test2");
// TODO Check exception message
}


@Test @Test
public void test3() { public void test3() {
@@ -87,16 +84,14 @@ public class ANTLRTest {
buildRule.executeTarget("test4"); buildRule.executeTarget("test4");
} }


@Test
/**
* should print "panic: Cannot find importVocab file 'JavaTokenTypes.txt'"
* since it needs to run java.g first before java.tree.g
*/
@Test(expected = BuildException.class)
public void test5() { public void test5() {
// should print "panic: Cannot find importVocab file 'JavaTokenTypes.txt'"
// since it needs to run java.g first before java.tree.g
try {
buildRule.executeTarget("test5");
fail("ANTLR returned: 1");
} catch (BuildException ex) {
//TODO should check exception message
}
buildRule.executeTarget("test5");
// TODO Check exception message
} }


@Test @Test
@@ -104,27 +99,22 @@ public class ANTLRTest {
buildRule.executeTarget("test6"); buildRule.executeTarget("test6");
} }


@Test
/**
* Expected failure due to inability to determine generated class
*/
@Test(expected = BuildException.class)
public void test7() { public void test7() {
try {
buildRule.executeTarget("test7");
fail("Unable to determine generated class");
} catch (BuildException ex) {
//TODO should check exception message
}
buildRule.executeTarget("test7");
// TODO Check exception message
} }


/** /**
* Expected failure due to invalid super grammar (glib) option. * Expected failure due to invalid super grammar (glib) option.
*/ */
@Test
@Test(expected = BuildException.class)
public void test8() { public void test8() {
try {
buildRule.executeTarget("test8");
fail("Invalid super grammar file");
} catch (BuildException ex) {
//TODO should check exception message
}
buildRule.executeTarget("test8");
// TODO Check exception message
} }


/** /**


+ 7
- 7
src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java View File

@@ -30,10 +30,10 @@ import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;


/** /**
* Tests the Jspc task. * Tests the Jspc task.
@@ -46,6 +46,9 @@ public class JspcTest {


private static final String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/"; private static final String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/";


@Rule
public ExpectedException thrown = ExpectedException.none();

@Rule @Rule
public BuildFileRule buildRule = new BuildFileRule(); public BuildFileRule buildRule = new BuildFileRule();


@@ -88,12 +91,9 @@ public class JspcTest {


@Test @Test
public void testNoTld() { public void testNoTld() {
try {
buildRule.executeTarget("testNoTld");
fail("Not found");
} catch (BuildException ex) {
assertEquals("Java returned: 9", ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage("Java returned: 9");
buildRule.executeTarget("testNoTld");
} }


@Test @Test


+ 10
- 16
src/tests/junit/org/apache/tools/ant/taskdefs/optional/PvcsTest.java View File

@@ -24,8 +24,6 @@ import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;


import static org.junit.Assert.fail;

public class PvcsTest { public class PvcsTest {


@Rule @Rule
@@ -36,14 +34,12 @@ public class PvcsTest {
buildRule.configureProject("src/etc/testcases/taskdefs/optional/pvcs.xml"); buildRule.configureProject("src/etc/testcases/taskdefs/optional/pvcs.xml");
} }


@Test
/**
* Expected failure due to missing argument "repository"
*/
@Test(expected = BuildException.class)
public void test1() { public void test1() {
try {
buildRule.executeTarget("test1"); buildRule.executeTarget("test1");
fail("Required argument repository not specified");
} catch (BuildException ex) {
//TODO check exception message
}
} }


@Test @Test
@@ -66,14 +62,12 @@ public class PvcsTest {
buildRule.executeTarget("test5"); buildRule.executeTarget("test5");
} }


@Test
/**
* Expected failure due to nonexistent directory structure
*/
@Test(expected = BuildException.class)
public void test6() { public void test6() {
try {
buildRule.executeTarget("test6");
fail("Failed executing: /never/heard/of/a/directory/structure/like/this/pcli lvf -z " +
"-aw -pr//ct4serv2/pvcs/monitor /. Exception: /never/heard/of/a/directory/structure/like/this/pcli: not found");
} catch (BuildException ex) {
//TODO assert exception message
}
buildRule.executeTarget("test6");
//TODO assert exception message
} }
} }

+ 2
- 9
src/tests/junit/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTaskTest.java View File

@@ -10,8 +10,6 @@ import org.junit.Test;


import java.io.File; import java.io.File;


import static org.junit.Assert.fail;

/** /**
* Tests the {@link JUnitLauncherTask} * Tests the {@link JUnitLauncherTask}
*/ */
@@ -72,14 +70,9 @@ public class JUnitLauncherTaskTest {
* Tests that when a test, that's configured with {@code haltOnFailure=true}, stops the build, when the * Tests that when a test, that's configured with {@code haltOnFailure=true}, stops the build, when the
* test fails * test fails
*/ */
@Test
@Test(expected = BuildException.class)
public void testFailureStopsBuild() { public void testFailureStopsBuild() {
try {
project.executeTarget("test-failure-stops-build");
fail("Test execution failure was expected to stop the build but didn't");
} catch (BuildException be) {
// expected
}
project.executeTarget("test-failure-stops-build");
} }


/** /**


+ 6
- 26
src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java View File

@@ -20,8 +20,6 @@ package org.apache.tools.ant.taskdefs.optional.net;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;


import java.io.File; import java.io.File;
@@ -613,17 +611,11 @@ public class FTPTest {
performConfigTest("configuration.3", expectedCounts); performConfigTest("configuration.3", expectedCounts);
} }


@Test
@Test(expected = BuildException.class)
public void testConfigurationLang() { public void testConfigurationLang() {
int[] expectedCounts = {1, 1, 0, 0, 0, 0, 1}; int[] expectedCounts = {1, 1, 0, 0, 0, 0, 1};
performConfigTest("configuration.lang.good", expectedCounts); performConfigTest("configuration.lang.good", expectedCounts);

try {
performConfigTest("configuration.lang.bad", expectedCounts);
fail("BuildException Expected");
} catch (Exception bx) {
assertTrue(bx instanceof BuildException);
}
performConfigTest("configuration.lang.bad", expectedCounts);
} }
/** /**
* Tests the systemTypeKey attribute. * Tests the systemTypeKey attribute.
@@ -757,21 +749,13 @@ public class FTPTest {


public void testGetWithSelectorRetryable1() { public void testGetWithSelectorRetryable1() {
buildRule.getProject().addTaskDefinition("ftp", oneFailureFTP.class); buildRule.getProject().addTaskDefinition("ftp", oneFailureFTP.class);
try {
buildRule.getProject().executeTarget("ftp-get-with-selector-retryable");
} catch (BuildException bx) {
fail("Two retries expected, failed after one.");
}
buildRule.getProject().executeTarget("ftp-get-with-selector-retryable");
} }


@Test @Test
public void testGetWithSelectorRetryable2() { public void testGetWithSelectorRetryable2() {
buildRule.getProject().addTaskDefinition("ftp", twoFailureFTP.class); buildRule.getProject().addTaskDefinition("ftp", twoFailureFTP.class);
try {
buildRule.getProject().executeTarget("ftp-get-with-selector-retryable");
} catch (BuildException bx) {
fail("Two retries expected, failed after two.");
}
buildRule.getProject().executeTarget("ftp-get-with-selector-retryable");
} }


/** /**
@@ -786,12 +770,8 @@ public class FTPTest {
@Test @Test
public void testGetWithSelectorRetryableRandom() { public void testGetWithSelectorRetryableRandom() {
buildRule.getProject().addTaskDefinition("ftp", randomFailureFTP.class); buildRule.getProject().addTaskDefinition("ftp", randomFailureFTP.class);
try {
buildRule.getProject().setProperty("ftp.retries", "forever");
buildRule.getProject().executeTarget("ftp-get-with-selector-retryable");
} catch (BuildException bx) {
fail("Retry forever specified, but failed.");
}
buildRule.getProject().setProperty("ftp.retries", "forever");
buildRule.getProject().executeTarget("ftp-get-with-selector-retryable");
} }


@Test @Test


+ 8
- 7
src/tests/junit/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java View File

@@ -28,9 +28,9 @@ import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;


/** /**
* Testcase to ensure that command line generation and required attributes are * Testcase to ensure that command line generation and required attributes are
@@ -54,8 +54,12 @@ public class SOSTest {
private static final String SOS_HOME = "/home/user/.sos"; private static final String SOS_HOME = "/home/user/.sos";
private static final String VERSION = "007"; private static final String VERSION = "007";


@Rule
public ExpectedException thrown = ExpectedException.none();

@Rule @Rule
public BuildFileRule buildRule = new BuildFileRule(); public BuildFileRule buildRule = new BuildFileRule();

private Project project; private Project project;


@Before @Before
@@ -317,12 +321,9 @@ public class SOSTest {


private void expectSpecificBuildException(String target, String errorMessage, private void expectSpecificBuildException(String target, String errorMessage,
String exceptionMessage) { String exceptionMessage) {
try {
buildRule.executeTarget(target);
fail(errorMessage);
} catch (BuildException ex) {
assertEquals(exceptionMessage, ex.getMessage());
}
thrown.expect(BuildException.class);
thrown.expectMessage(exceptionMessage);
buildRule.executeTarget(target);
} }


/** /**


+ 10
- 14
src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java View File

@@ -39,7 +39,6 @@ import org.junit.Test;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;


/** /**
* This is a unit test for the Scp task in Ant. It must be * This is a unit test for the Scp task in Ant. It must be
@@ -170,22 +169,19 @@ public class ScpTest {
scpTask.execute(); scpTask.execute();
} }


/**
* Expected failure due to invalid remoteToDir
*
* @throws IOException
*/
@Test(expected = BuildException.class)
public void testInvalidRemoteToDir() throws IOException {
scpTask.setRemoteTodir("host:/a/path/without/an/at");
}

@Test @Test
public void testRemoteToDir() { public void testRemoteToDir() {

// first try an invalid URI
try {
scpTask.setRemoteTodir("host:/a/path/without/an/at");
fail("Expected a BuildException to be thrown due to invalid"
+ " remoteToDir");
} catch (BuildException e) {
// expected
//TODO we should be asserting a value in here
}

// And this one should work
scpTask.setRemoteTodir("user:password@host:/a/path/with/an/at"); scpTask.setRemoteTodir("user:password@host:/a/path/with/an/at");
// no exception
} }


private void addCleanup(File file) { private void addCleanup(File file) {


+ 23
- 15
src/tests/junit/org/apache/tools/ant/types/CommandlineTest.java View File

@@ -19,10 +19,11 @@
package org.apache.tools.ant.types; package org.apache.tools.ant.types;


import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;


/** /**
@@ -30,6 +31,9 @@ import static org.junit.Assert.assertNotNull;
*/ */
public class CommandlineTest { public class CommandlineTest {


@Rule
public ExpectedException thrown = ExpectedException.none();

@Test @Test
public void testTokenizer() { public void testTokenizer() {
String[] s = Commandline.translateCommandline("1 2 3"); String[] s = Commandline.translateCommandline("1 2 3");
@@ -100,22 +104,26 @@ public class CommandlineTest {
s = Commandline.translateCommandline("\'\'"); s = Commandline.translateCommandline("\'\'");
assertEquals("Singlequoted null arg", 1, s.length); assertEquals("Singlequoted null arg", 1, s.length);
assertEquals("Singlequoted null arg", "", s[0]); assertEquals("Singlequoted null arg", "", s[0]);
}


// now to the expected failures

try {
Commandline.translateCommandline("a \'b c");
fail("unbalanced single quotes undetected");
} catch (BuildException be) {
assertEquals("unbalanced quotes in a \'b c", be.getMessage());
}
/**
* Expected failure due to unbalanced single quote
*/
@Test
public void testTokenizerUnbalancedSingleQuote() {
thrown.expect(BuildException.class);
thrown.expectMessage("unbalanced quotes in a \'b c");
Commandline.translateCommandline("a \'b c");
}


try {
Commandline.translateCommandline("a \"b c");
fail("unbalanced double quotes undetected");
} catch (BuildException be) {
assertEquals("unbalanced quotes in a \"b c", be.getMessage());
}
/**
* Expected failure due to unbalanced double quote
*/
@Test
public void testTokenizerUnbalancedDoubleQuote() {
thrown.expect(BuildException.class);
thrown.expectMessage("unbalanced quotes in a \"b c");
Commandline.translateCommandline("a \"b c");
} }


@Test @Test


+ 24
- 29
src/tests/junit/org/apache/tools/ant/types/EnumeratedAttributeTest.java View File

@@ -24,7 +24,6 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;


/** /**
* JUnit testcases for org.apache.tools.ant.EnumeratedAttribute. * JUnit testcases for org.apache.tools.ant.EnumeratedAttribute.
@@ -37,8 +36,7 @@ public class EnumeratedAttributeTest {
public void testContains() { public void testContains() {
EnumeratedAttribute t1 = new TestNormal(); EnumeratedAttribute t1 = new TestNormal();
for (String value : expected) { for (String value : expected) {
assertTrue(value + " is in TestNormal",
t1.containsValue(value));
assertTrue(value + " is in TestNormal", t1.containsValue(value));
assertFalse(value.toUpperCase() + " is in TestNormal", assertFalse(value.toUpperCase() + " is in TestNormal",
t1.containsValue(value.toUpperCase())); t1.containsValue(value.toUpperCase()));
} }
@@ -47,43 +45,40 @@ public class EnumeratedAttributeTest {
(new TestNull()).containsValue("d")); (new TestNull()).containsValue("d"));
} }


@Test
/**
* Expected failure due to attempt to set an illegal value
*/
@Test(expected = BuildException.class)
public void testFactory() { public void testFactory() {
Factory ea = (Factory) EnumeratedAttribute.getInstance(Factory.class, "one"); Factory ea = (Factory) EnumeratedAttribute.getInstance(Factory.class, "one");
assertEquals("Factory did not set the right value.", ea.getValue(), "one"); assertEquals("Factory did not set the right value.", ea.getValue(), "one");
try {
EnumeratedAttribute.getInstance(Factory.class, "illegal");
fail("Factory should fail when trying to set an illegal value.");
} catch (BuildException be) {
// was expected
//TODO assert exception message
}
EnumeratedAttribute.getInstance(Factory.class, "illegal");
} }


@Test @Test
public void testExceptions() {
public void testExceptionsNormal() {
EnumeratedAttribute t1 = new TestNormal(); EnumeratedAttribute t1 = new TestNormal();
for (String value : expected) { for (String value : expected) {
try {
t1.setValue(value);
} catch (BuildException be) {
fail("unexpected exception for value " + value);
}
}
try {
t1.setValue("d");
fail("expected exception for value \"d\"");
} catch (BuildException be) {
//TODO assert build exception
}
try {
(new TestNull()).setValue("d");
fail("expected exception for value \"d\" in TestNull");
} catch (BuildException be) {
//TODO assert exception message
t1.setValue(value);
} }
} }


/**
* Expected exception for value "d" in TestNormal
*/
@Test(expected = BuildException.class)
public void testExceptionNormal() {
new TestNormal().setValue("d");
}

/**
* Expected exception for value "d" in TestNull
*/
@Test(expected = BuildException.class)
public void testExceptionNull() {
new TestNull().setValue("d");
}

public static class TestNormal extends EnumeratedAttribute { public static class TestNormal extends EnumeratedAttribute {
public String[] getValues() { public String[] getValues() {
return expected; return expected;


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

@@ -32,7 +32,6 @@ import java.util.Hashtable;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;


/** /**
* FilterSet testing * FilterSet testing
@@ -189,14 +188,10 @@ public class FilterSetTest {
buildRule.executeTarget("testMultipleFiltersFiles"); buildRule.executeTarget("testMultipleFiltersFiles");
} }


@Test
@Test(expected = BuildException.class)
public void testMissingFiltersFile() { public void testMissingFiltersFile() {
try {
buildRule.executeTarget("testMissingFiltersFile");
fail("should fail due to missing filtersfile");
} catch (BuildException ex) {
//TODO assert exception text
}
buildRule.executeTarget("testMissingFiltersFile");
// TODO assert exception text
} }


@Test @Test


+ 10
- 15
src/tests/junit/org/apache/tools/ant/types/RedirectorElementTest.java View File

@@ -27,7 +27,6 @@ import org.junit.Test;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;


public class RedirectorElementTest { public class RedirectorElementTest {


@@ -46,24 +45,20 @@ public class RedirectorElementTest {
instanceof RedirectorElement)); instanceof RedirectorElement));
} }


@Test
/**
* Expected failure due to multiple attributes when using refid
*/
@Test(expected = BuildException.class)
public void test2() { public void test2() {
try {
buildRule.executeTarget("test2");
fail("You must not specify more than one attribute when using refid");
} catch (BuildException ex) {
//TODO assert exception message
}
buildRule.executeTarget("test2");
} }


@Test
/**
* Expected failure due to nested elements when using refid
*/
@Test(expected = BuildException.class)
public void test3() { public void test3() {
try {
buildRule.executeTarget("test3");
fail("You must not specify nested elements when using refid");
} catch (BuildException ex) {
//TODO assert exception message
}
buildRule.executeTarget("test3");
} }


@Test @Test


+ 49
- 34
src/tests/junit/org/apache/tools/ant/types/ResourceOutputTest.java View File

@@ -23,6 +23,7 @@ import java.io.IOException;
import java.net.UnknownServiceException; import java.net.UnknownServiceException;


import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Zip; import org.apache.tools.ant.taskdefs.Zip;
import org.apache.tools.ant.types.resources.ImmutableResourceException; import org.apache.tools.ant.types.resources.ImmutableResourceException;
@@ -33,34 +34,40 @@ import org.apache.tools.ant.types.resources.ZipResource;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.ResourceUtils; import org.apache.tools.ant.util.ResourceUtils;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;


public class ResourceOutputTest { public class ResourceOutputTest {


@Rule
public ExpectedException thrown = ExpectedException.none();

@Rule
public BuildFileRule buildRule = new BuildFileRule();

private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
private static final File basedir = new File(System.getProperty("root"),
"src/etc/testcases/types/resources");
private static final String BASE_DIR = "src/etc/testcases/types/resources";


private Project project; private Project project;


@Before @Before
public void setUp() { public void setUp() {
project = new Project();
project.init();
project.setUserProperty("basedir", basedir.getAbsolutePath());
buildRule.configureProject(BASE_DIR + "/resourcelist.xml");
project = buildRule.getProject();
if (System.getProperty("root") != null) {
project.setBasedir(System.getProperty("root"));
}
} }


@Test
/**
* Expected failure
*/
@Test(expected = UnsupportedOperationException.class)
public void testresourceoutput() { public void testresourceoutput() {
try {
testoutputbe(new Resource("foo"));
fail("should have caught UnsupportedOperationException");
} catch (UnsupportedOperationException e) {
//TODO assert exception message
}
testoutputbe(new Resource("foo"));
} }


@Test @Test
@@ -70,15 +77,20 @@ public class ResourceOutputTest {
assertEquals("foo", r.getValue()); assertEquals("foo", r.getValue());
} }


@Test
/**
* Expected failure
*
* @throws IOException if something goes wrong
*/
@Test(expected = ImmutableResourceException.class)
public void teststringoutput2() throws IOException { public void teststringoutput2() throws IOException {
StringResource r = new StringResource("bar"); StringResource r = new StringResource("bar");
try {
testoutput(r);
fail("should have caught ImmutableResourceException");
} catch (ImmutableResourceException e) {
//TODO assert exception message
}
testoutput(r);
}
@Test
public void teststringoutput3() throws IOException {
StringResource r = new StringResource("bar");
assertEquals("bar", r.getValue()); assertEquals("bar", r.getValue());
} }


@@ -89,28 +101,32 @@ public class ResourceOutputTest {
assertEquals("foo", project.getProperty("bar")); assertEquals("foo", project.getProperty("bar"));
} }


@Test
/**
* Expected failure
*
* @throws IOException if something goes wrong
*/
@Test(expected = ImmutableResourceException.class)
public void testpropertyoutput2() throws IOException { public void testpropertyoutput2() throws IOException {
project.setNewProperty("bar", "bar"); project.setNewProperty("bar", "bar");
PropertyResource r = new PropertyResource(project, "bar"); PropertyResource r = new PropertyResource(project, "bar");
try {
testoutput(r);
fail("should have caught ImmutableResourceException");
} catch (ImmutableResourceException e) {
//TODO assert exception message
}
testoutput(r);
}
@Test
public void testpropertyoutput3() throws IOException {
project.setNewProperty("bar", "bar");
assertEquals("bar", project.getProperty("bar")); assertEquals("bar", project.getProperty("bar"));
} }


@Test @Test
public void testurloutput() throws IOException { public void testurloutput() throws IOException {
thrown.expect(UnknownServiceException.class);
// TODO assert exception message
File f = project.resolveFile("testurloutput"); File f = project.resolveFile("testurloutput");
try { try {
FILE_UTILS.createNewFile(f); FILE_UTILS.createNewFile(f);
testoutput(new URLResource(f)); testoutput(new URLResource(f));
fail("should have caught UnknownServiceException");
} catch (UnknownServiceException e) {
//TODO assert exception message
} finally { } finally {
if (!f.delete()) { if (!f.delete()) {
f.deleteOnExit(); f.deleteOnExit();
@@ -120,12 +136,14 @@ public class ResourceOutputTest {


@Test @Test
public void testzipentryoutput() { public void testzipentryoutput() {
thrown.expect(UnsupportedOperationException.class);
// TODO assert exception message
Zip z = new Zip(); Zip z = new Zip();
z.setProject(project); z.setProject(project);
Zip.WhenEmpty create = new Zip.WhenEmpty(); Zip.WhenEmpty create = new Zip.WhenEmpty();
create.setValue("create"); create.setValue("create");
z.setWhenempty(create); z.setWhenempty(create);
z.setBasedir(basedir);
z.setBasedir(project.getBaseDir());
z.setExcludes("**/*"); z.setExcludes("**/*");
File f = project.resolveFile("foo"); File f = project.resolveFile("foo");
z.setDestFile(f); z.setDestFile(f);
@@ -135,9 +153,6 @@ public class ResourceOutputTest {
r.setName("foo"); r.setName("foo");
try { try {
testoutputbe(r); testoutputbe(r);
fail("should have caught UnsupportedOperationException");
} catch (UnsupportedOperationException e) {
//TODO assert exception message
} finally { } finally {
if (!f.delete()) { if (!f.delete()) {
f.deleteOnExit(); f.deleteOnExit();


+ 8
- 18
src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java View File

@@ -28,7 +28,6 @@ import org.junit.Test;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;


public class LazyResourceCollectionTest { public class LazyResourceCollectionTest {


@@ -76,7 +75,7 @@ public class LazyResourceCollectionTest {
} }
} }


@Test
@Test(expected = NoSuchElementException.class)
public void testLazyLoading() { public void testLazyLoading() {
StringResourceCollection collectionTest = new StringResourceCollection(); StringResourceCollection collectionTest = new StringResourceCollection();
LazyResourceCollectionWrapper lazyCollection = new LazyResourceCollectionWrapper(); LazyResourceCollectionWrapper lazyCollection = new LazyResourceCollectionWrapper();
@@ -103,12 +102,7 @@ public class LazyResourceCollectionTest {
assertEquals("Iterating 3 times load more than 3 resources", 3, assertEquals("Iterating 3 times load more than 3 resources", 3,
stringResourceIterator.cursor); stringResourceIterator.cursor);


try {
it.next();
fail("NoSuchElementException should have been raised");
} catch (NoSuchElementException e) {
// ok
}
it.next();
} }


private void assertOneCreatedIterator( private void assertOneCreatedIterator(
@@ -117,7 +111,7 @@ public class LazyResourceCollectionTest {
testCollection.createdIterators.size()); testCollection.createdIterators.size());
} }


@Test
@Test(expected = NoSuchElementException.class)
public void testCaching() { public void testCaching() {
StringResourceCollection collectionTest = new StringResourceCollection(); StringResourceCollection collectionTest = new StringResourceCollection();
LazyResourceCollectionWrapper lazyCollection = new LazyResourceCollectionWrapper(); LazyResourceCollectionWrapper lazyCollection = new LazyResourceCollectionWrapper();
@@ -160,18 +154,14 @@ public class LazyResourceCollectionTest {
"The first iterator did not lookup in the cache for a resource", 3, "The first iterator did not lookup in the cache for a resource", 3,
stringResourceIterator.cursor); stringResourceIterator.cursor);


// next() must throw the expected NoSuchElementException;
// if that does not happen, assertions throw the unexpected Assertion error
try { try {
it1.next(); it1.next();
fail("NoSuchElementException should have been raised");
} catch (NoSuchElementException e) {
// ok
}

try {
assertTrue(it1.hasNext());
} finally {
it2.next(); it2.next();
fail("NoSuchElementException should have been raised");
} catch (NoSuchElementException e) {
// ok
assertTrue(it2.hasNext());
} }
} }




+ 4
- 17
src/tests/junit/org/apache/tools/ant/util/VectorSetTest.java View File

@@ -27,7 +27,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;


public class VectorSetTest { public class VectorSetTest {


@@ -108,18 +107,12 @@ public class VectorSetTest {
assertEquals(1, v.size()); assertEquals(1, v.size());
} }


@Test
@Test(expected = ArrayIndexOutOfBoundsException.class)
public void testRemoveIndex() { public void testRemoveIndex() {
v.add(O); v.add(O);
assertSame(O, v.remove(0)); assertSame(O, v.remove(0));
assertEquals(0, v.size()); assertEquals(0, v.size());
try {
v.remove(0);
fail("expected an AIOBE");
} catch (ArrayIndexOutOfBoundsException e) {
//TODO assert exception values
// expected
}
v.remove(0);
} }


@Test @Test
@@ -204,18 +197,12 @@ public class VectorSetTest {
assertFalse(v.removeElement(O)); assertFalse(v.removeElement(O));
} }


@Test
@Test(expected = ArrayIndexOutOfBoundsException.class)
public void testRemoveElementAt() { public void testRemoveElementAt() {
v.add(O); v.add(O);
v.removeElementAt(0); v.removeElementAt(0);
assertEquals(0, v.size()); assertEquals(0, v.size());
try {
v.removeElementAt(0);
fail("expected an AIOBE");
} catch (ArrayIndexOutOfBoundsException e) {
//TODO assert exception values
// expected
}
v.removeElementAt(0);
} }


@Test @Test


+ 14
- 12
src/tests/junit/org/apache/tools/zip/ExtraFieldUtilsTest.java View File

@@ -18,12 +18,15 @@


package org.apache.tools.zip; package org.apache.tools.zip;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.zip.ZipException;


/** /**
* JUnit 4 testcases for org.apache.tools.zip.ExtraFieldUtils. * JUnit 4 testcases for org.apache.tools.zip.ExtraFieldUtils.
@@ -43,6 +46,9 @@ public class ExtraFieldUtilsTest implements UnixStat {
private byte[] data; private byte[] data;
private byte[] aLocal; private byte[] aLocal;


@Rule
public ExpectedException thrown = ExpectedException.none();

@Before @Before
public void setUp() { public void setUp() {
a = new AsiExtraField(); a = new AsiExtraField();
@@ -73,6 +79,10 @@ public class ExtraFieldUtilsTest implements UnixStat {
*/ */
@Test @Test
public void testParse() throws Exception { public void testParse() throws Exception {
thrown.expect(ZipException.class);
thrown.expectMessage("bad extra field starting at " + (4 + aLocal.length)
+ ". Block length of 1 bytes exceeds remaining data of 0 bytes.");

ZipExtraField[] ze = ExtraFieldUtils.parse(data); ZipExtraField[] ze = ExtraFieldUtils.parse(data);
assertEquals("number of fields", 2, ze.length); assertEquals("number of fields", 2, ze.length);
assertTrue("type field 1", ze[0] instanceof AsiExtraField); assertTrue("type field 1", ze[0] instanceof AsiExtraField);
@@ -84,15 +94,7 @@ public class ExtraFieldUtilsTest implements UnixStat {


byte[] data2 = new byte[data.length - 1]; byte[] data2 = new byte[data.length - 1];
System.arraycopy(data, 0, data2, 0, data2.length); System.arraycopy(data, 0, data2, 0, data2.length);
try {
ExtraFieldUtils.parse(data2);
fail("data should be invalid");
} catch (Exception e) {
assertEquals("message",
"bad extra field starting at " + (4 + aLocal.length)
+ ". Block length of 1 bytes exceeds remaining data of 0 bytes.",
e.getMessage());
}
ExtraFieldUtils.parse(data2);
} }


@Test @Test


+ 8
- 7
src/tests/junit/org/apache/tools/zip/ZipEntryTest.java View File

@@ -18,20 +18,24 @@


package org.apache.tools.zip; package org.apache.tools.zip;


import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;


import java.util.NoSuchElementException; import java.util.NoSuchElementException;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;


/** /**
* JUnit 4 testcases for org.apache.tools.zip.ZipEntry. * JUnit 4 testcases for org.apache.tools.zip.ZipEntry.
*/ */
public class ZipEntryTest { public class ZipEntryTest {


@Rule
public ExpectedException thrown = ExpectedException.none();

/** /**
* test handling of extra fields * test handling of extra fields
*/ */
@@ -79,12 +83,9 @@ public class ZipEntryTest {
assertSame(u3, result[1]); assertSame(u3, result[1]);
assertEquals("length fourth pass", data2.length, data3.length); assertEquals("length fourth pass", data2.length, data3.length);


try {
ze.removeExtraField(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
fail("should be no such element");
} catch (NoSuchElementException nse) {
//TODO assert exception values
}
thrown.expect(NoSuchElementException.class);
//TODO assert exception values
ze.removeExtraField(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
} }


/** /**


Loading…
Cancel
Save