From bd56d7b9c60bce356ee27a5684f44ff87b68ddb2 Mon Sep 17 00:00:00 2001 From: Gintas Grigelionis Date: Tue, 3 Apr 2018 09:27:18 +0200 Subject: [PATCH] Simplify assertions --- .../org/apache/tools/ant/BuildFileTest.java | 2 +- .../tools/ant/IntrospectionHelperTest.java | 2 +- .../apache/tools/ant/MockBuildListener.java | 9 +-- .../ant/taskdefs/AbstractCvsTaskTest.java | 5 +- .../apache/tools/ant/taskdefs/AntTest.java | 15 ++--- .../tools/ant/taskdefs/ExecTaskTest.java | 3 +- .../tools/ant/taskdefs/ExecuteJavaTest.java | 5 +- .../ant/taskdefs/ExecuteWatchdogTest.java | 4 +- .../apache/tools/ant/taskdefs/JarTest.java | 38 +++++------ .../apache/tools/ant/taskdefs/JavaTest.java | 3 +- .../apache/tools/ant/taskdefs/StyleTest.java | 8 +-- .../apache/tools/ant/taskdefs/TarTest.java | 4 +- .../apache/tools/ant/taskdefs/UnzipTest.java | 7 +- .../taskdefs/optional/EchoPropertiesTest.java | 13 +--- .../taskdefs/optional/TraXLiaisonTest.java | 3 +- .../optional/junit/JUnitTaskTest.java | 4 +- .../optional/junit/JUnitTestRunnerTest.java | 11 ++-- .../ant/taskdefs/optional/net/FTPTest.java | 12 ++-- .../ant/types/EnumeratedAttributeTest.java | 12 ++-- .../types/selectors/ModifiedSelectorTest.java | 3 +- .../tools/ant/util/DOMElementWriterTest.java | 17 ++--- .../apache/tools/ant/util/FileUtilsTest.java | 65 ++++++++++--------- .../tools/ant/util/GlobPatternMapperTest.java | 2 +- .../apache/tools/ant/util/JAXPUtilsTest.java | 3 +- .../tools/ant/util/JavaEnvUtilsTest.java | 10 +-- .../util/LayoutPreservingPropertiesTest.java | 32 ++++----- .../ant/util/LazyFileOutputStreamTest.java | 3 +- .../util/LineOrientedOutputStreamTest.java | 2 +- .../tools/ant/util/XMLFragmentTest.java | 5 +- .../ant/util/facade/FacadeTaskHelperTest.java | 5 +- .../util/regexp/JakartaRegexpMatcherTest.java | 28 +++----- .../util/regexp/JakartaRegexpRegexpTest.java | 28 +++----- .../util/regexp/Jdk14RegexpMatcherTest.java | 48 ++++++-------- .../util/regexp/Jdk14RegexpRegexpTest.java | 48 ++++++-------- .../ant/util/regexp/RegexpMatcherTest.java | 52 +++++++-------- .../apache/tools/zip/AsiExtraFieldTest.java | 9 +-- .../org/apache/tools/zip/ZipLongTest.java | 8 +-- .../org/apache/tools/zip/ZipShortTest.java | 8 +-- 38 files changed, 246 insertions(+), 290 deletions(-) diff --git a/src/tests/junit/org/apache/tools/ant/BuildFileTest.java b/src/tests/junit/org/apache/tools/ant/BuildFileTest.java index b63ac9eae..72e18a714 100644 --- a/src/tests/junit/org/apache/tools/ant/BuildFileTest.java +++ b/src/tests/junit/org/apache/tools/ant/BuildFileTest.java @@ -425,7 +425,7 @@ public abstract class BuildFileTest extends TestCase { executeTarget(target); } catch (org.apache.tools.ant.BuildException ex) { buildException = ex; - if ((null != contains) && (!ex.getMessage().contains(contains))) { + if (null != contains && !ex.getMessage().contains(contains)) { fail("Should throw BuildException because '" + cause + "' with message containing '" + contains + "' (actual message '" + ex.getMessage() + "' instead)"); } return; diff --git a/src/tests/junit/org/apache/tools/ant/IntrospectionHelperTest.java b/src/tests/junit/org/apache/tools/ant/IntrospectionHelperTest.java index 87baa1f98..90c8bd753 100644 --- a/src/tests/junit/org/apache/tools/ant/IntrospectionHelperTest.java +++ b/src/tests/junit/org/apache/tools/ant/IntrospectionHelperTest.java @@ -108,7 +108,7 @@ public class IntrospectionHelperTest { ih.supportsCharacters()); ih = IntrospectionHelper.getHelper(String.class); - assertTrue("String doesn\'t support addText", !ih.supportsCharacters()); + assertFalse("String doesn\'t support addText", ih.supportsCharacters()); } public void addText(String text) { diff --git a/src/tests/junit/org/apache/tools/ant/MockBuildListener.java b/src/tests/junit/org/apache/tools/ant/MockBuildListener.java index 4829770b0..34e716009 100644 --- a/src/tests/junit/org/apache/tools/ant/MockBuildListener.java +++ b/src/tests/junit/org/apache/tools/ant/MockBuildListener.java @@ -18,11 +18,12 @@ package org.apache.tools.ant; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertEquals; - import java.util.Vector; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + public class MockBuildListener implements BuildListener { private final Vector buffer = new Vector<>(); @@ -54,7 +55,7 @@ public class MockBuildListener implements BuildListener { if (actual.getPriority() == Project.MSG_DEBUG) { return; } - assertTrue("unexpected messageLogged: "+ actual.getMessage(), !buffer.isEmpty()); + assertFalse("unexpected messageLogged: " + actual.getMessage(), buffer.isEmpty()); assertEquals("unexpected project ", project, actual.getProject()); BuildEvent expected = buffer.elementAt(0); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/AbstractCvsTaskTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/AbstractCvsTaskTest.java index 227987fa8..39aed2674 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/AbstractCvsTaskTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/AbstractCvsTaskTest.java @@ -26,6 +26,7 @@ import org.junit.Test; import java.io.File; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /** @@ -54,7 +55,7 @@ public class AbstractCvsTaskTest { @Test public void testPackageAttribute() { File f = new File(buildRule.getProject().getProperty("output") + "/src/Makefile"); - assertTrue("starting empty", !f.exists()); + assertFalse("starting empty", f.exists()); buildRule.executeTarget("package-attribute"); AntAssert.assertContains("U src/Makefile", buildRule.getLog()); assertTrue("now it is there", f.exists()); @@ -63,7 +64,7 @@ public class AbstractCvsTaskTest { @Test public void testTagAttribute() { File f = new File(buildRule.getProject().getProperty("output") + "/src/Makefile"); - assertTrue("starting empty", !f.exists()); + assertFalse("starting empty", f.exists()); buildRule.executeTarget("tag-attribute"); AntAssert.assertContains("OPENBSD_5_3", buildRule.getLog()); assertTrue("now it is there", f.exists()); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java index a5f615d65..5fddd8062 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java @@ -36,8 +36,9 @@ import org.junit.Rule; import org.junit.Test; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -243,15 +244,13 @@ public class AntTest { buildRule.getProject().resolveFile("ant/test4.log") }; for (File logFile : logFiles) { - assertTrue(logFile.getName() + " doesn\'t exist", - !logFile.exists()); + assertFalse(logFile.getName() + " doesn\'t exist", logFile.exists()); } buildRule.executeTarget("testLogfilePlacement"); for (File logFile : logFiles) { - assertTrue(logFile.getName() + " exists", - logFile.exists()); + assertTrue(logFile.getName() + " exists", logFile.exists()); } } @@ -496,19 +495,19 @@ public class AntTest { Path received = event.getProject().getReference(keys[calls]); boolean shouldBeEqual = expectSame[calls++]; if (received == null) { - assertTrue(msg, !shouldBeEqual); + assertFalse(msg, shouldBeEqual); } else { String[] l1 = expect.list(); String[] l2 = received.list(); if (l1.length == l2.length) { for (int i = 0; i < l1.length; i++) { if (!l1[i].equals(l2[i])) { - assertTrue(msg, !shouldBeEqual); + assertFalse(msg, shouldBeEqual); } } assertTrue(msg, shouldBeEqual); } else { - assertTrue(msg, !shouldBeEqual); + assertFalse(msg, shouldBeEqual); } } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ExecTaskTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ExecTaskTest.java index 709de0120..8e81fcd83 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ExecTaskTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ExecTaskTest.java @@ -18,6 +18,7 @@ package org.apache.tools.ant.taskdefs; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeNotNull; @@ -73,7 +74,7 @@ public class ExecTaskTest { logFile = FILE_UTILS.createTempFile("spawn", "log", new File(buildRule.getProject().getProperty("output")), false, false); // this is guaranteed by FileUtils#createTempFile - assertTrue("log file not existing", !logFile.exists()); + assertFalse("log file not existing", logFile.exists()); // make the spawned process run 1 seconds myBuild.setTimeToWait(TIME_TO_WAIT); myBuild.setLogFile(logFile.getAbsolutePath()); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java index c00d1b79d..e6dca54f1 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java @@ -26,6 +26,7 @@ import org.apache.tools.ant.types.Commandline; import org.junit.Before; import org.junit.Test; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /** @@ -66,7 +67,7 @@ public class ExecuteJavaTest { Commandline cmd = getCommandline(TIME_OUT / 2); ej.setJavaCommand(cmd); ej.execute(project); - assertTrue("process should not have been killed", !ej.killedProcess()); + assertFalse("process should not have been killed", ej.killedProcess()); } // test that the watchdog ends the process @@ -92,7 +93,7 @@ public class ExecuteJavaTest { Commandline cmd = getCommandline(TIME_OUT / 2); ej.setJavaCommand(cmd); ej.fork(cp); - assertTrue("process should not have been killed", !ej.killedProcess()); + assertFalse("process should not have been killed", ej.killedProcess()); } // test that the watchdog ends the process diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteWatchdogTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteWatchdogTest.java index 54491354b..3efeef5aa 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteWatchdogTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteWatchdogTest.java @@ -126,7 +126,7 @@ public class ExecuteWatchdogTest { Process process = getProcess(-1); // process should abort watchdog.start(process); int retCode = process.waitFor(); - assertTrue("process should not have been killed", !watchdog.killedProcess()); + assertFalse("process should not have been killed", watchdog.killedProcess()); assertTrue("return code is invalid: " + retCode, retCode!=0); } @@ -159,6 +159,6 @@ public class ExecuteWatchdogTest { // process should be dead and well finished assertEquals(0, process.exitValue()); - assertTrue("process should not have been killed", !watchdog.killedProcess()); + assertFalse("process should not have been killed", watchdog.killedProcess()); } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java index 37f9f2062..86b18fdb8 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java @@ -80,34 +80,30 @@ public class JarTest { } } - @Test + /** + * Expected failure due to 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"); } - @Test + /** + * Expected failure due to nonexistent manifest file + */ + @Test(expected = BuildException.class) public void test2() { - try { - buildRule.executeTarget("test2"); - fail("BuildException expected: manifest file does not exist"); - } catch (BuildException ex) { - //TODO assert value - } + buildRule.executeTarget("test2"); + // TODO assert exception message } - @Test + /** + * Expected failure due to unrecognized whenempty attribute: format C: /y + */ + @Test(expected = BuildException.class) public void test3() { - try { - buildRule.executeTarget("test3"); - fail("BuildException expected: Unrecognized whenempty attribute: format C: /y"); - } catch (BuildException ex) { - //TODO assert value - } + buildRule.executeTarget("test3"); + // TODO assert exception message } private File getOutputDir() { diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java index 59d3cf642..339bd5ec1 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java @@ -41,6 +41,7 @@ import org.junit.internal.AssumptionViolatedException; import static org.apache.tools.ant.AntAssert.assertContains; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -321,7 +322,7 @@ public class JavaTest { File logFile = FILE_UTILS.createTempFile("spawn", "log", new File(buildRule.getProject().getProperty("output")), false, false); // this is guaranteed by FileUtils#createTempFile - assertTrue("log file not existing", !logFile.exists()); + assertFalse("log file not existing", logFile.exists()); buildRule.getProject().setProperty("logFile", logFile.getAbsolutePath()); buildRule.getProject().setProperty("timeToWait", Long.toString(TIME_TO_WAIT)); buildRule.getProject().executeTarget("testSpawn"); 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 6cde0ff49..1fcf57a43 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/StyleTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/StyleTest.java @@ -29,6 +29,7 @@ import org.junit.Rule; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -106,8 +107,7 @@ public class StyleTest { } public void testDefaultMapper(String target) throws Exception { - assertTrue(!( - new File(buildRule.getOutputDir().getAbsoluteFile(), "data.html").exists())); + assertFalse(new File(buildRule.getOutputDir().getAbsoluteFile(), "data.html").exists()); expectFileContains(target, buildRule.getOutputDir().getAbsoluteFile() + "/data.html", "set='myvalue'"); @@ -115,7 +115,7 @@ public class StyleTest { @Test public void testCustomMapper() throws Exception { - assertTrue(!new File(buildRule.getOutputDir().getAbsoluteFile(), "out.xml").exists()); + assertFalse(new File(buildRule.getOutputDir().getAbsoluteFile(), "out.xml").exists()); expectFileContains("testCustomMapper", buildRule.getOutputDir().getAbsoluteFile() + "/out.xml", "set='myvalue'"); @@ -123,7 +123,7 @@ public class StyleTest { @Test public void testTypedMapper() throws Exception { - assertTrue(!new File(buildRule.getOutputDir().getAbsoluteFile(), "out.xml").exists()); + assertFalse(new File(buildRule.getOutputDir().getAbsoluteFile(), "out.xml").exists()); expectFileContains("testTypedMapper", buildRule.getOutputDir().getAbsoluteFile() + "/out.xml", "set='myvalue'"); 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 9650dfcfd..fd4e23b53 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/TarTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/TarTest.java @@ -123,14 +123,14 @@ public class TarTest { File f1 = new File(buildRule.getProject().getProperty("output"), "untar/test7-prefix"); - if (!(f1.exists() && f1.isDirectory())) { + if (!f1.exists() || !f1.isDirectory()) { fail("The prefix attribute is not working properly."); } File f2 = new File(buildRule.getProject().getProperty("output"), "untar/test7dir"); - if (!(f2.exists() && f2.isDirectory())) { + if (!f2.exists() || !f2.isDirectory()) { fail("The prefix attribute is not working properly."); } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/UnzipTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/UnzipTest.java index 55d4c8b8f..f95c37d33 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/UnzipTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/UnzipTest.java @@ -29,6 +29,7 @@ import java.io.File; import java.io.IOException; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -214,8 +215,7 @@ public class UnzipTest { * @param filename filename to resolve against the project */ private void assertFileExists(String message, String filename) { - assertTrue(message, - buildRule.getProject().resolveFile(filename).exists()); + assertTrue(message, buildRule.getProject().resolveFile(filename).exists()); } /** @@ -225,8 +225,7 @@ public class UnzipTest { * @param filename filename to resolve against the project */ private void assertFileMissing(String message, String filename) { - assertTrue(message, - !buildRule.getProject().resolveFile(filename).exists()); + assertFalse(message, buildRule.getProject().resolveFile(filename).exists()); } /** diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java index 07c653769..68275f2d9 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java @@ -126,9 +126,7 @@ public class EchoPropertiesTest { // read in the file File f = createRelativeFile(GOOD_OUTFILE_XML); - FileReader fr = new FileReader(f); - BufferedReader br = new BufferedReader(fr); - try { + try (BufferedReader br = new BufferedReader(new FileReader(f))) { String read = null; while ((read = br.readLine()) != null) { if (read.contains("")) { @@ -137,15 +135,6 @@ public class EchoPropertiesTest { } } fail("did not encounter set property in generated file."); - } finally { - try { - fr.close(); - } catch (IOException e) { - } - try { - br.close(); - } catch (IOException e) { - } } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java index 2485ac470..196b38cbd 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java @@ -18,6 +18,7 @@ package org.apache.tools.ant.taskdefs.optional; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeNoException; @@ -162,7 +163,7 @@ public class TraXLiaisonTest extends AbstractXSLTLiaisonTest implements XSLTLogg } String systemid = JAXPUtils.getSystemId(file); assertTrue("SystemIDs should start by file:/", systemid.startsWith("file:/")); - assertTrue("SystemIDs should not start with file:////", !systemid.startsWith("file:////")); + assertFalse("SystemIDs should not start with file:////", systemid.startsWith("file:////")); } public void log(String message) { diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java index 580819146..616e6a042 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java @@ -22,7 +22,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeFalse; +import static org.junit.Assume.assumeTrue; import static org.apache.tools.ant.AntAssert.assertNotContains; import static org.apache.tools.ant.AntAssert.assertContains; @@ -140,7 +140,7 @@ public class JUnitTaskTest { if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_1_5)) { try { Class clazz = Class.forName("junit.framework.JUnit4TestAdapter"); - assumeFalse("Skipping test since it fails with JUnit 4", clazz != null); + assumeTrue("Skipping test since it fails with JUnit 4", clazz == null); } catch (ClassNotFoundException e) { // OK, this is JUnit3, can run test } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java index d23a59b65..292eb60bb 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java @@ -17,10 +17,6 @@ */ package org.apache.tools.ant.taskdefs.optional.junit; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - import java.io.OutputStream; import java.io.PrintWriter; import java.io.StringWriter; @@ -32,6 +28,11 @@ import junit.framework.TestSuite; import org.apache.tools.ant.BuildException; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * Small testcase for the runner, tests are very very very basics. * They must be enhanced with time. @@ -54,7 +55,7 @@ public class JUnitTestRunnerTest { runner.run(); String error = runner.getFormatter().getError(); // might be FAILURES or ERRORS depending on JUnit version? - assertTrue(error, runner.getRetCode() != JUnitTestRunner.SUCCESS); + assertNotEquals(error, JUnitTestRunner.SUCCESS, runner.getRetCode()); } // check that having no suite generates no errors diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java index 3a977963d..a2dfe4f47 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java @@ -773,14 +773,13 @@ public class FTPTest { } } - @Test + /** + * Two retries expected, continued after two. + */ + @Test(expected = BuildException.class) public void testGetWithSelectorRetryable3() { buildRule.getProject().addTaskDefinition("ftp", threeFailureFTP.class); - try { - buildRule.getProject().executeTarget("ftp-get-with-selector-retryable"); - fail("Two retries expected, continued after two."); - } catch (BuildException bx) { - } + buildRule.getProject().executeTarget("ftp-get-with-selector-retryable"); } @Test @@ -808,7 +807,6 @@ public class FTPTest { String[] messages = new String[]{ "Doing Site Command: umask 222", "Failed to issue Site Command: umask 222", - }; LogCounter counter = new LogCounter(); for (String message : messages) { diff --git a/src/tests/junit/org/apache/tools/ant/types/EnumeratedAttributeTest.java b/src/tests/junit/org/apache/tools/ant/types/EnumeratedAttributeTest.java index 14436de8d..fd80b97fc 100644 --- a/src/tests/junit/org/apache/tools/ant/types/EnumeratedAttributeTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/EnumeratedAttributeTest.java @@ -22,6 +22,7 @@ import org.apache.tools.ant.BuildException; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -38,13 +39,12 @@ public class EnumeratedAttributeTest { for (String value : expected) { assertTrue(value + " is in TestNormal", t1.containsValue(value)); - assertTrue(value.toUpperCase() + " is in TestNormal", - !t1.containsValue(value.toUpperCase())); + assertFalse(value.toUpperCase() + " is in TestNormal", + t1.containsValue(value.toUpperCase())); } - assertTrue("TestNormal doesn\'t have \"d\" attribute", - !t1.containsValue("d")); - assertTrue("TestNull doesn\'t have \"d\" attribute and doesn\'t die", - !(new TestNull()).containsValue("d")); + assertFalse("TestNormal doesn\'t have \"d\" attribute", t1.containsValue("d")); + assertFalse("TestNull doesn\'t have \"d\" attribute and doesn\'t die", + (new TestNull()).containsValue("d")); } @Test diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java index 65aa53a72..fb511b085 100644 --- a/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java @@ -55,7 +55,6 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.junit.Assume.assumeNotNull; - /** * Unit tests for ModifiedSelector. * @@ -184,7 +183,7 @@ public class ModifiedSelectorTest { String fsModValue = bft.getProperty("fs.mod.value"); assertNotNull("'fs.full.value' must be set.", fsFullValue); - assertTrue("'fs.full.value' must not be null.", !"".equals(fsFullValue)); + assertNotEquals("'fs.full.value' must not be null.", "", fsFullValue); assertTrue("'fs.full.value' must contain ant.bat.", fsFullValue.contains("ant.bat")); assertNotNull("'fs.mod.value' must be set.", fsModValue); diff --git a/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java b/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java index f9bf08bc8..a11fef60e 100644 --- a/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.io.StringWriter; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /** @@ -41,9 +42,9 @@ public class DOMElementWriterTest { assertTrue("", w.isReference("")); assertTrue(" ", w.isReference(" ")); assertTrue(" ", w.isReference(" ")); - assertTrue("&#A0;", !w.isReference("&#A0;")); - assertTrue("20;", !w.isReference("20;")); - assertTrue("", !w.isReference("")); + assertFalse("&#A0;", w.isReference("&#A0;")); + assertFalse("20;", w.isReference("20;")); + assertFalse("", w.isReference("")); assertTrue(""", w.isReference(""")); assertTrue("'", w.isReference("'")); assertTrue(">", w.isReference(">")); @@ -111,18 +112,18 @@ public class DOMElementWriterTest { @Test public void testIsLegalCharacter() { - assertTrue("0x00", !w.isLegalCharacter('\u0000')); + assertFalse("0x00", w.isLegalCharacter('\u0000')); assertTrue("0x09", w.isLegalCharacter('\t')); assertTrue("0x0A", w.isLegalCharacter('\n')); assertTrue("0x0C", w.isLegalCharacter('\r')); - assertTrue("0x1F", !w.isLegalCharacter('\u001F')); + assertFalse("0x1F", w.isLegalCharacter('\u001F')); assertTrue("0x20", w.isLegalCharacter('\u0020')); assertTrue("0xD7FF", w.isLegalCharacter('\uD7FF')); - assertTrue("0xD800", !w.isLegalCharacter('\uD800')); - assertTrue("0xDFFF", !w.isLegalCharacter('\uDFFF')); + assertFalse("0xD800", w.isLegalCharacter('\uD800')); + assertFalse("0xDFFF", w.isLegalCharacter('\uDFFF')); assertTrue("0xE000", w.isLegalCharacter('\uE000')); assertTrue("0xFFFD", w.isLegalCharacter('\uFFFD')); - assertTrue("0xFFFE", !w.isLegalCharacter('\uFFFE')); + assertFalse("0xFFFE", w.isLegalCharacter('\uFFFE')); } @Test diff --git a/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java index c52015654..198723675 100644 --- a/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java @@ -30,6 +30,7 @@ import org.junit.Test; 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.assumeTrue; @@ -52,10 +53,8 @@ public class FileUtilsTest { @After public void tearDown() { - if (removeThis != null && removeThis.exists()) { - if (!removeThis.delete()) { - removeThis.deleteOnExit(); - } + if (removeThis != null && removeThis.exists() && !removeThis.delete()) { + removeThis.deleteOnExit(); } } @@ -77,7 +76,7 @@ public class FileUtilsTest { fos.close(); assumeTrue("Could not change file modified time", removeThis.setLastModified(removeThis.lastModified() - 2000)); long modTime = removeThis.lastModified(); - assertTrue(modTime != 0); + assertNotEquals(0, modTime); FILE_UTILS.setFileLastModified(removeThis, -1); @@ -97,12 +96,12 @@ public class FileUtilsTest { * * Just assert the time has changed. */ - assertTrue(thirdModTime != secondModTime); + assertNotEquals(thirdModTime, secondModTime); } @Test public void testResolveFile() { - if (!(Os.isFamily("dos") || Os.isFamily("netware"))) { + if (!Os.isFamily("dos") && !Os.isFamily("netware")) { /* * Start with simple absolute file names. */ @@ -157,7 +156,7 @@ public class FileUtilsTest { FILE_UTILS.resolveFile(null, driveSpec + "/////").getPath()); assertEquals(driveSpec, FILE_UTILS.resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath()); - } else if (!(Os.isFamily("dos"))) { + } else if (!Os.isFamily("dos")) { /* * drive letters must be considered just normal filenames. */ @@ -202,7 +201,7 @@ public class FileUtilsTest { @Test public void testNormalize() { - if (!(Os.isFamily("dos") || Os.isFamily("netware"))) { + if (!Os.isFamily("dos") && !Os.isFamily("netware")) { /* * Start with simple absolute file names. */ @@ -348,8 +347,8 @@ public class FileUtilsTest { assertTrue("starts with pre", name.startsWith("pre")); assertTrue("ends with .suf", name.endsWith(".suf")); assertTrue("File was created", tmp1.exists()); - assertEquals((new File(tmploc, tmp1.getName())).getAbsolutePath(), tmp1 - .getAbsolutePath()); + assertEquals((new File(tmploc, tmp1.getName())).getAbsolutePath(), + tmp1.getAbsolutePath()); tmp1.delete(); File dir2 = new File(tmploc + "/ant-test"); @@ -361,14 +360,14 @@ public class FileUtilsTest { assertTrue("starts with pre", name2.startsWith("pre")); assertTrue("ends with .suf", name2.endsWith(".suf")); assertTrue("File was created", tmp2.exists()); - assertEquals((new File(dir2, tmp2.getName())).getAbsolutePath(), tmp2 - .getAbsolutePath()); + assertEquals((new File(dir2, tmp2.getName())).getAbsolutePath(), + tmp2.getAbsolutePath()); tmp2.delete(); dir2.delete(); File parent = new File((new File("/tmp")).getAbsolutePath()); tmp1 = FILE_UTILS.createTempFile("pre", ".suf", parent, false); - assertTrue("new file", !tmp1.exists()); + assertFalse("new file", tmp1.exists()); name = tmp1.getName(); assertTrue("starts with pre", name.startsWith("pre")); @@ -377,14 +376,13 @@ public class FileUtilsTest { .getParent()); tmp2 = FILE_UTILS.createTempFile("pre", ".suf", parent, false); - assertTrue("files are different", !tmp1.getAbsolutePath().equals( - tmp2.getAbsolutePath())); + assertNotEquals("files are different", tmp1.getAbsolutePath(), tmp2.getAbsolutePath()); // null parent dir File tmp3 = FILE_UTILS.createTempFile("pre", ".suf", null, false); tmploc = System.getProperty("java.io.tmpdir"); - assertEquals((new File(tmploc, tmp3.getName())).getAbsolutePath(), tmp3 - .getAbsolutePath()); + assertEquals((new File(tmploc, tmp3.getName())).getAbsolutePath(), + tmp3.getAbsolutePath()); } /** @@ -392,18 +390,21 @@ public class FileUtilsTest { */ @Test public void testContentEquals() throws IOException { - assertTrue("Non existing files", FILE_UTILS.contentEquals(new File(System.getProperty("root"), "foo"), - new File(System.getProperty("root"), "bar"))); - assertTrue("One exists, the other one doesn\'t", - !FILE_UTILS.contentEquals(new File(System.getProperty("root"), "foo"), new File(System.getProperty("root"), "build.xml"))); - assertTrue("Don\'t compare directories", - !FILE_UTILS.contentEquals(new File(System.getProperty("root"), "src"), new File(System.getProperty("root"), "src"))); + assertTrue("Non existing files", + FILE_UTILS.contentEquals(new File(System.getProperty("root"), "foo"), + new File(System.getProperty("root"), "bar"))); + assertFalse("One exists, the other one doesn\'t", + FILE_UTILS.contentEquals(new File(System.getProperty("root"), "foo"), + new File(System.getProperty("root"), "build.xml"))); + assertFalse("Don\'t compare directories", + FILE_UTILS.contentEquals(new File(System.getProperty("root"), "src"), + new File(System.getProperty("root"), "src"))); assertTrue("File equals itself", - FILE_UTILS.contentEquals(new File(System.getProperty("root"), "build.xml"), - new File(System.getProperty("root"), "build.xml"))); - assertTrue("Files are different", - !FILE_UTILS.contentEquals(new File(System.getProperty("root"), "build.xml"), - new File(System.getProperty("root"), "docs.xml"))); + FILE_UTILS.contentEquals(new File(System.getProperty("root"), "build.xml"), + new File(System.getProperty("root"), "build.xml"))); + assertFalse("Files are different", + FILE_UTILS.contentEquals(new File(System.getProperty("root"), "build.xml"), + new File(System.getProperty("root"), "docs.xml"))); } /** @@ -438,7 +439,7 @@ public class FileUtilsTest { new File("c:\\foo\\bar"))); assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar"))); - if (!(Os.isFamily("dos") || Os.isFamily("netware"))) { + if (!Os.isFamily("dos") && !Os.isFamily("netware")) { assertEquals(FILE_UTILS.normalize("/bar").getAbsolutePath(), FILE_UTILS.removeLeadingPath(new File("/foo"), new File("/bar"))); assertEquals(FILE_UTILS.normalize("/foobar").getAbsolutePath(), @@ -564,8 +565,8 @@ public class FileUtilsTest { assertFalse("newer source files are no up to date", FILE_UTILS.isUpToDate(secondTime, firstTime)); - assertTrue("-1 dest timestamp implies nonexistence", - !FILE_UTILS.isUpToDate(firstTime,-1L)); + assertFalse("-1 dest timestamp implies nonexistence", + FILE_UTILS.isUpToDate(firstTime, -1L)); } @Test diff --git a/src/tests/junit/org/apache/tools/ant/util/GlobPatternMapperTest.java b/src/tests/junit/org/apache/tools/ant/util/GlobPatternMapperTest.java index 5bd7db606..4d437ab06 100644 --- a/src/tests/junit/org/apache/tools/ant/util/GlobPatternMapperTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/GlobPatternMapperTest.java @@ -25,7 +25,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; /** - * Tests for org.apache.tools.ant.util;GlobPatternMapper. + * Tests for org.apache.tools.ant.util.GlobPatternMapper. * */ public class GlobPatternMapperTest { diff --git a/src/tests/junit/org/apache/tools/ant/util/JAXPUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/JAXPUtilsTest.java index 7950771c9..924de6e3c 100644 --- a/src/tests/junit/org/apache/tools/ant/util/JAXPUtilsTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/JAXPUtilsTest.java @@ -21,6 +21,7 @@ import org.junit.Test; import java.io.File; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /** @@ -38,6 +39,6 @@ public class JAXPUtilsTest { } String systemid = JAXPUtils.getSystemId(file); assertTrue("SystemIDs should start by file:/", systemid.startsWith("file:/")); - assertTrue("SystemIDs should not start with file:////", !systemid.startsWith("file:////")); + assertFalse("SystemIDs should not start with file:////", systemid.startsWith("file:////")); } } diff --git a/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java index c428eb395..d37d4a923 100644 --- a/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java @@ -23,7 +23,9 @@ import org.apache.tools.ant.taskdefs.condition.Os; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; /** @@ -69,7 +71,7 @@ public class JavaEnvUtilsTest { if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9)) { assertTrue(j + " is normalized and not in the JRE dir", j.startsWith(javaHome)); } else { - assertTrue(j + " is normalized and not in the JRE dir", !j.startsWith(javaHome)); + assertFalse(j + " is normalized and not in the JRE dir", j.startsWith(javaHome)); } } catch (AssertionError e) { // java.home is bogus @@ -82,8 +84,8 @@ public class JavaEnvUtilsTest { @Test public void testGetExecutableMostPlatforms() { - assumeTrue("Test only runs on non Netware and non Windows systems", - !Os.isName("netware") && !Os.isFamily("windows")); + assumeFalse("Test only runs on non Netware and non Windows systems", + Os.isName("netware") || Os.isFamily("windows")); String javaHome = FILE_UTILS.normalize(System.getProperty("java.home")).getAbsolutePath(); // could still be OS/2 @@ -108,7 +110,7 @@ public class JavaEnvUtilsTest { if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9)) { assertTrue(j + " is normalized and in the JRE dir", j.startsWith(javaHome)); } else { - assertTrue(j + " is normalized and not in the JRE dir", !j.startsWith(javaHome)); + assertFalse(j + " is normalized and not in the JRE dir", j.startsWith(javaHome)); } assertEquals("foo" + extension, JavaEnvUtils.getJreExecutable("foo")); diff --git a/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java b/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java index 78a987a0f..409f755bf 100644 --- a/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java @@ -27,6 +27,7 @@ import java.util.Properties; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; public class LayoutPreservingPropertiesTest { @@ -171,19 +172,13 @@ public class LayoutPreservingPropertiesTest { // and check that the resulting file looks okay String s = readFile(tmp); - assertTrue("should have had no properties ", - !s.contains("prop.alpha")); - assertTrue("should have had no properties ", - !s.contains("prop.beta")); - assertTrue("should have had no properties ", - !s.contains("prop.gamma")); - - assertTrue("should have had no comments", - !s.contains("# a comment")); - assertTrue("should have had no comments", - !s.contains("! more comment")); - assertTrue("should have had no comments", - !s.contains("# now a line wrapping one")); + assertFalse("should have had no properties ", s.contains("prop.alpha")); + assertFalse("should have had no properties ", s.contains("prop.beta")); + assertFalse("should have had no properties ", s.contains("prop.gamma")); + + assertFalse("should have had no comments", s.contains("# a comment")); + assertFalse("should have had no comments", s.contains("! more comment")); + assertFalse("should have had no comments", s.contains("# now a line wrapping one")); } @Test @@ -203,8 +198,7 @@ public class LayoutPreservingPropertiesTest { // and check that the resulting file looks okay String s = readFile(tmp); - assertTrue("should not have had prop.beta", - !s.contains("prop.beta")); + assertFalse("should not have had prop.beta", s.contains("prop.beta")); assertTrue("should have had prop.beta's comment", s.contains("! more comment")); } @@ -228,10 +222,8 @@ public class LayoutPreservingPropertiesTest { // and check that the resulting file looks okay String s = readFile(tmp); - assertTrue("should not have had prop.beta", - !s.contains("prop.beta")); - assertTrue("should not have had prop.beta's comment", - !s.contains("! more comment")); + assertFalse("should not have had prop.beta", s.contains("prop.beta")); + assertFalse("should not have had prop.beta's comment", s.contains("! more comment")); } @Test @@ -263,7 +255,7 @@ public class LayoutPreservingPropertiesTest { // check original is untouched assertTrue("should have had 'simple'", s1.contains("simple")); - assertTrue("should not have had prop.new", !s1.contains("prop.new")); + assertFalse("should not have had prop.new", s1.contains("prop.new")); // check clone has the changes assertTrue("should have had 'a new value for beta'", diff --git a/src/tests/junit/org/apache/tools/ant/util/LazyFileOutputStreamTest.java b/src/tests/junit/org/apache/tools/ant/util/LazyFileOutputStreamTest.java index 82c363407..2a4cbf766 100644 --- a/src/tests/junit/org/apache/tools/ant/util/LazyFileOutputStreamTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/LazyFileOutputStreamTest.java @@ -23,6 +23,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /** @@ -49,7 +50,7 @@ public class LazyFileOutputStreamTest { @Test public void testNoFileWithoutWrite() throws IOException { los.close(); - assertTrue(f + " has not been written.", !f.exists()); + assertFalse(f + " has not been written.", f.exists()); } @Test diff --git a/src/tests/junit/org/apache/tools/ant/util/LineOrientedOutputStreamTest.java b/src/tests/junit/org/apache/tools/ant/util/LineOrientedOutputStreamTest.java index 68a81648a..0fbc48bb8 100644 --- a/src/tests/junit/org/apache/tools/ant/util/LineOrientedOutputStreamTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/LineOrientedOutputStreamTest.java @@ -147,7 +147,7 @@ public class LineOrientedOutputStreamTest { } private void assertNotInvoked() { - assertTrue("No output", !invoked); + assertFalse("No output", invoked); } } } diff --git a/src/tests/junit/org/apache/tools/ant/util/XMLFragmentTest.java b/src/tests/junit/org/apache/tools/ant/util/XMLFragmentTest.java index 74467851e..576ec770c 100644 --- a/src/tests/junit/org/apache/tools/ant/util/XMLFragmentTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/XMLFragmentTest.java @@ -27,6 +27,7 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -45,7 +46,7 @@ public class XMLFragmentTest { XMLFragment x = buildRule.getProject().getReference("nested-text"); assertNotNull(x); Node n = x.getFragment(); - assertTrue("No attributes", !n.hasAttributes()); + assertFalse("No attributes", n.hasAttributes()); NodeList nl = n.getChildNodes(); assertEquals(1, nl.getLength()); assertEquals(Node.TEXT_NODE, nl.item(0).getNodeType()); @@ -58,7 +59,7 @@ public class XMLFragmentTest { buildRule.getProject().getReference("with-children"); assertNotNull(x); Node n = x.getFragment(); - assertTrue("No attributes", !n.hasAttributes()); + assertFalse("No attributes", n.hasAttributes()); NodeList nl = n.getChildNodes(); assertEquals(3, nl.getLength()); diff --git a/src/tests/junit/org/apache/tools/ant/util/facade/FacadeTaskHelperTest.java b/src/tests/junit/org/apache/tools/ant/util/facade/FacadeTaskHelperTest.java index df2d43b30..622095511 100644 --- a/src/tests/junit/org/apache/tools/ant/util/facade/FacadeTaskHelperTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/facade/FacadeTaskHelperTest.java @@ -21,6 +21,7 @@ package org.apache.tools.ant.util.facade; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /** @@ -51,9 +52,9 @@ public class FacadeTaskHelperTest { @Test public void testHasBeenSet() { FacadeTaskHelper fth = new FacadeTaskHelper("foo"); - assertTrue("nothing set", !fth.hasBeenSet()); + assertFalse("nothing set", fth.hasBeenSet()); fth.setMagicValue(null); - assertTrue("magic has not been set", !fth.hasBeenSet()); + assertFalse("magic has not been set", fth.hasBeenSet()); fth.setMagicValue("foo"); assertTrue("magic has been set", fth.hasBeenSet()); fth.setMagicValue(null); diff --git a/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaRegexpMatcherTest.java b/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaRegexpMatcherTest.java index ce42c8cbf..67e51d543 100644 --- a/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaRegexpMatcherTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaRegexpMatcherTest.java @@ -18,12 +18,8 @@ package org.apache.tools.ant.util.regexp; -import java.io.IOException; - import org.junit.Test; -import static org.junit.Assert.fail; - /** * Tests for the jakarta-regexp implementation of the RegexpMatcher interface. * @@ -34,25 +30,21 @@ public class JakartaRegexpMatcherTest extends RegexpMatcherTest { return new JakartaRegexpMatcher(); } - @Test - public void testWindowsLineSeparator2() throws IOException { - try { - super.testWindowsLineSeparator2(); - fail("Should trigger when this bug is fixed. {@since 1.2}"); - } catch (AssertionError e) { - } + /** + * Should trigger once fixed. {@since 1.2} + */ + @Test(expected = AssertionError.class) + public void testWindowsLineSeparator2() { + super.testWindowsLineSeparator2(); } /** * Fails for the same reason as "default" mode in doEndTest2. + * Should trigger once fixed. {@since 1.2} */ - @Test - public void testUnixLineSeparator() throws IOException { - try { - super.testUnixLineSeparator(); - fail("Should trigger once this bug is fixed. {@since 1.2}"); - } catch (AssertionError e) { - } + @Test(expected = AssertionError.class) + public void testUnixLineSeparator() { + super.testUnixLineSeparator(); } /** diff --git a/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaRegexpRegexpTest.java b/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaRegexpRegexpTest.java index 4937ff4e5..d143e28ed 100644 --- a/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaRegexpRegexpTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaRegexpRegexpTest.java @@ -18,12 +18,8 @@ package org.apache.tools.ant.util.regexp; -import java.io.IOException; - import org.junit.Test; -import static org.junit.Assert.fail; - /** * Tests for the jakarta-regexp implementation of the Regexp interface. * @@ -34,25 +30,21 @@ public class JakartaRegexpRegexpTest extends RegexpTest { return new JakartaRegexpRegexp(); } - @Test - public void testWindowsLineSeparator2() throws IOException { - try { - super.testWindowsLineSeparator2(); - fail("Should trigger when this bug is fixed. {@since 1.2}"); - } catch (AssertionError e) { - } + /** + * Should trigger once fixed. {@since 1.2} + */ + @Test(expected = AssertionError.class) + public void testWindowsLineSeparator2() { + super.testWindowsLineSeparator2(); } /** * Fails for the same reason as "default" mode in doEndTest2. + * Should trigger once fixed. {@since 1.2} */ - @Test - public void testUnixLineSeparator() throws IOException { - try { - super.testUnixLineSeparator(); - fail("Should trigger once this bug is fixed. {@since 1.2}"); - } catch (AssertionError e) { - } + @Test(expected = AssertionError.class) + public void testUnixLineSeparator() { + super.testUnixLineSeparator(); } /** diff --git a/src/tests/junit/org/apache/tools/ant/util/regexp/Jdk14RegexpMatcherTest.java b/src/tests/junit/org/apache/tools/ant/util/regexp/Jdk14RegexpMatcherTest.java index 5a5f1d2a6..7f5b31c5d 100644 --- a/src/tests/junit/org/apache/tools/ant/util/regexp/Jdk14RegexpMatcherTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/regexp/Jdk14RegexpMatcherTest.java @@ -18,12 +18,8 @@ package org.apache.tools.ant.util.regexp; -import java.io.IOException; - import org.junit.Test; -import static org.junit.Assert.fail; - /** * Tests for the JDK 1.4 implementation of the RegexpMatcher interface. * @@ -34,39 +30,35 @@ public class Jdk14RegexpMatcherTest extends RegexpMatcherTest { return new Jdk14RegexpMatcher(); } + /** + * Should trigger once fixed. {@since JDK 1.4RC1} + */ @Test - public void testParagraphCharacter() throws IOException { - try { - super.testParagraphCharacter(); - fail("Should trigger once fixed. {@since JDK 1.4RC1}"); - } catch (AssertionError e) { - } + public void testParagraphCharacter() { + super.testParagraphCharacter(); } + /** + * Should trigger once fixed. {@since JDK 1.4RC1} + */ @Test - public void testLineSeparatorCharacter() throws IOException { - try { - super.testLineSeparatorCharacter(); - fail("Should trigger once fixed. {@since JDK 1.4RC1}"); - } catch (AssertionError e) { - } + public void testLineSeparatorCharacter() { + super.testLineSeparatorCharacter(); } + /** + * Should trigger once fixed. {@since JDK 1.4RC1} + */ @Test - public void testStandaloneCR() throws IOException { - try { - super.testStandaloneCR(); - fail("Should trigger once fixed. {@since JDK 1.4RC1}"); - } catch (AssertionError e) { - } + public void testStandaloneCR() { + super.testStandaloneCR(); } + /** + * Should trigger once fixed. {@since JDK 1.4RC1} + */ @Test - public void testWindowsLineSeparator() throws IOException { - try { - super.testWindowsLineSeparator(); - fail("Should trigger once fixed. {@since JDK 1.4RC1}"); - } catch (AssertionError e) { - } + public void testWindowsLineSeparator() { + super.testWindowsLineSeparator(); } } diff --git a/src/tests/junit/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexpTest.java b/src/tests/junit/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexpTest.java index 67b69aa3a..d85373c06 100644 --- a/src/tests/junit/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexpTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexpTest.java @@ -18,12 +18,8 @@ package org.apache.tools.ant.util.regexp; -import java.io.IOException; - import org.junit.Test; -import static org.junit.Assert.fail; - /** * Tests for the JDK 1.4 implementation of the Regexp interface. * @@ -34,40 +30,36 @@ public class Jdk14RegexpRegexpTest extends RegexpTest { return new Jdk14RegexpRegexp(); } + /** + * Should trigger once fixed. {@since JDK 1.4RC1} + */ @Test - public void testParagraphCharacter() throws IOException { - try { - super.testParagraphCharacter(); - fail("Should trigger once fixed. {@since JDK 1.4RC1}"); - } catch (AssertionError e) { - } + public void testParagraphCharacter() { + super.testParagraphCharacter(); } + /** + * Should trigger once fixed. {@since JDK 1.4RC1} + */ @Test - public void testLineSeparatorCharacter() throws IOException { - try { - super.testLineSeparatorCharacter(); - fail("Should trigger once fixed. {@since JDK 1.4RC1}"); - } catch (AssertionError e) { - } + public void testLineSeparatorCharacter() { + super.testLineSeparatorCharacter(); } + /** + * Should trigger once fixed. {@since JDK 1.4RC1} + */ @Test - public void testStandaloneCR() throws IOException { - try { - super.testStandaloneCR(); - fail("Should trigger once fixed. {@since JDK 1.4RC1}"); - } catch (AssertionError e) { - } + public void testStandaloneCR() { + super.testStandaloneCR(); } + /** + * Should trigger once fixed. {@since JDK 1.4RC1} + */ @Test - public void testWindowsLineSeparator() throws IOException { - try { - super.testWindowsLineSeparator(); - fail("Should trigger once fixed. {@since JDK 1.4RC1}"); - } catch (AssertionError e) { - } + public void testWindowsLineSeparator() { + super.testWindowsLineSeparator(); } } diff --git a/src/tests/junit/org/apache/tools/ant/util/regexp/RegexpMatcherTest.java b/src/tests/junit/org/apache/tools/ant/util/regexp/RegexpMatcherTest.java index 9feb67ce9..aa95c29c7 100644 --- a/src/tests/junit/org/apache/tools/ant/util/regexp/RegexpMatcherTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/regexp/RegexpMatcherTest.java @@ -21,10 +21,10 @@ package org.apache.tools.ant.util.regexp; import org.junit.Before; import org.junit.Test; -import java.io.IOException; import java.util.Vector; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /** @@ -53,18 +53,18 @@ public abstract class RegexpMatcherTest { reg.setPattern("aaaa"); assertTrue("aaaa should match itself", reg.matches("aaaa")); assertTrue("aaaa should match xaaaa", reg.matches("xaaaa")); - assertTrue("aaaa shouldn\'t match xaaa", !reg.matches("xaaa")); + assertFalse("aaaa shouldn\'t match xaaa", reg.matches("xaaa")); reg.setPattern("^aaaa"); - assertTrue("^aaaa shouldn\'t match xaaaa", !reg.matches("xaaaa")); + assertFalse("^aaaa shouldn\'t match xaaaa", reg.matches("xaaaa")); assertTrue("^aaaa should match aaaax", reg.matches("aaaax")); reg.setPattern("aaaa$"); - assertTrue("aaaa$ shouldn\'t match aaaax", !reg.matches("aaaax")); + assertFalse("aaaa$ shouldn\'t match aaaax", reg.matches("aaaax")); assertTrue("aaaa$ should match xaaaa", reg.matches("xaaaa")); reg.setPattern("[0-9]+"); assertTrue("[0-9]+ should match 123", reg.matches("123")); assertTrue("[0-9]+ should match 1", reg.matches("1")); - assertTrue("[0-9]+ shouldn\'t match \'\'", !reg.matches("")); - assertTrue("[0-9]+ shouldn\'t match a", !reg.matches("a")); + assertFalse("[0-9]+ shouldn\'t match \'\'", reg.matches("")); + assertFalse("[0-9]+ shouldn\'t match a", reg.matches("a")); reg.setPattern("[0-9]*"); assertTrue("[0-9]* should match 123", reg.matches("123")); assertTrue("[0-9]* should match 1", reg.matches("1")); @@ -72,7 +72,7 @@ public abstract class RegexpMatcherTest { assertTrue("[0-9]* should match a", reg.matches("a")); reg.setPattern("([0-9]+)=\\1"); assertTrue("([0-9]+)=\\1 should match 1=1", reg.matches("1=1")); - assertTrue("([0-9]+)=\\1 shouldn\'t match 1=2", !reg.matches("1=2")); + assertFalse("([0-9]+)=\\1 shouldn\'t match 1=2", reg.matches("1=2")); } @Test @@ -113,7 +113,7 @@ public abstract class RegexpMatcherTest { @Test public void testCaseInsensitiveMatch() { reg.setPattern("aaaa"); - assertTrue("aaaa doesn't match AAaa", !reg.matches("AAaa")); + assertFalse("aaaa doesn't match AAaa", reg.matches("AAaa")); assertTrue("aaaa matches AAaa ignoring case", reg.matches("AAaa", RegexpMatcher.MATCH_CASE_INSENSITIVE)); } @@ -122,43 +122,43 @@ public abstract class RegexpMatcherTest { // a line separator for regex (perl) is always a unix line (ie \n) @Test - public void testParagraphCharacter() throws IOException { + public void testParagraphCharacter() { reg.setPattern("end of text$"); - assertTrue("paragraph character", !reg.matches("end of text\u2029")); + assertFalse("paragraph character", reg.matches("end of text\u2029")); } @Test - public void testLineSeparatorCharacter() throws IOException { + public void testLineSeparatorCharacter() { reg.setPattern("end of text$"); - assertTrue("line-separator character", !reg.matches("end of text\u2028")); + assertFalse("line-separator character", reg.matches("end of text\u2028")); } @Test public void testNextLineCharacter() { reg.setPattern("end of text$"); - assertTrue("next-line character", !reg.matches("end of text\u0085")); + assertFalse("next-line character", reg.matches("end of text\u0085")); } @Test - public void testStandaloneCR() throws IOException { + public void testStandaloneCR() { reg.setPattern("end of text$"); - assertTrue("standalone CR", !reg.matches("end of text\r")); + assertFalse("standalone CR", reg.matches("end of text\r")); } @Test - public void testWindowsLineSeparator() throws IOException { + public void testWindowsLineSeparator() { reg.setPattern("end of text$"); - assertTrue("Windows line separator", !reg.matches("end of text\r\n")); + assertFalse("Windows line separator", reg.matches("end of text\r\n")); } @Test - public void testWindowsLineSeparator2() throws IOException { + public void testWindowsLineSeparator2() { reg.setPattern("end of text\r$"); assertTrue("Windows line separator", reg.matches("end of text\r\n")); } @Test - public void testUnixLineSeparator() throws IOException { + public void testUnixLineSeparator() { reg.setPattern("end of text$"); assertTrue("Unix line separator", reg.matches("end of text\n")); } @@ -178,9 +178,9 @@ public abstract class RegexpMatcherTest { protected void doStartTest1(String text) { reg.setPattern("^starttest"); - assertTrue("^starttest in default mode", !reg.matches(text)); - assertTrue("^starttest in single line mode", - !reg.matches(text, RegexpMatcher.MATCH_SINGLELINE)); + assertFalse("^starttest in default mode", reg.matches(text)); + assertFalse("^starttest in single line mode", + reg.matches(text, RegexpMatcher.MATCH_SINGLELINE)); assertTrue("^starttest in multi line mode", reg.matches(text, RegexpMatcher.MATCH_MULTILINE)); } @@ -196,11 +196,11 @@ public abstract class RegexpMatcherTest { protected void doEndTest1(String text) { reg.setPattern("endtest$"); - assertTrue("endtest$ in default mode", !reg.matches(text)); - assertTrue("endtest$ in single line mode", - !reg.matches(text, RegexpMatcher.MATCH_SINGLELINE)); + assertFalse("endtest$ in default mode", reg.matches(text)); + assertFalse("endtest$ in single line mode", + reg.matches(text, RegexpMatcher.MATCH_SINGLELINE)); assertTrue("endtest$ in multi line mode", - reg.matches(text, RegexpMatcher.MATCH_MULTILINE)); + reg.matches(text, RegexpMatcher.MATCH_MULTILINE)); } protected void doEndTest2(String text) { diff --git a/src/tests/junit/org/apache/tools/zip/AsiExtraFieldTest.java b/src/tests/junit/org/apache/tools/zip/AsiExtraFieldTest.java index af44e7d47..9a9abddea 100644 --- a/src/tests/junit/org/apache/tools/zip/AsiExtraFieldTest.java +++ b/src/tests/junit/org/apache/tools/zip/AsiExtraFieldTest.java @@ -21,6 +21,7 @@ package org.apache.tools.zip; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -94,8 +95,8 @@ public class AsiExtraFieldTest implements UnixStat { a.parseFromLocalFileData(data, 0, data.length); assertEquals("length plain file", data.length, a.getLocalFileDataLength().getValue()); - assertTrue("plain file, no link", !a.isLink()); - assertTrue("plain file, no dir", !a.isDirectory()); + assertFalse("plain file, no link", a.isLink()); + assertFalse("plain file, no dir", a.isDirectory()); assertEquals("mode plain file", FILE_FLAG | 0123, a.getMode()); assertEquals("uid plain file", 5, a.getUserId()); assertEquals("gid plain file", 6, a.getGroupId()); @@ -110,7 +111,7 @@ public class AsiExtraFieldTest implements UnixStat { assertEquals("length link", data.length, a.getLocalFileDataLength().getValue()); assertTrue("link, is link", a.isLink()); - assertTrue("link, no dir", !a.isDirectory()); + assertFalse("link, no dir", a.isDirectory()); assertEquals("mode link", LINK_FLAG | 0123, a.getMode()); assertEquals("uid link", 5, a.getUserId()); assertEquals("gid link", 6, a.getGroupId()); @@ -124,7 +125,7 @@ public class AsiExtraFieldTest implements UnixStat { a.parseFromLocalFileData(data, 0, data.length); assertEquals("length dir", data.length, a.getLocalFileDataLength().getValue()); - assertTrue("dir, no link", !a.isLink()); + assertFalse("dir, no link", a.isLink()); assertTrue("dir, is dir", a.isDirectory()); assertEquals("mode dir", DIR_FLAG | 0123, a.getMode()); assertEquals("uid dir", 5, a.getUserId()); diff --git a/src/tests/junit/org/apache/tools/zip/ZipLongTest.java b/src/tests/junit/org/apache/tools/zip/ZipLongTest.java index 04c47c7f9..67a4e177c 100644 --- a/src/tests/junit/org/apache/tools/zip/ZipLongTest.java +++ b/src/tests/junit/org/apache/tools/zip/ZipLongTest.java @@ -22,7 +22,7 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNotEquals; /** * JUnit testcases for org.apache.tools.zip.ZipLong. @@ -66,12 +66,12 @@ public class ZipLongTest { assertEquals("reflexive", zl, zl); assertEquals("works", zl, zl2); - assertTrue("works, part two", !zl.equals(zl3)); + assertNotEquals("works, part two", zl, zl3); assertEquals("symmetric", zl2, zl); - assertTrue("null handling", !zl.equals(null)); - assertTrue("non ZipLong handling", !zl.equals(0x1234)); + assertNotEquals("null handling", null, zl); + assertNotEquals("non ZipLong handling", 0x1234, zl); } /** diff --git a/src/tests/junit/org/apache/tools/zip/ZipShortTest.java b/src/tests/junit/org/apache/tools/zip/ZipShortTest.java index 0f191e8f2..559a24fba 100644 --- a/src/tests/junit/org/apache/tools/zip/ZipShortTest.java +++ b/src/tests/junit/org/apache/tools/zip/ZipShortTest.java @@ -21,8 +21,8 @@ package org.apache.tools.zip; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; /** * JUnit 4 testcases for org.apache.tools.zip.ZipShort. @@ -63,12 +63,12 @@ public class ZipShortTest { assertEquals("reflexive", zs, zs); assertEquals("works", zs, zs2); - assertTrue("works, part two", !zs.equals(zs3)); + assertNotEquals("works, part two", zs, zs3); assertEquals("symmetric", zs2, zs); - assertTrue("null handling", !zs.equals(null)); - assertTrue("non ZipShort handling", !zs.equals(0x1234)); + assertNotEquals("null handling", null, zs); + assertNotEquals("non ZipShort handling", 0x1234, zs); } /**