Expected exceptions galore Project: http://git-wip-us.apache.org/repos/asf/ant/repo Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/ad98e27d Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/ad98e27d Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/ad98e27d
Branch: refs/heads/master Commit: ad98e27d0caff44ec10b16b8eed07e9c4264898f Parents: 8a3b165 Author: Gintas Grigelionis <[email protected]> Authored: Mon Apr 23 00:48:06 2018 +0200 Committer: Gintas Grigelionis <[email protected]> Committed: Mon Apr 23 00:48:06 2018 +0200 ---------------------------------------------------------------------- .../org/apache/tools/ant/DispatchTaskTest.java | 9 +- .../org/apache/tools/ant/ExecutorTest.java | 51 +++--- .../taskdefs/AntLikeTasksAtTopLevelTest.java | 37 ++-- .../tools/ant/taskdefs/AntStructureTest.java | 13 +- .../tools/ant/taskdefs/AvailableTest.java | 174 ++++++++++++------- .../apache/tools/ant/taskdefs/BasenameTest.java | 31 +--- .../apache/tools/ant/taskdefs/CVSPassTest.java | 24 ++- .../tools/ant/taskdefs/CallTargetTest.java | 13 +- .../apache/tools/ant/taskdefs/ConcatTest.java | 35 +--- .../tools/ant/taskdefs/ConditionTest.java | 88 ++++------ .../apache/tools/ant/taskdefs/CopydirTest.java | 53 +++--- .../apache/tools/ant/taskdefs/CopyfileTest.java | 49 ++---- .../apache/tools/ant/taskdefs/DeleteTest.java | 29 +++- .../apache/tools/ant/taskdefs/DeltreeTest.java | 15 +- .../apache/tools/ant/taskdefs/DirnameTest.java | 42 ++--- .../org/apache/tools/ant/taskdefs/FailTest.java | 123 +++++-------- .../apache/tools/ant/taskdefs/FilterTest.java | 57 ++---- .../apache/tools/ant/taskdefs/GUnzipTest.java | 27 ++- .../apache/tools/ant/taskdefs/InputTest.java | 23 +-- .../apache/tools/ant/taskdefs/MkdirTest.java | 35 ++-- .../apache/tools/ant/taskdefs/RenameTest.java | 52 +++--- .../apache/tools/ant/taskdefs/ReplaceTest.java | 81 ++++----- .../apache/tools/ant/taskdefs/SignJarTest.java | 14 +- .../apache/tools/ant/taskdefs/SleepTest.java | 18 +- .../apache/tools/ant/taskdefs/StyleTest.java | 35 ++-- .../org/apache/tools/ant/taskdefs/TarTest.java | 79 ++++----- .../apache/tools/ant/taskdefs/TaskdefTest.java | 67 ++++--- .../apache/tools/ant/taskdefs/UntarTest.java | 12 +- .../apache/tools/ant/taskdefs/UnzipTest.java | 56 +++--- .../apache/tools/ant/taskdefs/XmlnsTest.java | 18 +- .../tools/ant/taskdefs/condition/HttpTest.java | 13 +- .../ant/taskdefs/condition/IsReferenceTest.java | 17 +- .../taskdefs/condition/ParserSupportsTest.java | 34 ++-- .../tools/ant/taskdefs/email/EmailTaskTest.java | 28 ++- .../tools/ant/taskdefs/optional/ANTLRTest.java | 70 ++++---- .../tools/ant/taskdefs/optional/JspcTest.java | 14 +- .../tools/ant/taskdefs/optional/PvcsTest.java | 26 ++- .../junitlauncher/JUnitLauncherTaskTest.java | 11 +- .../ant/taskdefs/optional/net/FTPTest.java | 32 +--- .../ant/taskdefs/optional/sos/SOSTest.java | 15 +- .../ant/taskdefs/optional/ssh/ScpTest.java | 24 ++- .../apache/tools/ant/types/CommandlineTest.java | 38 ++-- .../ant/types/EnumeratedAttributeTest.java | 53 +++--- .../apache/tools/ant/types/FilterSetTest.java | 11 +- .../tools/ant/types/RedirectorElementTest.java | 25 ++- .../tools/ant/types/ResourceOutputTest.java | 83 +++++---- .../resources/LazyResourceCollectionTest.java | 26 +-- .../apache/tools/ant/util/VectorSetTest.java | 21 +-- .../apache/tools/zip/ExtraFieldUtilsTest.java | 26 +-- .../org/apache/tools/zip/ZipEntryTest.java | 15 +- 50 files changed, 844 insertions(+), 1098 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/DispatchTaskTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/DispatchTaskTest.java b/src/tests/junit/org/apache/tools/ant/DispatchTaskTest.java index dab734f..4c76dc5 100644 --- a/src/tests/junit/org/apache/tools/ant/DispatchTaskTest.java +++ b/src/tests/junit/org/apache/tools/ant/DispatchTaskTest.java @@ -18,8 +18,6 @@ package org.apache.tools.ant; -import static org.junit.Assert.fail; - import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -34,13 +32,8 @@ public class DispatchTaskTest { buildRule.configureProject("src/etc/testcases/core/dispatch/dispatch.xml"); } - @Test + @Test(expected = BuildException.class) public void testDisp() { - try { 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 - } } } http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/ExecutorTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/ExecutorTest.java b/src/tests/junit/org/apache/tools/ant/ExecutorTest.java index 283b04e..acf526f 100644 --- a/src/tests/junit/org/apache/tools/ant/ExecutorTest.java +++ b/src/tests/junit/org/apache/tools/ant/ExecutorTest.java @@ -19,23 +19,29 @@ package org.apache.tools.ant; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; import java.util.Vector; import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; /** * Executor tests */ public class ExecutorTest implements BuildListener { + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + private static final String SINGLE_CHECK - = "org.apache.tools.ant.helper.SingleCheckExecutor"; + = "org.apache.tools.ant.helper.SingleCheckExecutor"; 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; static { @@ -44,9 +50,6 @@ public class ExecutorTest implements BuildListener { TARGET_NAMES.add("b"); } - @Rule - public BuildFileRule buildRule = new BuildFileRule(); - private int targetCount; /* BuildListener stuff */ @@ -117,22 +120,22 @@ public class ExecutorTest implements BuildListener { @Test public void testDefaultFailure() { + thrown.expect(BuildException.class); + thrown.expectMessage("failfoo"); try { getProject(null, true).executeTargets(TARGET_NAMES); - fail("should fail"); - } catch (BuildException e) { - assertEquals("failfoo", e.getMessage()); + } finally { assertEquals(1, targetCount); } } @Test public void testSingleCheckFailure() { + thrown.expect(BuildException.class); + thrown.expectMessage("failfoo"); try { getProject(SINGLE_CHECK, true).executeTargets(TARGET_NAMES); - fail("should fail"); - } catch (BuildException e) { - assertEquals("failfoo", e.getMessage()); + } finally { assertEquals(1, targetCount); } } @@ -145,36 +148,36 @@ public class ExecutorTest implements BuildListener { @Test public void testKeepGoingDefault() { + thrown.expect(BuildException.class); + thrown.expectMessage("failfoo"); try { getProject(null, true, true).executeTargets(TARGET_NAMES); - fail("should fail"); - } catch (BuildException e) { - assertEquals("failfoo", e.getMessage()); + } finally { assertEquals(2, targetCount); } } @Test public void testKeepGoingSingleCheck() { + thrown.expect(BuildException.class); + thrown.expectMessage("failfoo"); try { getProject(SINGLE_CHECK, true, true).executeTargets(TARGET_NAMES); - fail("should fail"); - } catch (BuildException e) { - assertEquals("failfoo", e.getMessage()); + } finally { assertEquals(1, targetCount); } } @Test 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 { - //explicitly add foo for failure - Vector<String> targetNames = new Vector<>(TARGET_NAMES); - targetNames.add(0, "foo"); getProject(IGNORE_DEPS, true, true).executeTargets(targetNames); - fail("should fail"); - } catch (BuildException e) { - assertEquals("failfoo", e.getMessage()); + } finally { assertEquals(3, targetCount); } } http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/AntLikeTasksAtTopLevelTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/AntLikeTasksAtTopLevelTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/AntLikeTasksAtTopLevelTest.java index cb03609..6333106 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/AntLikeTasksAtTopLevelTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/AntLikeTasksAtTopLevelTest.java @@ -22,9 +22,7 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildFileRule; import org.junit.Rule; 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 @@ -34,37 +32,28 @@ public class AntLikeTasksAtTopLevelTest { @Rule public BuildFileRule buildRule = new BuildFileRule(); + @Rule + public ExpectedException thrown = ExpectedException.none(); + @Test 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 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 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"); } } http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/AntStructureTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/AntStructureTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/AntStructureTest.java index 8c05288..6787436 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/AntStructureTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/AntStructureTest.java @@ -34,7 +34,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; /** */ @@ -53,14 +52,12 @@ public class AntStructureTest { buildRule.executeTarget("tearDown"); } - @Test + /** + * Expected failure due lacking a required argument + */ + @Test(expected = BuildException.class) public void test1() { - try { - buildRule.executeTarget("test1"); - fail("required argument not specified"); - } catch (BuildException ex) { - //TODO assert exception message - } + buildRule.executeTarget("test1"); } @Test http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/AvailableTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/AvailableTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/AvailableTest.java index be14160..0666a72 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/AvailableTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/AvailableTest.java @@ -21,12 +21,12 @@ package org.apache.tools.ant.taskdefs; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildFileRule; import org.junit.Before; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; /** * JUnit test for the Available task/condition. @@ -43,95 +43,104 @@ public class AvailableTest { buildRule.executeTarget("setUp"); } - // Nothing specified -> Fail - @Test + /** + * Nothing specified -> Fail + */ + @Test(expected = BuildException.class) 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 -> Fail + */ + @Test(expected = BuildException.class) 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 -> Fail + */ + @Test(expected = BuildException.class) 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 -> property 'test' == null + */ @Test public void test4() { buildRule.executeTarget("test4"); assertNull(buildRule.getProject().getProperty("test")); } - // file does exist -> property 'test' == 'true' + /** + * File does exist -> property 'test' == 'true' + */ public void test5() { buildRule.executeTarget("test5"); assertEquals("true", buildRule.getProject().getProperty("test")); } - // resource doesn't exist -> property 'test' == null + /** + * Resource doesn't exist -> property 'test' == null + */ @Test public void test6() { buildRule.executeTarget("test6"); assertNull(buildRule.getProject().getProperty("test")); } - // resource does exist -> property 'test' == 'true' + /** + * Resource does exist -> property 'test' == 'true' + */ @Test public void test7() { buildRule.executeTarget("test7"); assertEquals("true", buildRule.getProject().getProperty("test")); } - // class doesn't exist -> property 'test' == null + /** + * Class doesn't exist -> property 'test' == null + */ @Test public void test8() { buildRule.executeTarget("test8"); assertNull(buildRule.getProject().getProperty("test")); } - // class does exist -> property 'test' == 'true' + /** + * class does exist -> property 'test' == 'true' + */ @Test public void test9() { buildRule.executeTarget("test9"); assertEquals("true", buildRule.getProject().getProperty("test")); } - // All three specified and all three exist -> true + /** + * All three specified and all three exist -> true + */ @Test public void test10() { buildRule.executeTarget("test10"); assertEquals("true", buildRule.getProject().getProperty("test")); } - // All three specified but class missing -> null + /** + * All three specified but class missing -> null + */ @Test public void test11() { buildRule.executeTarget("test11"); assertNull(buildRule.getProject().getProperty("test")); } - // Specified property-name is "" -> true + /** + * Specified property-name is "" -> true + */ @Test public void test12() { buildRule.executeTarget("test12"); @@ -139,131 +148,162 @@ public class AvailableTest { assertEquals("true", buildRule.getProject().getProperty("")); } - // Specified file is "" -> invalid files do not exist + /** + * Specified file is "" -> invalid files do not exist + */ @Test public void test13() { buildRule.executeTarget("test13"); 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 public void test13b() { buildRule.executeTarget("test13b"); 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 "" -> can not exist + */ @Test public void test15() { buildRule.executeTarget("test15"); assertNull(buildRule.getProject().getProperty("test")); } - // Specified dir is "" -> this is the current directory and should - // always exist + /** + * Specified dir is "" -> this is the current directory and should always exist + */ @Test public void test16() { buildRule.executeTarget("test16"); 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" -> should exist since it's the location + * of the buildfile used... + */ @Test public void test17() { buildRule.executeTarget("test17"); assertEquals("true", buildRule.getProject().getProperty("test")); } - // Specified dir is "../this_dir_should_never_exist" -> null + /** + * Specified dir is "../this_dir_should_never_exist" -> null + */ @Test public void test18() { buildRule.executeTarget("test18"); assertNull(buildRule.getProject().getProperty("test")); } - // Invalid type specified - @Test + /** + * Invalid type specified + */ + @Test(expected = BuildException.class) 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 public void test20() { buildRule.executeTarget("test20"); 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 public void test21() { buildRule.executeTarget("test21"); 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 public void test22() { buildRule.executeTarget("test22"); 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 public void test23() { buildRule.executeTarget("test23"); assertEquals("true", buildRule.getProject().getProperty("test")); } - // Class is found in specified classpath + /** + * Class is found in specified classpath + */ @Test public void test24() { buildRule.executeTarget("test24"); assertEquals("true", buildRule.getProject().getProperty("test")); } - // File is not found in specified filepath + /** + * File is not found in specified filepath + */ @Test public void testSearchInPathNotThere() { buildRule.executeTarget("searchInPathNotThere"); assertNull(buildRule.getProject().getProperty("test")); } - // File is not found in specified filepath + /** + * File is not found in specified filepath + */ @Test public void testSearchInPathIsThere() { buildRule.executeTarget("searchInPathIsThere"); assertEquals("true", buildRule.getProject().getProperty("test")); } - // test when file begins with basedir twice + /** + * File begins with basedir twice + */ @Test public void testDoubleBasedir() { buildRule.executeTarget("testDoubleBasedir"); } - // test for searching parents + /** + * Search parents + */ @Test public void testSearchParents() { buildRule.executeTarget("search-parents"); } - // test for not searching parents + + /** + * Do not search parents + */ @Test public void testSearchParentsNot() { buildRule.executeTarget("search-parents-not"); http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/BasenameTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/BasenameTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/BasenameTest.java index 3915d6b..313271d 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/BasenameTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/BasenameTest.java @@ -25,7 +25,6 @@ import org.junit.Rule; import org.junit.Test; 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"); } - @Test + @Test(expected = BuildException.class) 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() { - 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() { - try { - buildRule.executeTarget("test3"); - fail("Required attribute missing"); - } catch (BuildException ex) { - //TODO assert exception message - } + buildRule.executeTarget("test3"); + // TODO assert exception message } @Test http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/CVSPassTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/CVSPassTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/CVSPassTest.java index a83a9c3..22329d2 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/CVSPassTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/CVSPassTest.java @@ -27,10 +27,10 @@ import org.junit.After; import org.junit.Before; import org.junit.Rule; 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; /** * Tests CVSLogin task. @@ -46,8 +46,10 @@ public class CVSPassTest { ":pserver:[email protected]:/cvs AIbdZ,"; @Rule - public final BuildFileRule buildRule = new BuildFileRule(); + public ExpectedException thrown = ExpectedException.none(); + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); @Before public void setUp() { @@ -56,22 +58,16 @@ public class CVSPassTest { @Test 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 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 http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/CallTargetTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/CallTargetTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/CallTargetTest.java index 81f7cbf..f7dddcf 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/CallTargetTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/CallTargetTest.java @@ -29,7 +29,6 @@ import java.util.Vector; import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertEquals; 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")); } - @Test + /** + * Expected failure due to empty target name + */ + @Test(expected = BuildException.class) 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 http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/ConcatTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ConcatTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ConcatTest.java index e4e8b3f..0e8f4cc 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ConcatTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ConcatTest.java @@ -34,7 +34,6 @@ import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; 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 @@ -79,28 +78,19 @@ public class ConcatTest { /** * Expect an exception when insufficient information is provided. */ - @Test + @Test(expected = BuildException.class) 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. */ - @Test + @Test(expected = BuildException.class) 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 public void test3() { - File file = new File(buildRule.getProject().getBaseDir(), tempFile); if (file.exists()) { file.delete(); } buildRule.executeTarget("test3"); - assertTrue(file.exists()); } @@ -179,7 +167,6 @@ public class ConcatTest { final long newSize = file2.length(); assertEquals(origSize, newSize); - } @Test @@ -195,7 +182,6 @@ public class ConcatTest { final long newSize = file2.length(); assertEquals(origSize * 2, newSize); - } @Test @@ -237,14 +223,9 @@ public class ConcatTest { /** * Expect an exception when attempting to cat an file to itself */ - @Test + @Test(expected = BuildException.class) 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"); } /** http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/ConditionTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ConditionTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ConditionTest.java index 9329512..0b4d227 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ConditionTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ConditionTest.java @@ -23,16 +23,18 @@ import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; public class ConditionTest { @Rule - public BuildFileRule buildRule = new BuildFileRule(); + public ExpectedException thrown = ExpectedException.none(); + @Rule + public BuildFileRule buildRule = new BuildFileRule(); /** * The JUnit setup method @@ -59,22 +61,16 @@ public class ConditionTest { @Test 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 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 @@ -109,12 +105,9 @@ public class ConditionTest { @Test 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 @@ -173,12 +166,9 @@ public class ConditionTest { @Test 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 @@ -252,22 +242,16 @@ public class ConditionTest { @Test 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 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 @@ -290,12 +274,9 @@ public class ConditionTest { @Test 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 @@ -319,12 +300,9 @@ public class ConditionTest { @Test 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 @@ -332,14 +310,10 @@ public class ConditionTest { buildRule.executeTarget("testElse"); } - @Test + @Test(expected = BuildException.class) 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 http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/CopydirTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/CopydirTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/CopydirTest.java index 8ba8c4f..704a37d 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/CopydirTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/CopydirTest.java @@ -26,7 +26,6 @@ import org.junit.Test; import java.io.File; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; import static org.junit.Assert.assertTrue; @@ -40,34 +39,31 @@ public class CopydirTest { buildRule.executeTarget("setUp"); } - @Test + /** + * Expected failure due to required argument not specified + */ + @Test(expected = BuildException.class) 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() { - 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() { - try { - buildRule.executeTarget("test3"); - fail("Required argument not specified"); - } catch (BuildException ex) { - // TODO assert value - } + buildRule.executeTarget("test3"); + // TODO Assert exception message } @Test @@ -86,14 +82,13 @@ public class CopydirTest { // 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() { - try { - buildRule.executeTarget("test6"); - fail("target is file"); - } catch (BuildException ex) { - //TODO assert value - } + buildRule.executeTarget("test6"); + // TODO Assert exception message } } http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/CopyfileTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/CopyfileTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/CopyfileTest.java index a3d84ee..23f9f94 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/CopyfileTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/CopyfileTest.java @@ -26,7 +26,7 @@ import org.junit.Test; import java.io.File; 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"); } - @Test + @Test(expected = BuildException.class) 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() { - 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() { - try { - buildRule.executeTarget("test3"); - fail("Required argument not specified"); - } catch (BuildException ex) { - // TODO assert value - } + buildRule.executeTarget("test3"); + // TODO assert value } @Test @@ -81,20 +69,13 @@ public class CopyfileTest { public void test5() { buildRule.executeTarget("test5"); 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() { - try { - buildRule.executeTarget("test6"); - fail("Required argument not specified"); - } catch (BuildException ex) { - // TODO assert value - } + buildRule.executeTarget("test6"); + // TODO assert value } } http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/DeleteTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/DeleteTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/DeleteTest.java index 4d34341..2c9b560 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/DeleteTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/DeleteTest.java @@ -24,8 +24,6 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import static org.junit.Assert.fail; - /** */ public class DeleteTest { @@ -38,73 +36,86 @@ public class DeleteTest { buildRule.configureProject("src/etc/testcases/taskdefs/delete.xml"); } - @Test + /** + * Expected failure due to required argument not specified + */ + @Test(expected = BuildException.class) 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 public void test2() { buildRule.executeTarget("test2"); } + //where oh where has my test case 3 gone? @Test public void test4() { buildRule.executeTarget("test4"); } + @Test public void test5() { buildRule.executeTarget("test5"); } + @Test public void test6() { buildRule.executeTarget("test6"); } + @Test public void test7() { buildRule.executeTarget("test7"); } + @Test public void test8() { buildRule.executeTarget("test8"); } + @Test public void test9() { buildRule.executeTarget("test9"); } + @Test public void test10() { buildRule.executeTarget("test10"); } + @Test public void test11() { buildRule.executeTarget("test11"); } + @Test public void test12() { buildRule.executeTarget("test12"); } + @Test public void test13() { buildRule.executeTarget("test13"); } + @Test public void test14() { buildRule.executeTarget("test14"); } + @Test public void test15() { buildRule.executeTarget("test15"); } + @Test public void test16() { buildRule.executeTarget("test16"); } + @Test public void test17() { buildRule.executeTarget("test17"); http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/DeltreeTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/DeltreeTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/DeltreeTest.java index b2dcc69..f6c617d 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/DeltreeTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/DeltreeTest.java @@ -24,8 +24,6 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import static org.junit.Assert.fail; - public class DeltreeTest { @Rule @@ -36,14 +34,13 @@ public class DeltreeTest { buildRule.configureProject("src/etc/testcases/taskdefs/deltree.xml"); } - @Test + /** + * Expected failure due to missing required argument + */ + @Test(expected = BuildException.class) 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 http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/DirnameTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/DirnameTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/DirnameTest.java index bc0d127..82d4bc9 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/DirnameTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/DirnameTest.java @@ -19,7 +19,6 @@ package org.apache.tools.ant.taskdefs; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; import static org.junit.Assume.assumeFalse; 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.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import java.io.File; @@ -36,6 +36,9 @@ import java.io.File; public class DirnameTest { @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Rule public BuildFileRule buildRule = new BuildFileRule(); @Before @@ -45,49 +48,38 @@ public class DirnameTest { @Test 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 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 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 public void test4() { assumeFalse("Test not possible on DOS or Netware family OS", Os.isFamily("netware") || Os.isFamily("dos")); 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 public void 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")); } } http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/FailTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/FailTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/FailTest.java index 34299d5..41ad81c 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/FailTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/FailTest.java @@ -23,17 +23,18 @@ import org.apache.tools.ant.BuildFileRule; import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import java.util.Arrays; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - /** */ public class FailTest { @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Rule public final BuildFileRule buildRule = new BuildFileRule(); @Before @@ -43,57 +44,42 @@ public class FailTest { @Test 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 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 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() { buildRule.executeTarget("testIf"); 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() { try { buildRule.executeTarget("testUnless"); - fail("testUnless must fail unless foo has been set"); - } catch (BuildException ex) { //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 public void testIfAndUnless() { + thrown.expect(BuildException.class); + thrown.expectMessage("if=if and unless=unless"); //neither buildRule.executeTarget("testIfAndUnless"); buildRule.getProject().setProperty("if", ""); try { 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 @@ -129,12 +115,9 @@ public class FailTest { @Test 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 @@ -144,64 +127,46 @@ public class FailTest { @Test 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 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"); for (char ch : Arrays.asList('a', 'b', 'c')) { 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 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 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 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"); for (char ch : Arrays.asList('a', 'b')) { 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()); } } http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/FilterTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/FilterTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/FilterTest.java index 0e40ad8..1629f8b 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/FilterTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/FilterTest.java @@ -32,8 +32,8 @@ import org.junit.Rule; import org.junit.Test; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class FilterTest { @@ -50,34 +50,22 @@ public class FilterTest { buildRule.executeTarget("cleanup"); } - @Test + @Test(expected = BuildException.class) 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() { - 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() { - try { - buildRule.executeTarget("test3"); - fail("required argument missing"); - } catch (BuildException ex) { - //TODO assert value - } + buildRule.executeTarget("test3"); + // TODO assert value } @Test @@ -122,24 +110,15 @@ public class FilterTest { } private String getFilteredFile(String testNumber, String filteredFile) { - String line = null; 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(); return line; http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/GUnzipTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/GUnzipTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/GUnzipTest.java index a7aac5d..747ea8d 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/GUnzipTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/GUnzipTest.java @@ -28,7 +28,6 @@ import org.junit.Rule; import org.junit.Test; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; public class GUnzipTest { @@ -45,24 +44,22 @@ public class GUnzipTest { buildRule.executeTarget("cleanup"); } - @Test + /** + * Expected failure due to missing required argument + */ + @Test(expected = BuildException.class) 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() { - try { - buildRule.executeTarget("test2"); - fail("attribute src invalid"); - } catch (BuildException ex) { - //TODO assert value - } + buildRule.executeTarget("test2"); + // TODO Assert exception message } @Test http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/InputTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/InputTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/InputTest.java index 4b6efaa..b1d1bab 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/InputTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/InputTest.java @@ -29,26 +29,25 @@ import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - public class InputTest { @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Rule public final BuildFileRule buildRule = new BuildFileRule(); private InputStream originalStdIn; - @Before public void setUp() { 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()); originalStdIn = System.in; } @@ -70,13 +69,9 @@ public class InputTest { @Test 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 http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/MkdirTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/MkdirTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/MkdirTest.java index 9864a4a..f503a7c 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/MkdirTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/MkdirTest.java @@ -19,14 +19,14 @@ package org.apache.tools.ant.taskdefs; import java.io.File; +import static org.junit.Assert.assertTrue; + import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildFileRule; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import static org.junit.Assert.fail; - /** */ public class MkdirTest { @@ -39,34 +39,27 @@ public class MkdirTest { buildRule.configureProject("src/etc/testcases/taskdefs/mkdir.xml"); } - @Test + /** + * Expected failure due to required argument missing + */ + @Test(expected = BuildException.class) 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() { - try { - buildRule.executeTarget("test2"); - fail("BuildException expected: directory already exists as a file"); - } catch (BuildException ex) { - //TODO assert value - } + buildRule.executeTarget("test2"); } @Test public void test3() { buildRule.executeTarget("test3"); 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(); } } http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/RenameTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/RenameTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/RenameTest.java index ca37799..6324547 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/RenameTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/RenameTest.java @@ -24,8 +24,6 @@ import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; -import static org.junit.Assert.fail; - public class RenameTest { @Rule @@ -36,43 +34,37 @@ public class RenameTest { buildRule.configureProject("src/etc/testcases/taskdefs/rename.xml"); } - @Test + /** + * Expected failure due to missing required argument + */ + @Test(expected = BuildException.class) 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() { - 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() { - 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") + @Test 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 http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/ReplaceTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ReplaceTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ReplaceTest.java index 12da88d..6045f85 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ReplaceTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ReplaceTest.java @@ -24,8 +24,6 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import junit.framework.AssertionFailedError; - import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildFileRule; 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.assertTrue; -import static org.junit.Assert.fail; import static org.junit.Assume.assumeTrue; /** @@ -51,44 +48,40 @@ public class ReplaceTest { buildRule.executeTarget("setUp"); } - @Test + /** + * Fail: required argument not specified + */ + @Test(expected = BuildException.class) 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() { - 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() { - 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() { - try { - buildRule.executeTarget("test4"); - fail("BuildException expected: empty token not allowed"); - } catch (BuildException ex) { - //TODO assert value - } + buildRule.executeTarget("test4"); + // TODO assert value } @Test @@ -96,24 +89,22 @@ public class ReplaceTest { buildRule.executeTarget("test5"); } - @Test + /** + * Fail: required argument not specified + */ + @Test(expected = BuildException.class) 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() { - try { - buildRule.executeTarget("test7"); - fail("BuildException expected: empty token not allowed"); - } catch (BuildException ex) { - //TODO assert value - } + buildRule.executeTarget("test7"); + // TODO assert value } @Test http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java index 6a0a8ad..e8f54f8 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java @@ -25,12 +25,12 @@ import org.apache.tools.ant.BuildFileRule; import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import static org.junit.Assume.assumeFalse; /** @@ -42,6 +42,9 @@ public class SignJarTest { @Rule public BuildFileRule buildRule = new BuildFileRule(); + @Rule + public ExpectedException thrown = ExpectedException.none(); + @Before public void setUp() { buildRule.configureProject("src/etc/testcases/taskdefs/signjar.xml"); @@ -106,12 +109,9 @@ public class SignJarTest { @Test 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"); } /** http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/SleepTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/SleepTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/SleepTest.java index 3d6ce87..163d485 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/SleepTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/SleepTest.java @@ -18,15 +18,14 @@ package org.apache.tools.ant.taskdefs; +import static org.junit.Assert.assertTrue; + import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildFileRule; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - public class SleepTest { @Rule @@ -72,14 +71,13 @@ public class SleepTest { 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() { - try { - buildRule.executeTarget("test5"); - fail("Negative sleep periods are not supported"); - } catch (BuildException ex) { - //TODO assert value - } + buildRule.executeTarget("test5"); + // TODO assert value } @Test http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/StyleTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/StyleTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/StyleTest.java index cf3546e..e1bc594 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/StyleTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/StyleTest.java @@ -27,13 +27,12 @@ import org.apache.tools.ant.FileUtilities; import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; /** @@ -46,21 +45,23 @@ public class StyleTest { @Rule public final BuildFileRule buildRule = new BuildFileRule(); + @Rule + public ExpectedException thrown = ExpectedException.none(); + @Before public void setUp() { buildRule.configureProject("src/etc/testcases/taskdefs/style/build.xml"); } + /** + * Expected failure: no stylesheet specified + */ @Test 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 @@ -145,15 +146,15 @@ public class StyleTest { .exists()); } + /** + * Expected failure: stylesheet specified twice + */ @Test 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 http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/TarTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/TarTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/TarTest.java index 6f69279..5b9815f 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/TarTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/TarTest.java @@ -29,7 +29,6 @@ import org.junit.Rule; import org.junit.Test; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; import static org.junit.Assert.assertTrue; public class TarTest { @@ -43,44 +42,40 @@ public class TarTest { buildRule.executeTarget("setUp"); } - @Test + /** + * Expected failure: required argument not specified + */ + @Test(expected = BuildException.class) 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() { - 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() { - 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() { - try { - buildRule.executeTarget("test4"); - fail("BuildException expected: tar cannot include itself"); - } catch (BuildException ex) { - //TODO assert value - } + buildRule.executeTarget("test4"); + // TODO assert value } @Test @@ -90,14 +85,13 @@ public class TarTest { 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() { - 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 @@ -156,14 +150,13 @@ public class TarTest { f1.exists()); } - @Test + /** + * Expected failure due to invalid value specified for compression attribute. + */ + @Test(expected = BuildException.class) 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 http://git-wip-us.apache.org/repos/asf/ant/blob/ad98e27d/src/tests/junit/org/apache/tools/ant/taskdefs/TaskdefTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/TaskdefTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/TaskdefTest.java index 0faf16a..55a2217 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/TaskdefTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/TaskdefTest.java @@ -20,7 +20,6 @@ package org.apache.tools.ant.taskdefs; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildFileRule; -import org.apache.tools.ant.Project; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -28,7 +27,6 @@ import org.junit.Test; import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertEquals; 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"); } - @Test + /** + * Expected failure due lacking a required argument + */ + @Test(expected = BuildException.class) 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() { - 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() { - 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() { - 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() { - 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
