From cac9c2fc4fa96c51bec547402dd4de055a6c84d0 Mon Sep 17 00:00:00 2001 From: Gintas Grigelionis Date: Sun, 1 Apr 2018 22:06:44 +0200 Subject: [PATCH] Simplify assertions --- .../org/apache/tools/ant/LocationTest.java | 13 +++--- .../tools/ant/taskdefs/AntStructureTest.java | 37 ++++++++-------- .../tools/ant/taskdefs/AvailableTest.java | 7 ++- .../apache/tools/ant/taskdefs/CopyTest.java | 43 ++++++++----------- .../taskdefs/ExecStreamRedirectorTest.java | 4 +- .../apache/tools/ant/taskdefs/ImportTest.java | 4 +- .../apache/tools/ant/taskdefs/JavaTest.java | 6 +-- .../tools/ant/taskdefs/ReplaceTest.java | 2 +- .../tools/ant/taskdefs/SignJarTest.java | 3 +- .../apache/tools/ant/taskdefs/ZipTest.java | 13 +++--- .../compilers/DefaultCompilerAdapterTest.java | 20 +++++---- .../tools/ant/taskdefs/optional/JspcTest.java | 5 +-- .../taskdefs/optional/PropertyFileTest.java | 6 +-- .../taskdefs/optional/image/ImageTest.java | 3 +- .../junitlauncher/JUnitLauncherTaskTest.java | 5 ++- .../taskdefs/optional/unix/SymlinkTest.java | 20 ++++----- .../tools/ant/types/TarFileSetTest.java | 13 ++---- .../tools/ant/types/ZipFileSetTest.java | 7 +-- .../types/selectors/ModifiedSelectorTest.java | 14 +++--- .../tools/ant/util/ClasspathUtilsTest.java | 4 +- .../tools/ant/util/DeweyDecimalTest.java | 20 ++++----- .../org/apache/tools/zip/ZipEncodingTest.java | 8 ++-- .../org/apache/tools/zip/ZipEntryTest.java | 4 +- .../org/apache/tools/zip/ZipLongTest.java | 6 +-- .../org/apache/tools/zip/ZipShortTest.java | 6 +-- .../vintage/JUnit4SampleTest.java | 11 +++-- 26 files changed, 139 insertions(+), 145 deletions(-) diff --git a/src/tests/junit/org/apache/tools/ant/LocationTest.java b/src/tests/junit/org/apache/tools/ant/LocationTest.java index 42aab1dd2..e6e3d535c 100644 --- a/src/tests/junit/org/apache/tools/ant/LocationTest.java +++ b/src/tests/junit/org/apache/tools/ant/LocationTest.java @@ -26,7 +26,8 @@ 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.assertNotEquals; +import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertTrue; public class LocationTest { @@ -43,8 +44,8 @@ public class LocationTest { public void testPlainTask() { buildRule.executeTarget("testPlainTask"); Echo e = buildRule.getProject().getReference("echo"); - assertFalse(e.getLocation() == Location.UNKNOWN_LOCATION); - assertFalse(e.getLocation().getLineNumber() == 0); + assertNotSame(e.getLocation(), Location.UNKNOWN_LOCATION); + assertNotEquals(0, e.getLocation().getLineNumber()); } @Test @@ -52,7 +53,7 @@ public class LocationTest { buildRule.executeTarget("testStandaloneType"); Echo e = buildRule.getProject().getReference("echo2"); FileSet f = buildRule.getProject().getReference("fs"); - assertFalse(f.getLocation() == Location.UNKNOWN_LOCATION); + assertNotSame(f.getLocation(), Location.UNKNOWN_LOCATION); assertEquals(e.getLocation().getLineNumber() + 1, f.getLocation().getLineNumber()); } @@ -62,8 +63,8 @@ public class LocationTest { buildRule.executeTarget("testConditionTask"); TaskAdapter ta = buildRule.getProject().getReference("cond"); ConditionTask c = (ConditionTask) ta.getProxy(); - assertFalse(c.getLocation() == Location.UNKNOWN_LOCATION); - assertFalse(c.getLocation().getLineNumber() == 0); + assertNotSame(c.getLocation(), Location.UNKNOWN_LOCATION); + assertNotEquals(0, c.getLocation().getLineNumber()); } @Test 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 da51b5d97..406b44149 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/AntStructureTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/AntStructureTest.java @@ -18,12 +18,10 @@ package org.apache.tools.ant.taskdefs; -import org.apache.tools.ant.AntAssert; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildFileRule; import org.apache.tools.ant.Project; import org.junit.After; -import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -31,6 +29,9 @@ import org.junit.Test; import java.io.PrintWriter; import java.util.Hashtable; +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** @@ -68,7 +69,7 @@ public class AntStructureTest { // the test has likely been loaded via a different classloader // than this class. Therefore we make the printer assert its // state and only check for the tail invocation. - AntAssert.assertContains(MyPrinter.TAIL_CALLED, buildRule.getLog()); + assertContains(MyPrinter.TAIL_CALLED, buildRule.getLog()); } public static class MyPrinter implements AntStructure.StructurePrinter { @@ -81,32 +82,32 @@ public class AntStructureTest { public void printHead(PrintWriter out, Project p, Hashtable tasks, Hashtable types) { - Assert.assertTrue(!headCalled); - Assert.assertTrue(!targetCalled); - Assert.assertTrue(!tailCalled); - Assert.assertEquals(0, elementCalled); + assertTrue(!headCalled); + assertTrue(!targetCalled); + assertTrue(!tailCalled); + assertEquals(0, elementCalled); headCalled = true; } public void printTargetDecl(PrintWriter out) { - Assert.assertTrue(headCalled); - Assert.assertTrue(!targetCalled); - Assert.assertTrue(!tailCalled); - Assert.assertEquals(0, elementCalled); + assertTrue(headCalled); + assertTrue(!targetCalled); + assertTrue(!tailCalled); + assertEquals(0, elementCalled); targetCalled = true; } public void printElementDecl(PrintWriter out, Project p, String name, Class element) { - Assert.assertTrue(headCalled); - Assert.assertTrue(targetCalled); - Assert.assertTrue(!tailCalled); + assertTrue(headCalled); + assertTrue(targetCalled); + assertTrue(!tailCalled); elementCalled++; this.p = p; } public void printTail(PrintWriter out) { - Assert.assertTrue(headCalled); - Assert.assertTrue(targetCalled); - Assert.assertTrue(!tailCalled); - Assert.assertTrue(elementCalled > 0); + assertTrue(headCalled); + assertTrue(targetCalled); + assertTrue(!tailCalled); + assertTrue(elementCalled > 0); tailCalled = true; p.log(TAIL_CALLED); } 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 ae87a5a1f..be141603d 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/AvailableTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/AvailableTest.java @@ -26,7 +26,6 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** @@ -81,7 +80,7 @@ public class AvailableTest { @Test public void test4() { buildRule.executeTarget("test4"); - assertTrue(buildRule.getProject().getProperty("test") == null); + assertNull(buildRule.getProject().getProperty("test")); } // file does exist -> property 'test' == 'true' @@ -94,7 +93,7 @@ public class AvailableTest { @Test public void test6() { buildRule.executeTarget("test6"); - assertTrue(buildRule.getProject().getProperty("test") == null); + assertNull(buildRule.getProject().getProperty("test")); } // resource does exist -> property 'test' == 'true' @@ -108,7 +107,7 @@ public class AvailableTest { @Test public void test8() { buildRule.executeTarget("test8"); - assertTrue(buildRule.getProject().getProperty("test") == null); + assertNull(buildRule.getProject().getProperty("test")); } // class does exist -> property 'test' == 'true' diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/CopyTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/CopyTest.java index c027ae232..961a473db 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/CopyTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/CopyTest.java @@ -23,8 +23,6 @@ import org.apache.tools.ant.BuildFileRule; import org.apache.tools.ant.FileUtilities; import org.apache.tools.ant.taskdefs.condition.Os; import org.apache.tools.ant.util.FileUtils; -import org.junit.Assert; -import org.junit.Assume; import org.junit.Before; import org.junit.Ignore; import org.junit.Rule; @@ -37,8 +35,10 @@ import java.io.IOException; import static org.apache.tools.ant.AntAssert.assertContains; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; /** * Tests FileSet using the Copy task. @@ -78,7 +78,7 @@ public class CopyTest { public void test3() { buildRule.executeTarget("test3"); File file3 = new File(buildRule.getProject().getProperty("output"), "copytest3.tmp"); - //rollback file timestamp instead of delaying test + // rollback file timestamp instead of delaying test FileUtilities.rollbackTimestamps(file3, 3); buildRule.executeTarget("test3Part2"); assertTrue(file3.exists()); @@ -90,19 +90,14 @@ public class CopyTest { File file3c = new File(buildRule.getProject().getProperty("output"), "copytest3c.tmp"); assertTrue(file3c.exists()); - //file length checks rely on touch generating a zero byte file - if (file3.length()==0) { - fail("could not overwrite an existing, older file"); - } - if (file3c.length()!=0) { - fail("could not force overwrite an existing, newer file"); - } - if (file3b.length()==0) { - fail("unexpectedly overwrote an existing, newer file"); - } + // file length checks rely on touch generating a zero byte file + + assertNotEquals("could not overwrite an existing, older file", 0, file3.length()); + assertEquals("could not force overwrite an existing, newer file", 0, file3c.length()); + assertNotEquals("unexpectedly overwrote an existing, newer file", 0, file3b.length()); - //file time checks for java1.2+ - assertTrue(file3a.lastModified() == file3.lastModified()); + // file time checks for java1.2+ + assertEquals(file3a.lastModified(), file3.lastModified()); assertTrue(file3c.lastModified() < file3a.lastModified()); } @@ -293,14 +288,14 @@ public class CopyTest { @Test public void testCopyToSymlinkedSelf() throws Exception { // we are only going to test against systems that support symlinks - Assume.assumeTrue("Symlinks not supported on this operating system", Os.isFamily(Os.FAMILY_UNIX)); + assumeTrue("Symlinks not supported on this operating system", Os.isFamily(Os.FAMILY_UNIX)); // setup the source files to run copying against buildRule.executeTarget("setupSelfCopyTesting"); final File testDir = new File(buildRule.getProject().getProperty("self.copy.test.root.dir")); - Assert.assertTrue(testDir + " was expected to be a directory", testDir.isDirectory()); + assertTrue(testDir + " was expected to be a directory", testDir.isDirectory()); final File srcFile = new File(testDir, "file.txt"); - Assert.assertTrue("Source file " + srcFile + " was expected to be a file", srcFile.isFile()); + assertTrue("Source file " + srcFile + " was expected to be a file", srcFile.isFile()); final long originalFileSize = srcFile.length(); final String originalContent; final BufferedReader reader = new BufferedReader(new FileReader(srcFile)); @@ -309,26 +304,26 @@ public class CopyTest { } finally { reader.close(); } - Assert.assertTrue("Content missing in file " + srcFile, originalContent != null && originalContent.length() > 0); + assertTrue("Content missing in file " + srcFile, originalContent != null && originalContent.length() > 0); // run the copy tests buildRule.executeTarget("testSelfCopy"); // make sure the source file hasn't been impacted by the copy assertSizeAndContent(srcFile, originalFileSize, originalContent); final File symlinkedFile = new File(testDir, "sylmink-file.txt"); - Assert.assertTrue(symlinkedFile + " was expected to be a file", symlinkedFile.isFile()); + assertTrue(symlinkedFile + " was expected to be a file", symlinkedFile.isFile()); assertSizeAndContent(symlinkedFile, originalFileSize, originalContent); final File symlinkedTestDir = new File(buildRule.getProject().getProperty("self.copy.test.symlinked.dir")); - Assert.assertTrue(symlinkedTestDir + " was expected to be a directory", symlinkedTestDir.isDirectory()); + assertTrue(symlinkedTestDir + " was expected to be a directory", symlinkedTestDir.isDirectory()); assertSizeAndContent(new File(symlinkedTestDir, "file.txt"), originalFileSize, originalContent); assertSizeAndContent(new File(symlinkedTestDir, "sylmink-file.txt"), originalFileSize, originalContent); } private void assertSizeAndContent(final File file, final long expectedSize, final String expectedContent) throws IOException { - Assert.assertTrue(file + " was expected to be a file", file.isFile()); - Assert.assertEquals("Unexpected size of file " + file, expectedSize, file.length()); + assertTrue(file + " was expected to be a file", file.isFile()); + assertEquals("Unexpected size of file " + file, expectedSize, file.length()); final BufferedReader reader = new BufferedReader(new FileReader(file)); final String content; try { @@ -336,6 +331,6 @@ public class CopyTest { } finally { reader.close(); } - Assert.assertEquals("Unexpected content in file " + file, expectedContent, content); + assertEquals("Unexpected content in file " + file, expectedContent, content); } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ExecStreamRedirectorTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ExecStreamRedirectorTest.java index 4b359e3e4..7a519469d 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ExecStreamRedirectorTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ExecStreamRedirectorTest.java @@ -11,7 +11,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.util.Arrays; -import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -57,7 +57,7 @@ public class ExecStreamRedirectorTest { assertTrue(redirectedOutputFile + " is missing or not a regular file", redirectedOutputFile.isFile()); final byte[] redirectedOutput = readAllBytes(redirectedOutputFile); assertNotNull("No content was redirected to " + redirectedOutputFile, redirectedOutput); - assertFalse("Content in redirected file " + redirectedOutputFile + " was empty", redirectedOutput.length == 0); + assertNotEquals("Content in redirected file " + redirectedOutputFile + " was empty", 0, redirectedOutput.length); if (dirListingOutput != null) { // compare the directory listing that was redirected to these files. all files should have the same content assertTrue("Redirected output in file " + redirectedOutputFile + diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ImportTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ImportTest.java index 40a52cd4f..79c3b3d26 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ImportTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ImportTest.java @@ -22,7 +22,6 @@ import static org.apache.tools.ant.AntAssert.assertContains; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.File; @@ -53,8 +52,7 @@ public class ImportTest { buildRule.configureProject("src/etc/testcases/taskdefs/import/unnamedImport.xml", Project.MSG_WARN); String log = buildRule.getLog(); - assertTrue("Warnings logged when not expected: " + log, - log.length() == 0); + assertEquals("Warnings logged when not expected: " + log, 0, log.length()); } @Test 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 5579f85d5..03804dcbb 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java @@ -41,8 +41,8 @@ import org.junit.Test; import org.junit.internal.AssumptionViolatedException; import static org.apache.tools.ant.AntAssert.assertContains; -import org.junit.Assert; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -169,7 +169,7 @@ public class JavaTest { java.setJvmargs("-Xmx128M"); java.setArgs(arg); final String[] cmdLine = java.getCommandLine().getCommandline(); - Assert.assertNotNull("Has command line.", cmdLine); + assertNotNull("Has command line.", cmdLine); assertEquals("Command line should have 5 elements", 5, cmdLine.length); assertEquals("Last command line element should be java argument: " + arg, arg, @@ -195,7 +195,7 @@ public class JavaTest { java.setJvmargs("-Xmx128M"); //NOI18N java.setArgs(arg); final String[] cmdLine = java.getCommandLine().getCommandline(); - Assert.assertNotNull("Has command line.", cmdLine); + assertNotNull("Has command line.", cmdLine); assertEquals("Command line should have 5 elements", 5, cmdLine.length); assertEquals("Last command line element should be java argument: " + arg, arg, 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 3d2ff4fc9..7dabd3dfe 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ReplaceTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ReplaceTest.java @@ -148,7 +148,7 @@ public class ReplaceTest { testFile.setLastModified(testFile.lastModified() - FileUtils.getFileUtils().getFileTimestampGranularity() * 5)); long ts1 = testFile.lastModified(); buildRule.executeTarget("testPreserve"); - assertTrue(ts1 == new File(buildRule.getOutputDir(), "test.txt").lastModified()); + assertEquals(ts1, new File(buildRule.getOutputDir(), "test.txt").lastModified()); } public void assertEqualContent(File expect, File result) 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 91073bdb9..8a691257c 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java @@ -29,6 +29,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; @@ -124,7 +125,7 @@ public class SignJarTest { File f = new File(testJarParent, "../" + testJarParent.getName() + "/" + testJar.getName()); - assertFalse(testJar.equals(f)); + assertNotEquals(testJar, f); assertEquals(testJar.getCanonicalPath(), f.getCanonicalPath()); SignJar s = new SignJar(); s.setProject(buildRule.getProject()); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java index b2e285847..9f93706e8 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java @@ -36,11 +36,10 @@ import org.junit.Test; import static org.apache.tools.ant.AntAssert.assertContains; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; import static org.junit.Assume.assumeTrue; - public class ZipTest { @Rule @@ -138,12 +137,12 @@ public class ZipTest { ZipFile zipFile = new ZipFile(new File(buildRule.getProject().getProperty("output"), "zipgroupfileset.zip")); - assertTrue(zipFile.getEntry("ant.xml") != null); - assertTrue(zipFile.getEntry("optional/jspc.xml") != null); - assertTrue(zipFile.getEntry("zip/zipgroupfileset3.zip") != null); + assertNotNull(zipFile.getEntry("ant.xml")); + assertNotNull(zipFile.getEntry("optional/jspc.xml")); + assertNotNull(zipFile.getEntry("zip/zipgroupfileset3.zip")); - assertTrue(zipFile.getEntry("test6.mf") == null); - assertTrue(zipFile.getEntry("test7.mf") == null); + assertNull(zipFile.getEntry("test6.mf")); + assertNull(zipFile.getEntry("test7.mf")); zipFile.close(); } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java index 2791e7dfe..dd9563461 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java @@ -30,12 +30,14 @@ import org.apache.tools.ant.taskdefs.Javac; import org.apache.tools.ant.types.Commandline; import org.junit.Test; -import static org.apache.tools.ant.AntAssert.assertContains; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.util.FileUtils; -import org.junit.Assert; + +import static org.apache.tools.ant.AntAssert.assertContains; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class DefaultCompilerAdapterTest { @@ -263,17 +265,17 @@ public class DefaultCompilerAdapterTest { javac.setIncludeantruntime(false); javac.add(impl); javac.execute(); - Assert.assertNotNull(cmd[0]); + assertNotNull(cmd[0]); final List cmdLine = Arrays.asList(cmd[0].getCommandline()); //No modulesourcepath assertEquals(-1, cmdLine.indexOf("--module-source-path")); //The -sourcepath has to be followed by src int index = cmdLine.indexOf("-sourcepath"); - Assert.assertTrue(index != -1 && index < cmdLine.size() - 1); + assertTrue(index != -1 && index < cmdLine.size() - 1); assertEquals(src.getAbsolutePath(), cmdLine.get(index + 1)); //The --module-path has to be followed by modules index = cmdLine.indexOf("--module-path"); - Assert.assertTrue(index != -1 && index < cmdLine.size() - 1); + assertTrue(index != -1 && index < cmdLine.size() - 1); assertEquals(modules.getAbsolutePath(), cmdLine.get(index + 1)); //J1.java & J2.java has to be in files list final Set expected = new TreeSet(); @@ -321,13 +323,13 @@ public class DefaultCompilerAdapterTest { javac.setIncludeantruntime(false); javac.add(impl); javac.execute(); - Assert.assertNotNull(cmd[0]); + assertNotNull(cmd[0]); final List cmdLine = Arrays.asList(cmd[0].getCommandline()); //No sourcepath assertEquals(-1, cmdLine.indexOf("-sourcepath")); //The --module-source-path has to be followed by the pattern int index = cmdLine.indexOf("--module-source-path"); - Assert.assertTrue(index != -1 && index < cmdLine.size() - 1); + assertTrue(index != -1 && index < cmdLine.size() - 1); String expectedModSrcPath = String.format("%s/%s", workDir.getAbsolutePath(), moduleSrcPathStr) @@ -336,7 +338,7 @@ public class DefaultCompilerAdapterTest { assertEquals(expectedModSrcPath, cmdLine.get(index + 1)); //The --module-path has to be followed by modules index = cmdLine.indexOf("--module-path"); - Assert.assertTrue(index != -1 && index < cmdLine.size() - 1); + assertTrue(index != -1 && index < cmdLine.size() - 1); assertEquals(modules.getAbsolutePath(), cmdLine.get(index + 1)); //J1.java, J2.java & J3.java has to be in files list final Set expectedFiles = new TreeSet(); @@ -386,7 +388,7 @@ public class DefaultCompilerAdapterTest { javac.add(impl); javac.execute(); final File[] compileList = impl.compileList; - Assert.assertNotNull(compileList); + assertNotNull(compileList); //J1.java, J2.java has to be in files list but not J3.java final Set expectedFiles = new TreeSet(); Collections.addAll(expectedFiles, diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java index 3ec210e48..555ab2f8c 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java @@ -181,9 +181,8 @@ public class JspcTest { */ protected void assertMapped(JspMangler mangler, String filename, String classname) { String mappedname = mangler.mapJspToJavaName(new File(filename)); - assertTrue(filename + " should have mapped to " + classname - + " but instead mapped to " + mappedname, - classname.equals(mappedname)); + assertEquals(filename + " should have mapped to " + classname + + " but instead mapped to " + mappedname, classname, mappedname); } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java index 7ccf00aa9..3896c8f18 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java @@ -81,9 +81,9 @@ public class PropertyFileTest { assertEquals(FNAME, beforeUpdate.getProperty(FNAME_KEY)); assertEquals(LNAME, beforeUpdate.getProperty(LNAME_KEY)); assertEquals(EMAIL, beforeUpdate.getProperty(EMAIL_KEY)); - assertEquals(null, beforeUpdate.getProperty(PHONE_KEY)); - assertEquals(null, beforeUpdate.getProperty(AGE_KEY)); - assertEquals(null, beforeUpdate.getProperty(DATE_KEY)); + assertNull(beforeUpdate.getProperty(PHONE_KEY)); + assertNull(beforeUpdate.getProperty(AGE_KEY)); + assertNull(beforeUpdate.getProperty(DATE_KEY)); // ask ant to update the properties... buildRule.executeTarget("update-existing-properties"); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java index 2b8b58294..0d91edeb6 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java @@ -29,6 +29,7 @@ import org.junit.Test; import java.io.File; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; @@ -96,7 +97,7 @@ public class ImageTest { AntAssert.assertContains("Processing File", buildRule.getLog()); f = new File(buildRule.getOutputDir(), LARGEIMAGE); long overwrittenLastModified = f.lastModified(); - assertTrue("File was overwritten.", lastModified == overwrittenLastModified); + assertEquals("File was overwritten.", lastModified, overwrittenLastModified); } @Test diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTaskTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTaskTest.java index 84d4875ce..1649a84c8 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTaskTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTaskTest.java @@ -5,12 +5,13 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildListener; import org.apache.tools.ant.Project; import org.apache.tools.ant.ProjectHelper; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; import java.io.File; +import static org.junit.Assert.fail; + /** * Tests the {@link JUnitLauncherTask} */ @@ -75,7 +76,7 @@ public class JUnitLauncherTaskTest { public void testFailureStopsBuild() { try { project.executeTarget("test-failure-stops-build"); - Assert.fail("Test execution failure was expected to stop the build but didn't"); + fail("Test execution failure was expected to stop the build but didn't"); } catch (BuildException be) { // expected } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java index 23f372558..717baecb0 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java @@ -35,16 +35,16 @@ import org.apache.tools.ant.taskdefs.condition.Os; import org.apache.tools.ant.Project; import org.apache.tools.ant.util.SymbolicLinkUtils; import org.junit.After; -import org.junit.Assert; -import org.junit.Assume; import org.junit.Before; 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.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; import java.io.File; import java.nio.file.Files; @@ -69,7 +69,7 @@ public class SymlinkTest { @Before public void setUp() { - Assume.assumeTrue("Symlinks not supported on current operating system", supportsSymlinks); + assumeTrue("Symlinks not supported on current operating system", supportsSymlinks); buildRule.configureProject("src/etc/testcases/taskdefs/optional/unix/symlink.xml"); buildRule.executeTarget("setUp"); } @@ -274,8 +274,8 @@ public class SymlinkTest { assertFalse(f.exists()); assertFalse(f.isDirectory()); assertFalse(f.isFile()); - assertTrue(su.isSymbolicLink(f.getAbsolutePath()) == false); - assertTrue(su.isSymbolicLink(f.getParentFile(), f.getName()) == false); + assertFalse(su.isSymbolicLink(f.getAbsolutePath())); + assertFalse(su.isSymbolicLink(f.getParentFile(), f.getName())); assertTrue(su.isDanglingSymbolicLink(f.getAbsolutePath())); assertTrue(su.isDanglingSymbolicLink(f.getParentFile(), f.getName())); @@ -284,8 +284,8 @@ public class SymlinkTest { assertFalse(f.exists()); assertFalse(f.isDirectory()); assertFalse(f.isFile()); - assertTrue(su.isSymbolicLink(f.getAbsolutePath()) == false); - assertTrue(su.isSymbolicLink(f.getParentFile(), f.getName()) == false); + assertFalse(su.isSymbolicLink(f.getAbsolutePath())); + assertFalse(su.isSymbolicLink(f.getParentFile(), f.getName())); assertTrue(su.isDanglingSymbolicLink(f.getAbsolutePath())); assertTrue(su.isDanglingSymbolicLink(f.getParentFile(), f.getName())); @@ -305,10 +305,10 @@ public class SymlinkTest { buildRule.executeTarget("test-overwrite-link"); final Project p = buildRule.getProject(); final String linkTargetResource = p.getProperty("test.overwrite.link.target.dir"); - Assert.assertNotNull("Property test.overwrite.link.target.dir is not set", linkTargetResource); + assertNotNull("Property test.overwrite.link.target.dir is not set", linkTargetResource); final Path targetResourcePath = Paths.get(linkTargetResource); - Assert.assertTrue(targetResourcePath + " is not a directory", Files.isDirectory(targetResourcePath)); - Assert.assertEquals(targetResourcePath + " directory was expected to be empty", 0, Files.list(targetResourcePath).count()); + assertTrue(targetResourcePath + " is not a directory", Files.isDirectory(targetResourcePath)); + assertEquals(targetResourcePath + " directory was expected to be empty", 0, Files.list(targetResourcePath).count()); } @After diff --git a/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java b/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java index 391e248f6..7d002e516 100644 --- a/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java @@ -24,7 +24,6 @@ import org.apache.tools.ant.BuildException; import org.junit.Test; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** @@ -107,14 +106,10 @@ public class TarFileSetTest extends AbstractFileSetTest { getProject().addReference("test", f); TarFileSet zid = (TarFileSet) getInstance(); zid.setRefid(new Reference(getProject(), "test")); - assertTrue("src attribute copied by copy constructor", - zid.getSrc(getProject()).equals(f.getSrc(getProject()))); - assertTrue("prefix attribute copied by copy constructor", - f.getPrefix(getProject()).equals(zid.getPrefix(getProject()))); - assertTrue("file mode attribute copied by copy constructor", - f.getFileMode(getProject()) == zid.getFileMode(getProject())); - assertTrue("dir mode attribute copied by copy constructor", - f.getDirMode(getProject()) == zid.getDirMode(getProject())); + assertEquals("src attribute copied by copy constructor", zid.getSrc(getProject()), f.getSrc(getProject())); + assertEquals("prefix attribute copied by copy constructor", f.getPrefix(getProject()), zid.getPrefix(getProject())); + assertEquals("file mode attribute copied by copy constructor", f.getFileMode(getProject()), zid.getFileMode(getProject())); + assertEquals("dir mode attribute copied by copy constructor", f.getDirMode(getProject()), zid.getDirMode(getProject())); } } diff --git a/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java b/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java index c89b42040..b4637da7b 100644 --- a/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java @@ -24,7 +24,6 @@ import org.apache.tools.ant.BuildException; import org.junit.Test; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** @@ -106,10 +105,8 @@ public class ZipFileSetTest extends AbstractFileSetTest { getProject().addReference("test", f); ZipFileSet zid = (ZipFileSet) getInstance(); zid.setRefid(new Reference(getProject(), "test")); - assertTrue("src attribute copied by copy constructor", - zid.getSrc(getProject()).equals(f.getSrc(getProject()))); - assertTrue("prefix attribute copied by copy constructor", - f.getPrefix(getProject()).equals(zid.getPrefix(getProject()))); + assertEquals("src attribute copied by copy constructor", zid.getSrc(getProject()), f.getSrc(getProject())); + assertEquals("prefix attribute copied by copy constructor", f.getPrefix(getProject()), zid.getPrefix(getProject())); assertEquals("file mode attribute copied by copy constructor", f.getFileMode(getProject()), zid.getFileMode(getProject())); assertEquals("dir mode attribute copied by copy constructor", 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 9be4d63b2..01c16e404 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 @@ -18,7 +18,6 @@ package org.apache.tools.ant.types.selectors; - import java.io.File; import java.io.FileWriter; import java.text.RuleBasedCollator; @@ -51,6 +50,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.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -189,7 +189,7 @@ public class ModifiedSelectorTest { assertNotNull("'fs.mod.value' must be set.", fsModValue); // must be empty according to the Mock* implementations - assertTrue("'fs.mod.value' must be empty.", "".equals(fsModValue)); + assertEquals("'fs.mod.value' must be empty.", "", fsModValue); } finally { bft.doTarget("modifiedselectortest-scenario-clean"); bft.deletePropertiesfile(); @@ -602,9 +602,9 @@ public class ModifiedSelectorTest { Object o2 = "string2"; Object o3 = "string2"; // really "2" - assertTrue("Comparator gave wrong value.", comp.compare(o1, o2) != 0); - assertTrue("Comparator gave wrong value.", comp.compare(o1, o3) != 0); - assertTrue("Comparator gave wrong value.", comp.compare(o2, o3) == 0); + assertNotEquals("Comparator gave wrong value.", 0, comp.compare(o1, o2)); + assertNotEquals("Comparator gave wrong value.", 0, comp.compare(o1, o3)); + assertEquals("Comparator gave wrong value.", 0, comp.compare(o2, o3)); } // ===================== scenario tests ===================== @@ -837,8 +837,8 @@ public class ModifiedSelectorTest { // do the checks assertTrue("Cache file not created.", cachefile.exists()); assertTrue("Not enough files copied on first time.", to1.list().length > 5); - assertTrue("Too much files copied on second time.", to2.list().length == 0); - assertTrue("Too much files copied on third time.", to3.list().length == 2); + assertEquals("Too much files copied on second time.", 0, to2.list().length); + assertEquals("Too much files copied on third time.", 2, to3.list().length); // don't catch the JUnit exceptions } finally { bft.doTarget("modifiedselectortest-scenario-clean"); diff --git a/src/tests/junit/org/apache/tools/ant/util/ClasspathUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/ClasspathUtilsTest.java index ce6486b7a..916915638 100644 --- a/src/tests/junit/org/apache/tools/ant/util/ClasspathUtilsTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/ClasspathUtilsTest.java @@ -26,7 +26,7 @@ import org.apache.tools.ant.Project; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; /** @@ -61,6 +61,6 @@ public class ClasspathUtilsTest { list.append(" ").append(enumeration.nextElement()); count++; } - assertTrue("Should be only one and not " + count + " " + list, count == 1); + assertEquals("Should be only one and not " + count + " " + list, 1, count); } } diff --git a/src/tests/junit/org/apache/tools/ant/util/DeweyDecimalTest.java b/src/tests/junit/org/apache/tools/ant/util/DeweyDecimalTest.java index e8e8cbd5c..d16ba1578 100644 --- a/src/tests/junit/org/apache/tools/ant/util/DeweyDecimalTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/DeweyDecimalTest.java @@ -18,12 +18,12 @@ package org.apache.tools.ant.util; +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 org.junit.Test; - public class DeweyDecimalTest { @Test @@ -55,21 +55,21 @@ public class DeweyDecimalTest { @Test public void testEquals() { - assertTrue(new DeweyDecimal("1.2.3").equals(new DeweyDecimal("1.2.3"))); - assertFalse(new DeweyDecimal("1.2.3").equals(new DeweyDecimal("1.2.4"))); - assertTrue(new DeweyDecimal("1.2.0").equals(new DeweyDecimal("1.2"))); - assertTrue(new DeweyDecimal("1.2").equals(new DeweyDecimal("1.2.0"))); + assertEquals(new DeweyDecimal("1.2.3"), new DeweyDecimal("1.2.3")); + assertNotEquals(new DeweyDecimal("1.2.3"), new DeweyDecimal("1.2.4")); + assertEquals(new DeweyDecimal("1.2.0"), new DeweyDecimal("1.2")); + assertEquals(new DeweyDecimal("1.2"), new DeweyDecimal("1.2.0")); } @Test public void compareTo() { assertTrue(new DeweyDecimal("1.2.3").compareTo(new DeweyDecimal("1.2")) > 0); assertTrue(new DeweyDecimal("1.2").compareTo(new DeweyDecimal("1.2.3")) < 0); - assertTrue(new DeweyDecimal("1.2.3").compareTo(new DeweyDecimal("1.2.3")) == 0); + assertEquals(0, new DeweyDecimal("1.2.3").compareTo(new DeweyDecimal("1.2.3"))); assertTrue(new DeweyDecimal("1.2.3").compareTo(new DeweyDecimal("1.1.4")) > 0); assertTrue(new DeweyDecimal("1.2.3").compareTo(new DeweyDecimal("1.2.2.9")) > 0); - assertTrue(new DeweyDecimal("1.2.0").compareTo(new DeweyDecimal("1.2")) == 0); - assertTrue(new DeweyDecimal("1.2").compareTo(new DeweyDecimal("1.2.0")) == 0); + assertEquals(0, new DeweyDecimal("1.2.0").compareTo(new DeweyDecimal("1.2"))); + assertEquals(0, new DeweyDecimal("1.2").compareTo(new DeweyDecimal("1.2.0"))); } // TODO isGreaterThan, ... diff --git a/src/tests/junit/org/apache/tools/zip/ZipEncodingTest.java b/src/tests/junit/org/apache/tools/zip/ZipEncodingTest.java index f05d55348..66418ce2e 100644 --- a/src/tests/junit/org/apache/tools/zip/ZipEncodingTest.java +++ b/src/tests/junit/org/apache/tools/zip/ZipEncodingTest.java @@ -25,6 +25,8 @@ import java.nio.ByteBuffer; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * Test zip encodings. @@ -133,15 +135,15 @@ public class ZipEncodingTest { String decoded = enc.decode(testBytes); - assertEquals(true, enc.canEncode(decoded)); + assertTrue(enc.canEncode(decoded)); ByteBuffer encoded = enc.encode(decoded); assertByteEquals(testBytes, encoded); - assertEquals(false, enc.canEncode(UNENC_STRING)); + assertFalse(enc.canEncode(UNENC_STRING)); assertByteEquals("%U2016".getBytes("US-ASCII"), enc.encode(UNENC_STRING)); - assertEquals(false, enc.canEncode(BAD_STRING)); + assertFalse(enc.canEncode(BAD_STRING)); assertByteEquals(BAD_STRING_ENC.getBytes("US-ASCII"), enc.encode(BAD_STRING)); } diff --git a/src/tests/junit/org/apache/tools/zip/ZipEntryTest.java b/src/tests/junit/org/apache/tools/zip/ZipEntryTest.java index fc30eca23..290694ffc 100644 --- a/src/tests/junit/org/apache/tools/zip/ZipEntryTest.java +++ b/src/tests/junit/org/apache/tools/zip/ZipEntryTest.java @@ -23,7 +23,7 @@ import org.junit.Test; import java.util.NoSuchElementException; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; @@ -210,7 +210,7 @@ public class ZipEntryTest { public void testNotEquals() { ZipEntry entry1 = new ZipEntry("foo"); ZipEntry entry2 = new ZipEntry("bar"); - assertFalse(entry1.equals(entry2)); + assertNotEquals(entry1, entry2); } @Test diff --git a/src/tests/junit/org/apache/tools/zip/ZipLongTest.java b/src/tests/junit/org/apache/tools/zip/ZipLongTest.java index 69338407a..04c47c7f9 100644 --- a/src/tests/junit/org/apache/tools/zip/ZipLongTest.java +++ b/src/tests/junit/org/apache/tools/zip/ZipLongTest.java @@ -63,12 +63,12 @@ public class ZipLongTest { ZipLong zl2 = new ZipLong(0x12345678); ZipLong zl3 = new ZipLong(0x87654321); - assertTrue("reflexive", zl.equals(zl)); + assertEquals("reflexive", zl, zl); - assertTrue("works", zl.equals(zl2)); + assertEquals("works", zl, zl2); assertTrue("works, part two", !zl.equals(zl3)); - assertTrue("symmetric", zl2.equals(zl)); + assertEquals("symmetric", zl2, zl); assertTrue("null handling", !zl.equals(null)); assertTrue("non ZipLong handling", !zl.equals(0x1234)); diff --git a/src/tests/junit/org/apache/tools/zip/ZipShortTest.java b/src/tests/junit/org/apache/tools/zip/ZipShortTest.java index 5938db31f..0f191e8f2 100644 --- a/src/tests/junit/org/apache/tools/zip/ZipShortTest.java +++ b/src/tests/junit/org/apache/tools/zip/ZipShortTest.java @@ -60,12 +60,12 @@ public class ZipShortTest { ZipShort zs2 = new ZipShort(0x1234); ZipShort zs3 = new ZipShort(0x5678); - assertTrue("reflexive", zs.equals(zs)); + assertEquals("reflexive", zs, zs); - assertTrue("works", zs.equals(zs2)); + assertEquals("works", zs, zs2); assertTrue("works, part two", !zs.equals(zs3)); - assertTrue("symmetric", zs2.equals(zs)); + assertEquals("symmetric", zs2, zs); assertTrue("null handling", !zs.equals(null)); assertTrue("non ZipShort handling", !zs.equals(0x1234)); diff --git a/src/tests/junit/org/example/junitlauncher/vintage/JUnit4SampleTest.java b/src/tests/junit/org/example/junitlauncher/vintage/JUnit4SampleTest.java index f5896e1d3..f9cef561c 100644 --- a/src/tests/junit/org/example/junitlauncher/vintage/JUnit4SampleTest.java +++ b/src/tests/junit/org/example/junitlauncher/vintage/JUnit4SampleTest.java @@ -1,8 +1,11 @@ package org.example.junitlauncher.vintage; -import org.junit.Assert; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * */ @@ -10,16 +13,16 @@ public class JUnit4SampleTest { @Test public void testFoo() { - Assert.assertEquals(1, 1); + assertEquals(1, 1); } @Test public void testBar() { - Assert.assertTrue(true); + assertTrue(true); } @Test public void testFooBar() { - Assert.assertFalse(false); + assertFalse(false); } }