| @@ -402,11 +402,10 @@ public abstract class BuildFileTest extends TestCase { | |||
| executeTarget(target); | |||
| } catch (BuildException ex) { | |||
| buildException = ex; | |||
| if (null != msg && !ex.getMessage().equals(msg)) { | |||
| fail("Should throw BuildException because '" + cause | |||
| + "' with message '" + msg | |||
| + "' (actual message '" + ex.getMessage() + "' instead)"); | |||
| } | |||
| assertTrue("Should throw BuildException because '" + cause | |||
| + "' with message '" + msg + "' (actual message '" | |||
| + ex.getMessage() + "' instead)", | |||
| msg != null && !ex.getMessage().equals(msg)); | |||
| return; | |||
| } | |||
| fail("Should throw BuildException because: " + cause); | |||
| @@ -423,11 +422,12 @@ public abstract class BuildFileTest extends TestCase { | |||
| public void expectBuildExceptionContaining(String target, String cause, String contains) { | |||
| try { | |||
| executeTarget(target); | |||
| } catch (org.apache.tools.ant.BuildException ex) { | |||
| } catch (BuildException ex) { | |||
| buildException = ex; | |||
| if (null != contains && !ex.getMessage().contains(contains)) { | |||
| fail("Should throw BuildException because '" + cause + "' with message containing '" + contains + "' (actual message '" + ex.getMessage() + "' instead)"); | |||
| } | |||
| assertTrue("Should throw BuildException because '" + cause | |||
| + "' with message containing '" + contains + "' (actual message '" | |||
| + ex.getMessage() + "' instead)", | |||
| null != contains && !ex.getMessage().contains(contains)); | |||
| return; | |||
| } | |||
| fail("Should throw BuildException because: " + cause); | |||
| @@ -472,10 +472,8 @@ public abstract class BuildFileTest extends TestCase { | |||
| */ | |||
| public void assertPropertyUnset(String property) { | |||
| String result = project.getProperty(property); | |||
| if (result != null) { | |||
| fail("Expected property " + property | |||
| + " to be unset, but it is set to the value: " + result); | |||
| } | |||
| assertNull("Expected property " + property | |||
| + " to be unset, but it is set to the value: " + result, result); | |||
| } | |||
| /** | |||
| @@ -27,6 +27,7 @@ import java.io.File; | |||
| import static org.junit.Assert.assertEquals; | |||
| import static org.junit.Assert.fail; | |||
| import static org.junit.Assert.assertTrue; | |||
| public class CopydirTest { | |||
| @@ -81,9 +82,7 @@ public class CopydirTest { | |||
| buildRule.executeTarget("test5"); | |||
| File f = new File(new File(buildRule.getProject().getProperty("output")), "taskdefs.tmp"); | |||
| if (!f.exists() || !f.isDirectory()) { | |||
| fail("Copy failed"); | |||
| } | |||
| assertTrue("Copy failed", f.exists() && f.isDirectory()); | |||
| // We keep this, so we have something to delete in later tests :-) | |||
| } | |||
| @@ -123,7 +123,6 @@ public class ReplaceTest { | |||
| @Test | |||
| public void test9() throws IOException { | |||
| buildRule.executeTarget("test9"); | |||
| assertEqualContent(new File(buildRule.getOutputDir(), "result.txt"), | |||
| new File(buildRule.getOutputDir(), "output.txt")); | |||
| @@ -151,11 +150,8 @@ public class ReplaceTest { | |||
| assertEquals(ts1, new File(buildRule.getOutputDir(), "test.txt").lastModified()); | |||
| } | |||
| public void assertEqualContent(File expect, File result) | |||
| throws AssertionFailedError, IOException { | |||
| if (!result.exists()) { | |||
| fail("Expected file " + result + " doesn\'t exist"); | |||
| } | |||
| public void assertEqualContent(File expect, File result) throws IOException { | |||
| assertTrue("Expected file " + result + " doesn't exist", result.exists()); | |||
| try (InputStream inExpect = new BufferedInputStream(new FileInputStream(expect)); | |||
| InputStream inResult = new BufferedInputStream(new FileInputStream(result))) { | |||
| @@ -30,6 +30,7 @@ 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 { | |||
| @@ -85,12 +86,8 @@ public class TarTest { | |||
| @Test | |||
| public void test5() { | |||
| buildRule.executeTarget("test5"); | |||
| File f | |||
| = new File(buildRule.getProject().getProperty("output"), "test5.tar"); | |||
| if (!f.exists()) { | |||
| fail("Tarring a directory failed"); | |||
| } | |||
| File f = new File(buildRule.getProject().getProperty("output"), "test5.tar"); | |||
| assertTrue("Tarring a directory failed", f.exists()); | |||
| } | |||
| @Test | |||
| @@ -120,19 +117,11 @@ public class TarTest { | |||
| private void test7(String target) { | |||
| buildRule.executeTarget(target); | |||
| File f1 | |||
| = new File(buildRule.getProject().getProperty("output"), "untar/test7-prefix"); | |||
| if (!f1.exists() || !f1.isDirectory()) { | |||
| fail("The prefix attribute is not working properly."); | |||
| } | |||
| File f2 | |||
| = new File(buildRule.getProject().getProperty("output"), "untar/test7dir"); | |||
| File f1 = new File(buildRule.getProject().getProperty("output"), "untar/test7-prefix"); | |||
| assertTrue("The prefix attribute is not working properly.", f1.exists() && f1.isDirectory()); | |||
| if (!f2.exists() || !f2.isDirectory()) { | |||
| fail("The prefix attribute is not working properly."); | |||
| } | |||
| File f2 = new File(buildRule.getProject().getProperty("output"), "untar/test7dir"); | |||
| assertTrue("The prefix attribute is not working properly.", f2.exists() && f2.isDirectory()); | |||
| } | |||
| @Test | |||
| @@ -162,11 +151,9 @@ public class TarTest { | |||
| private void test8(String target) { | |||
| buildRule.executeTarget(target); | |||
| File f1 | |||
| = new File(buildRule.getProject().getProperty("output"), "untar/test8.xml"); | |||
| if (! f1.exists()) { | |||
| fail("The fullpath attribute or the preserveLeadingSlashes attribute does not work properly"); | |||
| } | |||
| File f1 = new File(buildRule.getProject().getProperty("output"), "untar/test8.xml"); | |||
| assertTrue("The fullpath attribute or the preserveLeadingSlashes attribute does not work properly", | |||
| f1.exists()); | |||
| } | |||
| @Test | |||
| @@ -182,21 +169,17 @@ public class TarTest { | |||
| @Test | |||
| public void test10() { | |||
| buildRule.executeTarget("test10"); | |||
| File f1 | |||
| = new File(buildRule.getProject().getProperty("output"), "untar/test10.xml"); | |||
| if (! f1.exists()) { | |||
| fail("The fullpath attribute or the preserveLeadingSlashes attribute does not work properly"); | |||
| } | |||
| File f1 = new File(buildRule.getProject().getProperty("output"), "untar/test10.xml"); | |||
| assertTrue("The fullpath attribute or the preserveLeadingSlashes attribute does not work properly", | |||
| f1.exists()); | |||
| } | |||
| @Test | |||
| public void test11() { | |||
| buildRule.executeTarget("test11"); | |||
| File f1 | |||
| = new File(buildRule.getProject().getProperty("output"), "untar/test11.xml"); | |||
| if (! f1.exists()) { | |||
| fail("The fullpath attribute or the preserveLeadingSlashes attribute does not work properly"); | |||
| } | |||
| File f1 = new File(buildRule.getProject().getProperty("output"), "untar/test11.xml"); | |||
| assertTrue("The fullpath attribute or the preserveLeadingSlashes attribute does not work properly", | |||
| f1.exists()); | |||
| } | |||
| @Test | |||
| @@ -115,7 +115,7 @@ public class ANTLRTest { | |||
| } | |||
| /** | |||
| * This is a negative test for the super grammar (glib) option. | |||
| * Expected failure due to invalid super grammar (glib) option. | |||
| */ | |||
| @Test | |||
| public void test8() { | |||
| @@ -145,7 +145,7 @@ public class ANTLRTest { | |||
| buildRule.executeTarget("test10"); | |||
| File outputDirectory = new File(buildRule.getProject().getProperty("output")); | |||
| String[] calcFiles = outputDirectory.list(new HTMLFilter()); | |||
| assertTrue(calcFiles.length > 0); | |||
| assertNotEquals(calcFiles.length, 0); | |||
| } | |||
| /** | |||
| @@ -21,18 +21,18 @@ import java.io.OutputStream; | |||
| import java.io.PrintWriter; | |||
| import java.io.StringWriter; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.junit.Test; | |||
| import junit.framework.AssertionFailedError; | |||
| import junit.framework.TestCase; | |||
| import junit.framework.TestSuite; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.junit.Test; | |||
| import static org.hamcrest.Matchers.containsString; | |||
| import static org.junit.Assert.assertEquals; | |||
| import static org.junit.Assert.assertNotEquals; | |||
| import static org.junit.Assert.assertThat; | |||
| import static org.junit.Assert.fail; | |||
| import static org.junit.Assert.assertTrue; | |||
| /** | |||
| * Small testcase for the runner, tests are very very very basics. | |||
| @@ -93,10 +93,8 @@ public class JUnitTestRunnerTest { | |||
| runner.run(); | |||
| // On junit3 this is a FAILURE, on junit4 this is an ERROR | |||
| int ret = runner.getRetCode(); | |||
| if (ret != JUnitTestRunner.FAILURES && ret != JUnitTestRunner.ERRORS) { | |||
| fail("Unexpected result " + ret + " from junit runner"); | |||
| } | |||
| assertTrue("Unexpected result " + ret + " from junit runner", | |||
| ret == JUnitTestRunner.FAILURES || ret == JUnitTestRunner.ERRORS); | |||
| // JUnit3 test | |||
| //assertEquals(runner.getFormatter().getError(), JUnitTestRunner.FAILURES, runner.getRetCode()); | |||
| } | |||
| @@ -125,9 +123,8 @@ public class JUnitTestRunnerTest { | |||
| runner.run(); | |||
| // For JUnit 3 this is a FAILURE, for JUnit 4 this is an ERROR | |||
| int ret = runner.getRetCode(); | |||
| if (ret != JUnitTestRunner.FAILURES && ret != JUnitTestRunner.ERRORS) { | |||
| fail("Unexpected result " + ret + " from junit runner"); | |||
| } | |||
| assertTrue("Unexpected result " + ret + " from junit runner", | |||
| ret == JUnitTestRunner.FAILURES || ret == JUnitTestRunner.ERRORS); | |||
| } | |||
| // check that an exception in the constructor is noticed | |||
| @@ -137,9 +134,8 @@ public class JUnitTestRunnerTest { | |||
| runner.run(); | |||
| // For JUnit 3 this is a FAILURE, for JUnit 4 this is an ERROR | |||
| int ret = runner.getRetCode(); | |||
| if (ret != JUnitTestRunner.FAILURES && ret != JUnitTestRunner.ERRORS) { | |||
| fail("Unexpected result " + ret + " from junit runner"); | |||
| } | |||
| assertTrue("Unexpected result " + ret + " from junit runner", | |||
| ret == JUnitTestRunner.FAILURES || ret == JUnitTestRunner.ERRORS); | |||
| // JUNIT3 test | |||
| //assertEquals(error, JUnitTestRunner.FAILURES, runner.getRetCode()); | |||
| //@fixme as of now does not report the original stacktrace. | |||
| @@ -335,17 +335,9 @@ public class SOSTest { | |||
| private void checkCommandLines(String[] sTestCmdLine, String[] sGeneratedCmdLine) { | |||
| int length = sTestCmdLine.length; | |||
| for (int i = 0; i < length; i++) { | |||
| try { | |||
| assertEquals("arg # " + String.valueOf(i), | |||
| sTestCmdLine[i], | |||
| sGeneratedCmdLine[i]); | |||
| } catch (ArrayIndexOutOfBoundsException aioob) { | |||
| fail("missing arg " + sTestCmdLine[i]); | |||
| } | |||
| } | |||
| if (sGeneratedCmdLine.length > sTestCmdLine.length) { | |||
| // We have extra elements | |||
| fail("extra args"); | |||
| assertEquals("arg # " + String.valueOf(i), | |||
| sTestCmdLine[i], sGeneratedCmdLine[i]); | |||
| } | |||
| assertEquals("extra args", sTestCmdLine.length, sGeneratedCmdLine.length); | |||
| } | |||
| } | |||
| @@ -39,7 +39,6 @@ import org.junit.rules.ExpectedException; | |||
| import static org.junit.Assert.assertEquals; | |||
| import static org.junit.Assert.assertFalse; | |||
| import static org.junit.Assert.fail; | |||
| /** | |||
| * Testcase to ensure that command line generation and required attributes are correct. | |||
| @@ -446,19 +445,14 @@ public class MSVSSTest implements MSVSSConstants { | |||
| int testIndex = 0; | |||
| while (testIndex < testLength) { | |||
| try { | |||
| if (sGeneratedCmdLine[genIndex].isEmpty()) { | |||
| genIndex++; | |||
| continue; | |||
| } | |||
| assertEquals("arg # " + testIndex, | |||
| sTestCmdLine[testIndex], | |||
| sGeneratedCmdLine[genIndex]); | |||
| testIndex++; | |||
| if (sGeneratedCmdLine[genIndex].isEmpty()) { | |||
| genIndex++; | |||
| } catch (ArrayIndexOutOfBoundsException aioob) { | |||
| fail("missing arg " + sTestCmdLine[testIndex]); | |||
| continue; | |||
| } | |||
| assertEquals("arg # " + testIndex, | |||
| sTestCmdLine[testIndex], sGeneratedCmdLine[genIndex]); | |||
| testIndex++; | |||
| genIndex++; | |||
| } | |||
| // Count the number of empty strings | |||
| @@ -26,7 +26,6 @@ import java.io.InputStreamReader; | |||
| import java.io.StringReader; | |||
| import static org.junit.Assert.assertEquals; | |||
| import static org.junit.Assert.fail; | |||
| /** | |||
| * Test for ReaderInputStream | |||
| @@ -131,15 +130,11 @@ public class ReaderInputStreamTest { | |||
| for (int i = 0; i < expected.length; ++i) { | |||
| int expect = expected[i] & 0xFF; | |||
| int read = r.read(); | |||
| if (expect != read) { | |||
| fail("Mismatch in ReaderInputStream at index " + i | |||
| + " expecting " + expect + " got " + read + " for string " | |||
| + s + " with encoding " + encoding); | |||
| } | |||
| } | |||
| if (r.read() != -1) { | |||
| fail("Mismatch in ReaderInputStream - EOF not seen for string " | |||
| + s + " with encoding " + encoding); | |||
| assertEquals("Mismatch in ReaderInputStream at index " + i | |||
| + " expecting " + expect + " got " + read + " for string " | |||
| + s + " with encoding " + encoding, expect, read); | |||
| } | |||
| assertEquals("Mismatch in ReaderInputStream - EOF not seen for string " | |||
| + s + " with encoding " + encoding, -1, r.read()); | |||
| } | |||
| } | |||