CollectionUtilsTest class.
@@ -35,12 +35,12 @@ * @version $Id: $Id * @since 3.4.0 */ -public class CollectionUtilsTest { +class CollectionUtilsTest { /** *testMergeMaps.
*/ @Test - public void testMergeMaps() { + void mergeMaps() { MaptestMavenPropertiesLoading.
*/ @Test - public void testMavenPropertiesLoading() { + void mavenPropertiesLoading() { // Mimic MavenSession properties loading. Properties listed // in dominant order. Properties systemProperties = new Properties(); @@ -193,7 +193,7 @@ public void testMavenPropertiesLoading() { *testIteratorToListWithAPopulatedList.
*/ @Test - public void testIteratorToListWithAPopulatedList() { + void iteratorToListWithAPopulatedList() { ListtestIteratorToListWithAEmptyList.
*/ @Test - public void testIteratorToListWithAEmptyList() { + void iteratorToListWithAEmptyList() { ListsetUp.
*/ - @Before - public void setUp() { + @BeforeEach + void setUp(TestInfo testInfo) { + testInfo.getTestMethod().ifPresent(method -> this.name = method.getName()); try { FileUtils.deleteDirectory(testDir); } catch (IOException e) { @@ -72,7 +72,7 @@ public void setUp() { * @throws java.net.URISyntaxException if any. */ @Test - public void testCrossPlatformIncludesString() throws IOException, URISyntaxException { + void crossPlatformIncludesString() throws IOException, URISyntaxException { DirectoryScanner ds = new DirectoryScanner(); ds.setBasedir(new File(getTestResourcesDir() + File.separator + "directory-scanner").getCanonicalFile()); @@ -98,7 +98,7 @@ public void testCrossPlatformIncludesString() throws IOException, URISyntaxExcep * @throws java.net.URISyntaxException if any. */ @Test - public void testCrossPlatformExcludesString() throws IOException, URISyntaxException { + void crossPlatformExcludesString() throws IOException, URISyntaxException { DirectoryScanner ds = new DirectoryScanner(); ds.setBasedir(new File(getTestResourcesDir() + File.separator + "directory-scanner").getCanonicalFile()); ds.setIncludes(new String[] {"**"}); @@ -161,11 +161,10 @@ private boolean checkTestFilesSymlinks() { } return true; } catch (IOException e) { - System.err.println(String.format( - "The unit test '%s.%s' will be skipped, reason: %s", - this.getClass().getSimpleName(), name.getMethodName(), e.getMessage())); - System.out.println( - String.format("This test requires symlinks files in '%s' directory.", symlinksDirectory.getPath())); + System.err.printf( + "The unit test '%s.%s' will be skipped, reason: %s%n", + this.getClass().getSimpleName(), name, e.getMessage()); + System.out.printf("This test requires symlinks files in '%s' directory.%n", symlinksDirectory.getPath()); System.out.println("On some OS (like Windows 10), files are present only if the clone/checkout is done" + " in administrator mode, and correct (symlinks and not flat file/directory)" + " if symlinks option are used (for git: git clone -c core.symlinks=true [url])"); @@ -179,7 +178,7 @@ private boolean checkTestFilesSymlinks() { * @throws java.io.IOException if any. */ @Test - public void testGeneral() throws IOException { + void general() throws IOException { this.createTestFiles(); String includes = "scanner1.dat,scanner2.dat,scanner3.dat,scanner4.dat,scanner5.dat"; @@ -187,10 +186,10 @@ public void testGeneral() throws IOException { ListtestFollowSymlinksFalse.
*/ @Test - public void testFollowSymlinksFalse() { + void followSymlinksFalse() { assumeTrue(checkTestFilesSymlinks()); DirectoryScanner ds = new DirectoryScanner(); @@ -253,7 +252,7 @@ private void assertAlwaysIncluded(ListtestFollowSymlinks.
*/ @Test - public void testFollowSymlinks() { + void followSymlinks() { assumeTrue(checkTestFilesSymlinks()); DirectoryScanner ds = new DirectoryScanner(); @@ -300,7 +299,7 @@ private void createTestDirectories() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testDirectoriesWithHyphens() throws IOException { + void directoriesWithHyphens() throws IOException { this.createTestDirectories(); DirectoryScanner ds = new DirectoryScanner(); @@ -313,7 +312,7 @@ public void testDirectoriesWithHyphens() throws IOException { ds.scan(); String[] files = ds.getIncludedFiles(); - assertEquals("Wrong number of results.", 3, files.length); + assertEquals(3, files.length, "Wrong number of results."); } /** @@ -322,7 +321,7 @@ public void testDirectoriesWithHyphens() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testAntExcludesOverrideIncludes() throws IOException { + void antExcludesOverrideIncludes() throws IOException { printTestHeader(); File dir = new File(testDir, "regex-dir"); @@ -360,7 +359,7 @@ public void testAntExcludesOverrideIncludes() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testAntExcludesOverrideIncludesWithExplicitAntPrefix() throws IOException { + void antExcludesOverrideIncludesWithExplicitAntPrefix() throws IOException { printTestHeader(); File dir = new File(testDir, "regex-dir"); @@ -399,7 +398,7 @@ public void testAntExcludesOverrideIncludesWithExplicitAntPrefix() throws IOExce * @throws java.io.IOException if any. */ @Test - public void testRegexIncludeWithExcludedPrefixDirs() throws IOException { + void regexIncludeWithExcludedPrefixDirs() throws IOException { printTestHeader(); File dir = new File(testDir, "regex-dir"); @@ -433,7 +432,7 @@ public void testRegexIncludeWithExcludedPrefixDirs() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testRegexExcludeWithNegativeLookahead() throws IOException { + void regexExcludeWithNegativeLookahead() throws IOException { printTestHeader(); File dir = new File(testDir, "regex-dir"); @@ -472,7 +471,7 @@ public void testRegexExcludeWithNegativeLookahead() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testRegexWithSlashInsideCharacterClass() throws IOException { + void regexWithSlashInsideCharacterClass() throws IOException { printTestHeader(); File dir = new File(testDir, "regex-dir"); @@ -513,7 +512,7 @@ public void testRegexWithSlashInsideCharacterClass() throws IOException { * @throws java.io.IOException if occurs an I/O error. */ @Test - public void testDoNotScanUnnecesaryDirectories() throws IOException { + void doNotScanUnnecesaryDirectories() throws IOException { createTestDirectories(); // create additional directories 'anotherDir1', 'anotherDir2' and 'anotherDir3' with a 'file1.dat' file @@ -582,7 +581,7 @@ protected void scandir(File dir, String vpath, boolean fast) { * @throws java.io.IOException if any. */ @Test - public void testIsSymbolicLink() throws IOException { + void isSymbolicLink() throws IOException { assumeTrue(checkTestFilesSymlinks()); final File directory = new File("src/test/resources/symlinks/src"); @@ -599,7 +598,7 @@ public void testIsSymbolicLink() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testIsParentSymbolicLink() throws IOException { + void isParentSymbolicLink() throws IOException { assumeTrue(checkTestFilesSymlinks()); final File directory = new File("src/test/resources/symlinks/src"); diff --git a/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java b/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java index 97786c51..f35062d7 100644 --- a/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java +++ b/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java @@ -18,11 +18,11 @@ import java.io.File; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** *DirectoryWalkerTest class.
@@ -31,12 +31,12 @@ * @version $Id: $Id * @since 3.4.0 */ -public class DirectoryWalkerTest { +class DirectoryWalkerTest { /** *testDirectoryWalk.
*/ @Test - public void testDirectoryWalk() { + void directoryWalk() { DirectoryWalker walker = new DirectoryWalker(); walker.addSCMExcludes(); @@ -48,11 +48,11 @@ public void testDirectoryWalk() { walker.scan(); - assertEquals("Walk Collector / Starting Count", 1, collector.startCount); - assertNotNull("Walk Collector / Starting Dir", collector.startingDir); - assertEquals("Walk Collector / Finish Count", 1, collector.finishCount); - assertEquals("Walk Collector / Steps Count", 4, collector.steps.size()); - assertTrue("Walk Collector / percentage low >= 0", collector.percentageLow >= 0); - assertTrue("Walk Collector / percentage high <= 100", collector.percentageHigh <= 100); + assertEquals(1, collector.startCount, "Walk Collector / Starting Count"); + assertNotNull(collector.startingDir, "Walk Collector / Starting Dir"); + assertEquals(1, collector.finishCount, "Walk Collector / Finish Count"); + assertEquals(4, collector.steps.size(), "Walk Collector / Steps Count"); + assertTrue(collector.percentageLow >= 0, "Walk Collector / percentage low >= 0"); + assertTrue(collector.percentageHigh <= 100, "Walk Collector / percentage high <= 100"); } } diff --git a/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java b/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java index 367eca64..d47e3ac2 100644 --- a/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java +++ b/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java @@ -26,17 +26,15 @@ import java.io.PrintWriter; import java.io.Writer; import java.nio.file.Files; -import java.util.Arrays; -import junit.framework.AssertionFailedError; +import org.opentest4j.AssertionFailedError; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Base class for testcases doing tests with files. * * @author Jeremias Maerki - * @version $Id: $Id * @since 3.4.0 */ public abstract class FileBasedTestCase { @@ -83,23 +81,18 @@ protected byte[] createFile(final File file, final long size) throws IOException /** *createSymlink.
* - * @param link a {@link java.io.File} object. + * @param link a {@link java.io.File} object. * @param target a {@link java.io.File} object. - * @return a boolean. */ - protected boolean createSymlink(final File link, final File target) { + protected void createSymlink(final File link, final File target) { try { String[] args = {"ln", "-s", target.getAbsolutePath(), link.getAbsolutePath()}; Process process = Runtime.getRuntime().exec(args); process.waitFor(); - if (0 != process.exitValue()) { - return false; - } + if (0 != process.exitValue()) {} } catch (Exception e) { // assume platform does not support "ln" command, tests should be skipped - return false; } - return true; } /** @@ -160,7 +153,7 @@ protected File newFile(String filename) throws IOException { * @throws java.lang.Exception if any. */ protected void checkFile(final File file, final File referenceFile) throws Exception { - assertTrue("Check existence of output file", file.exists()); + assertTrue(file.exists(), "Check existence of output file"); assertEqualContent(referenceFile, file); } @@ -168,9 +161,8 @@ protected void checkFile(final File file, final File referenceFile) throws Excep *checkWrite.
* * @param output a {@link java.io.OutputStream} object. - * @throws java.lang.Exception if any. */ - protected void checkWrite(final OutputStream output) throws Exception { + protected void checkWrite(final OutputStream output) { try { new PrintStream(output).write(0); } catch (final Throwable t) { @@ -202,7 +194,7 @@ protected void checkWrite(final Writer output) throws Exception { */ protected void deleteFile(final File file) throws Exception { if (file.exists()) { - assertTrue("Couldn't delete file: " + file, file.delete()); + assertTrue(file.delete(), "Couldn't delete file: " + file); } } @@ -217,10 +209,8 @@ private void assertEqualContent(final File f0, final File f1) throws IOException * + " and " + f1 + " have differing file sizes (" + f0.length() + " vs " + f1.length() + ")", ( f0.length() == * f1.length() ) ); */ - final InputStream is0 = Files.newInputStream(f0.toPath()); - try { - final InputStream is1 = Files.newInputStream(f1.toPath()); - try { + try (InputStream is0 = Files.newInputStream(f0.toPath())) { + try (InputStream is1 = Files.newInputStream(f1.toPath())) { final byte[] buf0 = new byte[1024]; final byte[] buf1 = new byte[1024]; int n0 = 0; @@ -230,17 +220,13 @@ private void assertEqualContent(final File f0, final File f1) throws IOException n0 = is0.read(buf0); n1 = is1.read(buf1); assertTrue( + (n0 == n1), "The files " + f0 + " and " + f1 + " have differing number of bytes available (" + n0 - + " vs " + n1 + ")", - (n0 == n1)); + + " vs " + n1 + ")"); - assertTrue("The files " + f0 + " and " + f1 + " have different content", Arrays.equals(buf0, buf1)); + assertArrayEquals(buf0, buf1, "The files " + f0 + " and " + f1 + " have different content"); } - } finally { - is1.close(); } - } finally { - is0.close(); } } @@ -252,17 +238,14 @@ private void assertEqualContent(final File f0, final File f1) throws IOException * @throws java.io.IOException if any. */ protected void assertEqualContent(final byte[] b0, final File file) throws IOException { - final InputStream is = Files.newInputStream(file.toPath()); - try { + try (InputStream is = Files.newInputStream(file.toPath())) { byte[] b1 = new byte[b0.length]; int numRead = is.read(b1); - assertTrue("Different number of bytes", numRead == b0.length && is.available() == 0); + assertTrue(numRead == b0.length && is.available() == 0, "Different number of bytes"); for (int i = 0; i < numRead; - assertTrue("Byte " + i + " differs (" + b0[i] + " != " + b1[i] + ")", b0[i] == b1[i]), i++) + assertEquals(b0[i], b1[i], "Byte " + i + " differs (" + b0[i] + " != " + b1[i] + ")"), i++) ; - } finally { - is.close(); } } @@ -272,9 +255,9 @@ protected void assertEqualContent(final byte[] b0, final File file) throws IOExc * @param file a {@link java.io.File} object. */ protected void assertIsDirectory(File file) { - assertTrue("The File doesn't exists: " + file.getAbsolutePath(), file.exists()); + assertTrue(file.exists(), "The File doesn't exists: " + file.getAbsolutePath()); - assertTrue("The File isn't a directory: " + file.getAbsolutePath(), file.isDirectory()); + assertTrue(file.isDirectory(), "The File isn't a directory: " + file.getAbsolutePath()); } /** @@ -283,8 +266,8 @@ protected void assertIsDirectory(File file) { * @param file a {@link java.io.File} object. */ protected void assertIsFile(File file) { - assertTrue("The File doesn't exists: " + file.getAbsolutePath(), file.exists()); + assertTrue(file.exists(), "The File doesn't exists: " + file.getAbsolutePath()); - assertTrue("The File isn't a file: " + file.getAbsolutePath(), file.isFile()); + assertTrue(file.isFile(), "The File isn't a file: " + file.getAbsolutePath()); } } diff --git a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java index dcfe8e4d..ed51f99a 100644 --- a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java @@ -24,22 +24,24 @@ import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; +import java.lang.reflect.Method; import java.net.URL; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.Optional; import java.util.Properties; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; -import static org.junit.Assert.assertEquals; -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.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * This is used to test FileUtils for correctness. @@ -51,8 +53,8 @@ * @since 3.4.0 */ public final class FileUtilsTest extends FileBasedTestCase { - @Rule - public TestName name = new TestName(); + + public String name; // Test data @@ -87,8 +89,12 @@ public FileUtilsTest() throws Exception { * * @throws java.lang.Exception if any. */ - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp(TestInfo testInfo) throws Exception { + OptionaltestByteCountToDisplaySize.
*/ @Test - public void testByteCountToDisplaySize() { - assertEquals(FileUtils.byteCountToDisplaySize(0), "0 bytes"); - assertEquals(FileUtils.byteCountToDisplaySize(1024), "1 KB"); - assertEquals(FileUtils.byteCountToDisplaySize(1024 * 1024), "1 MB"); - assertEquals(FileUtils.byteCountToDisplaySize(1024 * 1024 * 1024), "1 GB"); + void byteCountToDisplaySize() { + assertEquals("0 bytes", FileUtils.byteCountToDisplaySize(0)); + assertEquals("1 KB", FileUtils.byteCountToDisplaySize(1024)); + assertEquals("1 MB", FileUtils.byteCountToDisplaySize(1024 * 1024)); + assertEquals("1 GB", FileUtils.byteCountToDisplaySize(1024 * 1024 * 1024)); } // waitFor @@ -117,7 +123,7 @@ public void testByteCountToDisplaySize() { *testWaitFor.
*/ @Test - public void testWaitFor() { + void waitFor() { FileUtils.waitFor("", -1); FileUtils.waitFor("", 2); @@ -129,7 +135,7 @@ public void testWaitFor() { * @throws java.lang.Exception if any. */ @Test - public void testToFile() throws Exception { + void toFile() throws Exception { URL url = getClass().getResource("/test.txt"); url = new URL(url.toString() + "/name%20%23%2520%3F%7B%7D%5B%5D%3C%3E.txt"); File file = FileUtils.toFile(url); @@ -142,7 +148,7 @@ public void testToFile() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testToFileBadProtocol() throws Exception { + void toFileBadProtocol() throws Exception { URL url = new URL("http://maven.apache.org/"); File file = FileUtils.toFile(url); assertNull(file); @@ -154,7 +160,7 @@ public void testToFileBadProtocol() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testToFileNull() throws Exception { + void toFileNull() throws Exception { File file = FileUtils.toFile(null); assertNull(file); } @@ -166,7 +172,7 @@ public void testToFileNull() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testToURLs() throws Exception { + void toURLs() throws Exception { File[] files = new File[] { new File("file1"), new File("file2"), }; @@ -174,10 +180,10 @@ public void testToURLs() throws Exception { URL[] urls = FileUtils.toURLs(files); assertEquals( - "The length of the generated URL's is not equals to the length of files. " + "Was " + files.length - + ", expected " + urls.length, files.length, - urls.length); + urls.length, + "The length of the generated URL's is not equals to the length of files. " + "Was " + files.length + + ", expected " + urls.length); for (int i = 0; i < urls.length; i++) { assertEquals(files[i].toURI().toURL(), urls[i]); @@ -188,14 +194,14 @@ public void testToURLs() throws Exception { *testGetFilesFromExtension.
*/ @Test - public void testGetFilesFromExtension() { + void getFilesFromExtension() { // TODO I'm not sure what is supposed to happen here FileUtils.getFilesFromExtension("dir", null); // Non-existent files final String[] emptyFileNames = FileUtils.getFilesFromExtension(getTestDirectory().getAbsolutePath(), new String[] {"java"}); - assertTrue(emptyFileNames.length == 0); + assertEquals(0, emptyFileNames.length); // Existing files // TODO Figure out how to test this @@ -211,7 +217,7 @@ public void testGetFilesFromExtension() { *testMkdir.
*/ @Test - public void testMkdir() { + void mkdir() { final File dir = new File(getTestDirectory(), "testdir"); FileUtils.mkdir(dir.getAbsolutePath()); dir.deleteOnExit(); @@ -236,25 +242,25 @@ public void testMkdir() { * @throws java.lang.Exception if any. */ @Test - public void testContentEquals() throws Exception { + void contentEquals() throws Exception { // Non-existent files - final File file = new File(getTestDirectory(), name.getMethodName()); + final File file = new File(getTestDirectory(), name); assertTrue(FileUtils.contentEquals(file, file)); // TODO Should comparing 2 directories throw an Exception instead of returning false? // Directories - assertTrue(!FileUtils.contentEquals(getTestDirectory(), getTestDirectory())); + assertFalse(FileUtils.contentEquals(getTestDirectory(), getTestDirectory())); // Different files - final File objFile1 = new File(getTestDirectory(), name.getMethodName() + ".object"); + final File objFile1 = new File(getTestDirectory(), name + ".object"); objFile1.deleteOnExit(); FileUtils.copyURLToFile(getClass().getResource("/java/lang/Object.class"), objFile1); - final File objFile2 = new File(getTestDirectory(), name.getMethodName() + ".collection"); + final File objFile2 = new File(getTestDirectory(), name + ".collection"); objFile2.deleteOnExit(); FileUtils.copyURLToFile(getClass().getResource("/java/util/Collection.class"), objFile2); - assertTrue("Files should not be equal.", !FileUtils.contentEquals(objFile1, objFile2)); + assertFalse(FileUtils.contentEquals(objFile1, objFile2), "Files should not be equal."); // Equal files file.createNewFile(); @@ -267,10 +273,9 @@ public void testContentEquals() throws Exception { *testRemovePath.
*/ @Test - public void testRemovePath() { - final String fileName = - FileUtils.removePath(new File(getTestDirectory(), name.getMethodName()).getAbsolutePath()); - assertEquals(name.getMethodName(), fileName); + void removePath() { + final String fileName = FileUtils.removePath(new File(getTestDirectory(), name).getAbsolutePath()); + assertEquals(name, fileName); } // getPath @@ -279,8 +284,8 @@ public void testRemovePath() { *testGetPath.
*/ @Test - public void testGetPath() { - final String fileName = FileUtils.getPath(new File(getTestDirectory(), name.getMethodName()).getAbsolutePath()); + void getPath() { + final String fileName = FileUtils.getPath(new File(getTestDirectory(), name).getAbsolutePath()); assertEquals(getTestDirectory().getAbsolutePath(), fileName); } @@ -292,9 +297,9 @@ public void testGetPath() { * @throws java.lang.Exception if any. */ @Test - public void testCopyURLToFile() throws Exception { + void copyURLToFile() throws Exception { // Creates file - final File file = new File(getTestDirectory(), name.getMethodName()); + final File file = new File(getTestDirectory(), name); file.deleteOnExit(); // Loads resource @@ -305,7 +310,7 @@ public void testCopyURLToFile() throws Exception { final InputStream fis = Files.newInputStream(file.toPath()); try { assertTrue( - "Content is not equal.", IOUtil.contentEquals(getClass().getResourceAsStream(resourceName), fis)); + IOUtil.contentEquals(getClass().getResourceAsStream(resourceName), fis), "Content is not equal."); } finally { fis.close(); } @@ -317,7 +322,7 @@ public void testCopyURLToFile() throws Exception { *testCatPath.
*/ @Test - public void testCatPath() { + void catPath() { // TODO StringIndexOutOfBoundsException thrown if file doesn't contain slash. // Is this acceptable? // assertEquals("", FileUtils.catPath("a", "b")); @@ -334,15 +339,15 @@ public void testCatPath() { * @throws java.lang.Exception if any. */ @Test - public void testForceMkdir() throws Exception { + void forceMkdir() throws Exception { // Tests with existing directory FileUtils.forceMkdir(getTestDirectory()); // Creates test file - final File testFile = new File(getTestDirectory(), name.getMethodName()); + final File testFile = new File(getTestDirectory(), name); testFile.deleteOnExit(); testFile.createNewFile(); - assertTrue("Test file does not exist.", testFile.exists()); + assertTrue(testFile.exists(), "Test file does not exist."); // Tests with existing file try { @@ -355,7 +360,7 @@ public void testForceMkdir() throws Exception { // Tests with non-existent directory FileUtils.forceMkdir(testFile); - assertTrue("Directory was not created.", testFile.exists()); + assertTrue(testFile.exists(), "Directory was not created."); if (Os.isFamily(Os.FAMILY_WINDOWS)) { try { @@ -377,8 +382,8 @@ public void testForceMkdir() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testSizeOfDirectory() throws Exception { - final File file = new File(getTestDirectory(), name.getMethodName()); + void sizeOfDirectory() throws Exception { + final File file = new File(getTestDirectory(), name); // Non-existent file try { @@ -402,7 +407,7 @@ public void testSizeOfDirectory() throws Exception { file.delete(); file.mkdir(); - assertEquals("Unexpected directory size", TEST_DIRECTORY_SIZE, FileUtils.sizeOfDirectory(file)); + assertEquals(TEST_DIRECTORY_SIZE, FileUtils.sizeOfDirectory(file), "Unexpected directory size"); } // isFileNewer @@ -421,11 +426,11 @@ public void XtestIsFileNewer() {} * @throws java.lang.Exception if any. */ @Test - public void testCopyFile1() throws Exception { + void copyFile1() throws Exception { final File destination = new File(getTestDirectory(), "copy1.txt"); FileUtils.copyFile(testFile1, destination); - assertTrue("Check Exist", destination.exists()); - assertTrue("Check Full copy", destination.length() == testFile1Size); + assertTrue(destination.exists(), "Check Exist"); + assertEquals(destination.length(), testFile1Size, "Check Full copy"); } /** @@ -434,11 +439,11 @@ public void testCopyFile1() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCopyFile2() throws Exception { + void copyFile2() throws Exception { final File destination = new File(getTestDirectory(), "copy2.txt"); FileUtils.copyFile(testFile1, destination); - assertTrue("Check Exist", destination.exists()); - assertTrue("Check Full copy", destination.length() == testFile2Size); + assertTrue(destination.exists(), "Check Exist"); + assertEquals(destination.length(), testFile2Size, "Check Full copy"); } /** @@ -447,15 +452,15 @@ public void testCopyFile2() throws Exception { * @throws java.lang.Exception */ @Test - public void testCopyFile3() throws Exception { + void copyFile3() throws Exception { File destDirectory = new File(getTestDirectory(), "foo/bar/testcopy"); if (destDirectory.exists()) { destDirectory.delete(); } final File destination = new File(destDirectory, "copy2.txt"); FileUtils.copyFile(testFile1, destination); - assertTrue("Check Exist", destination.exists()); - assertTrue("Check Full copy", destination.length() == testFile2Size); + assertTrue(destination.exists(), "Check Exist"); + assertEquals(destination.length(), testFile2Size, "Check Full copy"); } // linkFile @@ -465,12 +470,12 @@ public void testCopyFile3() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testLinkFile1() throws Exception { + void linkFile1() throws Exception { final File destination = new File(getTestDirectory(), "link1.txt"); FileUtils.linkFile(testFile1, destination); - assertTrue("Check Exist", destination.exists()); - assertTrue("Check File length", destination.length() == testFile1Size); - assertTrue("Check is link", Files.isSymbolicLink(destination.toPath())); + assertTrue(destination.exists(), "Check Exist"); + assertEquals(destination.length(), testFile1Size, "Check File length"); + assertTrue(Files.isSymbolicLink(destination.toPath()), "Check is link"); } /** @@ -479,12 +484,12 @@ public void testLinkFile1() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testLinkFile2() throws Exception { + void linkFile2() throws Exception { final File destination = new File(getTestDirectory(), "link2.txt"); FileUtils.linkFile(testFile1, destination); - assertTrue("Check Exist", destination.exists()); - assertTrue("Check File length", destination.length() == testFile2Size); - assertTrue("Check is link", Files.isSymbolicLink(destination.toPath())); + assertTrue(destination.exists(), "Check Exist"); + assertEquals(destination.length(), testFile2Size, "Check File length"); + assertTrue(Files.isSymbolicLink(destination.toPath()), "Check is link"); } /** @@ -493,16 +498,16 @@ public void testLinkFile2() throws Exception { * @throws java.lang.Exception */ @Test - public void testLinkFile3() throws Exception { + void linkFile3() throws Exception { File destDirectory = new File(getTestDirectory(), "foo/bar/testlink"); if (destDirectory.exists()) { destDirectory.delete(); } final File destination = new File(destDirectory, "link2.txt"); FileUtils.linkFile(testFile1, destination); - assertTrue("Check Exist", destination.exists()); - assertTrue("Check File length", destination.length() == testFile2Size); - assertTrue("Check is link", Files.isSymbolicLink(destination.toPath())); + assertTrue(destination.exists(), "Check Exist"); + assertEquals(destination.length(), testFile2Size, "Check File length"); + assertTrue(Files.isSymbolicLink(destination.toPath()), "Check is link"); } // copyFileIfModified @@ -513,7 +518,7 @@ public void testLinkFile3() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCopyIfModifiedWhenSourceIsNewer() throws Exception { + void copyIfModifiedWhenSourceIsNewer() throws Exception { FileUtils.forceMkdir(new File(getTestDirectory() + "/temp")); // Place destination @@ -530,8 +535,8 @@ public void testCopyIfModifiedWhenSourceIsNewer() throws Exception { // Copy will occur when source is newer assertTrue( - "Failed copy. Target file should have been updated.", - FileUtils.copyFileIfModified(source, destination)); + FileUtils.copyFileIfModified(source, destination), + "Failed copy. Target file should have been updated."); } /** @@ -540,7 +545,7 @@ public void testCopyIfModifiedWhenSourceIsNewer() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCopyIfModifiedWhenSourceIsOlder() throws Exception { + void copyIfModifiedWhenSourceIsOlder() throws Exception { FileUtils.forceMkdir(new File(getTestDirectory() + "/temp")); // Place source @@ -555,7 +560,7 @@ public void testCopyIfModifiedWhenSourceIsOlder() throws Exception { FileUtils.copyFile(testFile1, destination); // Copy will occur when destination is newer - assertFalse("Source file should not have been copied.", FileUtils.copyFileIfModified(source, destination)); + assertFalse(FileUtils.copyFileIfModified(source, destination), "Source file should not have been copied."); } /** @@ -564,7 +569,7 @@ public void testCopyIfModifiedWhenSourceIsOlder() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCopyIfModifiedWhenSourceHasZeroDate() throws Exception { + void copyIfModifiedWhenSourceHasZeroDate() throws Exception { FileUtils.forceMkdir(new File(getTestDirectory(), "temp")); // Source modified on 1970-01-01T00:00Z @@ -576,7 +581,7 @@ public void testCopyIfModifiedWhenSourceHasZeroDate() throws Exception { File destination = new File(getTestDirectory(), "temp/copy1.txt"); // Should copy the source to the non existing destination. - assertTrue("Source file should have been copied.", FileUtils.copyFileIfModified(source, destination)); + assertTrue(FileUtils.copyFileIfModified(source, destination), "Source file should have been copied."); } // forceDelete @@ -587,12 +592,12 @@ public void testCopyIfModifiedWhenSourceHasZeroDate() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testForceDeleteAFile1() throws Exception { + void forceDeleteAFile1() throws Exception { final File destination = new File(getTestDirectory(), "copy1.txt"); destination.createNewFile(); - assertTrue("Copy1.txt doesn't exist to delete", destination.exists()); + assertTrue(destination.exists(), "Copy1.txt doesn't exist to delete"); FileUtils.forceDelete(destination); - assertTrue("Check No Exist", !destination.exists()); + assertFalse(destination.exists(), "Check No Exist"); } /** @@ -601,12 +606,12 @@ public void testForceDeleteAFile1() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testForceDeleteAFile2() throws Exception { + void forceDeleteAFile2() throws Exception { final File destination = new File(getTestDirectory(), "copy2.txt"); destination.createNewFile(); - assertTrue("Copy2.txt doesn't exist to delete", destination.exists()); + assertTrue(destination.exists(), "Copy2.txt doesn't exist to delete"); FileUtils.forceDelete(destination); - assertTrue("Check No Exist", !destination.exists()); + assertFalse(destination.exists(), "Check No Exist"); } // copyFileToDirectory @@ -617,15 +622,15 @@ public void testForceDeleteAFile2() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCopyFile1ToDir() throws Exception { + void copyFile1ToDir() throws Exception { final File directory = new File(getTestDirectory(), "subdir"); if (!directory.exists()) { directory.mkdirs(); } final File destination = new File(directory, testFile1.getName()); FileUtils.copyFileToDirectory(testFile1, directory); - assertTrue("Check Exist", destination.exists()); - assertTrue("Check Full copy", destination.length() == testFile1Size); + assertTrue(destination.exists(), "Check Exist"); + assertEquals(destination.length(), testFile1Size, "Check Full copy"); } /** @@ -634,15 +639,15 @@ public void testCopyFile1ToDir() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCopyFile2ToDir() throws Exception { + void copyFile2ToDir() throws Exception { final File directory = new File(getTestDirectory(), "subdir"); if (!directory.exists()) { directory.mkdirs(); } final File destination = new File(directory, testFile1.getName()); FileUtils.copyFileToDirectory(testFile1, directory); - assertTrue("Check Exist", destination.exists()); - assertTrue("Check Full copy", destination.length() == testFile2Size); + assertTrue(destination.exists(), "Check Exist"); + assertEquals(destination.length(), testFile2Size, "Check Full copy"); } // copyFileToDirectoryIfModified @@ -653,7 +658,7 @@ public void testCopyFile2ToDir() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCopyFile1ToDirIfModified() throws Exception { + void copyFile1ToDirIfModified() throws Exception { final File directory = new File(getTestDirectory(), "subdir"); if (directory.exists()) { FileUtils.forceDelete(directory); @@ -667,12 +672,12 @@ public void testCopyFile1ToDirIfModified() throws Exception { final File target = new File(getTestDirectory() + "/subdir", testFile1.getName()); long timestamp = target.lastModified(); - assertTrue("Check Exist", destination.exists()); - assertTrue("Check Full copy", destination.length() == testFile1Size); + assertTrue(destination.exists(), "Check Exist"); + assertEquals(destination.length(), testFile1Size, "Check Full copy"); FileUtils.copyFileToDirectoryIfModified(testFile1, directory); - assertTrue("Timestamp was changed", timestamp == target.lastModified()); + assertEquals(timestamp, target.lastModified(), "Timestamp was changed"); } /** @@ -681,7 +686,7 @@ public void testCopyFile1ToDirIfModified() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCopyFile2ToDirIfModified() throws Exception { + void copyFile2ToDirIfModified() throws Exception { final File directory = new File(getTestDirectory(), "subdir"); if (directory.exists()) { FileUtils.forceDelete(directory); @@ -695,12 +700,12 @@ public void testCopyFile2ToDirIfModified() throws Exception { final File target = new File(getTestDirectory() + "/subdir", testFile2.getName()); long timestamp = target.lastModified(); - assertTrue("Check Exist", destination.exists()); - assertTrue("Check Full copy", destination.length() == testFile2Size); + assertTrue(destination.exists(), "Check Exist"); + assertEquals(destination.length(), testFile2Size, "Check Full copy"); FileUtils.copyFileToDirectoryIfModified(testFile2, directory); - assertTrue("Timestamp was changed", timestamp == target.lastModified()); + assertEquals(timestamp, target.lastModified(), "Timestamp was changed"); } // forceDelete @@ -711,9 +716,9 @@ public void testCopyFile2ToDirIfModified() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testForceDeleteDir() throws Exception { + void forceDeleteDir() throws Exception { FileUtils.forceDelete(getTestDirectory().getParentFile()); - assertTrue("Check No Exist", !getTestDirectory().getParentFile().exists()); + assertFalse(getTestDirectory().getParentFile().exists(), "Check No Exist"); } // resolveFile @@ -724,9 +729,9 @@ public void testForceDeleteDir() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testResolveFileDotDot() throws Exception { + void resolveFileDotDot() throws Exception { final File file = FileUtils.resolveFile(getTestDirectory(), ".."); - assertEquals("Check .. operator", file, getTestDirectory().getParentFile()); + assertEquals(file, getTestDirectory().getParentFile(), "Check .. operator"); } /** @@ -735,9 +740,9 @@ public void testResolveFileDotDot() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testResolveFileDot() throws Exception { + void resolveFileDot() throws Exception { final File file = FileUtils.resolveFile(getTestDirectory(), "."); - assertEquals("Check . operator", file, getTestDirectory()); + assertEquals(file, getTestDirectory(), "Check . operator"); } // normalize @@ -748,7 +753,7 @@ public void testResolveFileDot() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testNormalize() throws Exception { + void normalize() throws Exception { final String[] src = { "", "/", @@ -789,11 +794,11 @@ public void testNormalize() throws Exception { null }; - assertEquals("Oops, test writer goofed", src.length, dest.length); + assertEquals(src.length, dest.length, "Oops, test writer goofed"); for (int i = 0; i < src.length; i++) { assertEquals( - "Check if '" + src[i] + "' normalized to '" + dest[i] + "'", dest[i], FileUtils.normalize(src[i])); + dest[i], FileUtils.normalize(src[i]), "Check if '" + src[i] + "' normalized to '" + dest[i] + "'"); } } @@ -816,46 +821,42 @@ private String replaceAll(String text, String lookFor, String replaceWith) { */ // Used to exist as IOTestCase class @Test - public void testFileUtils() throws Exception { + void fileUtils() throws Exception { // Loads file from classpath final String path = "/test.txt"; final URL url = this.getClass().getResource(path); - assertNotNull(path + " was not found.", url); + assertNotNull(url, path + " was not found."); final String filename = Paths.get(url.toURI()).toString(); final String filename2 = "test2.txt"; - assertTrue( - "test.txt extension == \"txt\"", - FileUtils.getExtension(filename).equals("txt")); + assertEquals("txt", FileUtils.getExtension(filename), "test.txt extension == \"txt\""); - assertTrue("Test file does exist: " + filename, FileUtils.fileExists(filename)); + assertTrue(FileUtils.fileExists(filename), "Test file does exist: " + filename); - assertTrue("Second test file does not exist", !FileUtils.fileExists(filename2)); + assertFalse(FileUtils.fileExists(filename2), "Second test file does not exist"); FileUtils.fileWrite(filename2, filename); - assertTrue("Second file was written", FileUtils.fileExists(filename2)); + assertTrue(FileUtils.fileExists(filename2), "Second file was written"); final String file2contents = FileUtils.fileRead(filename2); - assertTrue( - "Second file's contents correct", FileUtils.fileRead(filename2).equals(file2contents)); + assertEquals(FileUtils.fileRead(filename2), file2contents, "Second file's contents correct"); FileUtils.fileAppend(filename2, filename); - assertTrue( - "Second file's contents correct", FileUtils.fileRead(filename2).equals(file2contents + file2contents)); + assertEquals(FileUtils.fileRead(filename2), file2contents + file2contents, "Second file's contents correct"); FileUtils.fileDelete(filename2); - assertTrue("Second test file does not exist", !FileUtils.fileExists(filename2)); + assertFalse(FileUtils.fileExists(filename2), "Second test file does not exist"); final String contents = FileUtils.fileRead(filename); - assertTrue("FileUtils.fileRead()", contents.equals("This is a test")); + assertEquals("This is a test", contents, "FileUtils.fileRead()"); } /** *testGetExtension.
*/ @Test - public void testGetExtension() { + void getExtension() { final String[][] tests = { {"filename.ext", "ext"}, {"README", ""}, @@ -875,7 +876,7 @@ public void testGetExtension() { *testGetExtensionWithPaths.
*/ @Test - public void testGetExtensionWithPaths() { + void getExtensionWithPaths() { // Since the utilities are based on the separator for the platform // running the test, ensure we are using the right separator final String sep = File.separator; @@ -899,7 +900,7 @@ public void testGetExtensionWithPaths() { *testRemoveExtension.
*/ @Test - public void testRemoveExtension() { + void removeExtension() { final String[][] tests = { {"filename.ext", "filename"}, {"first.second.third.ext", "first.second.third"}, @@ -919,7 +920,7 @@ public void testRemoveExtension() { *testRemoveExtensionWithPaths.
*/ @Test - public void testRemoveExtensionWithPaths() { + void removeExtensionWithPaths() { // Since the utilities are based on the separator for the platform // running the test, ensure we are using the right separator final String sep = File.separator; @@ -954,7 +955,7 @@ public void testRemoveExtensionWithPaths() { * @throws java.lang.Exception if any. */ @Test - public void testCopyDirectoryStructureWithAEmptyDirectoryStructure() throws Exception { + void copyDirectoryStructureWithAEmptyDirectoryStructure() throws Exception { File from = new File(getTestDirectory(), "from"); FileUtils.deleteDirectory(from); @@ -974,7 +975,7 @@ public void testCopyDirectoryStructureWithAEmptyDirectoryStructure() throws Exce * @throws java.lang.Exception if any. */ @Test - public void testCopyDirectoryStructureWithAPopulatedStructure() throws Exception { + void copyDirectoryStructureWithAPopulatedStructure() throws Exception { // Make a structure to copy File from = new File(getTestDirectory(), "from"); @@ -1037,7 +1038,7 @@ public void testCopyDirectoryStructureWithAPopulatedStructure() throws Exception * @throws java.lang.Exception if any. */ @Test - public void testCopyDirectoryStructureIfModified() throws Exception { + void copyDirectoryStructureIfModified() throws Exception { // Make a structure to copy File from = new File(getTestDirectory(), "from"); @@ -1099,18 +1100,18 @@ public void testCopyDirectoryStructureIfModified() throws Exception { FileUtils.copyDirectoryStructureIfModified(from, to); - assertTrue("Unmodified file was overwritten", timestamps[0] == files[0].lastModified()); - assertTrue("Unmodified file was overwritten", timestamps[1] == files[1].lastModified()); - assertTrue("Unmodified file was overwritten", timestamps[2] == files[2].lastModified()); + assertEquals(timestamps[0], files[0].lastModified(), "Unmodified file was overwritten"); + assertEquals(timestamps[1], files[1].lastModified(), "Unmodified file was overwritten"); + assertEquals(timestamps[2], files[2].lastModified(), "Unmodified file was overwritten"); files[1].setLastModified(f2.lastModified() - 5000L); timestamps[1] = files[1].lastModified(); FileUtils.copyDirectoryStructureIfModified(from, to); - assertTrue("Unmodified file was overwritten", timestamps[0] == files[0].lastModified()); - assertTrue("Outdated file was not overwritten", timestamps[1] < files[1].lastModified()); - assertTrue("Unmodified file was overwritten", timestamps[2] == files[2].lastModified()); + assertEquals(timestamps[0], files[0].lastModified(), "Unmodified file was overwritten"); + assertTrue(timestamps[1] < files[1].lastModified(), "Outdated file was not overwritten"); + assertEquals(timestamps[2], files[2].lastModified(), "Unmodified file was overwritten"); } /** @@ -1119,7 +1120,7 @@ public void testCopyDirectoryStructureIfModified() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCopyDirectoryStructureToSelf() throws Exception { + void copyDirectoryStructureToSelf() throws Exception { // Make a structure to copy File toFrom = new File(getTestDirectory(), "tofrom"); @@ -1161,7 +1162,7 @@ public void testCopyDirectoryStructureToSelf() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testFilteredFileCopy() throws Exception { + void filteredFileCopy() throws Exception { File compareFile = new File(getTestDirectory(), "compare.txt"); FileUtils.fileWrite(compareFile.getAbsolutePath(), "UTF-8", "This is a test. Test sample text\n"); @@ -1183,7 +1184,7 @@ public Reader getReader(Reader reader) { FileUtils.fileWrite(srcFile.getAbsolutePath(), "UTF-8", "This is a test. Test ${s}\n"); FileUtils.copyFile(srcFile, destFile, "UTF-8", wrappers1); - assertTrue("Files should be equal.", FileUtils.contentEquals(compareFile, destFile)); + assertTrue(FileUtils.contentEquals(compareFile, destFile), "Files should be equal."); srcFile.delete(); destFile.delete(); @@ -1196,7 +1197,7 @@ public Reader getReader(Reader reader) { * @throws java.lang.Exception if any. */ @Test - public void testFilteredWithoutFilterAndOlderFile() throws Exception { + void filteredWithoutFilterAndOlderFile() throws Exception { String content = "This is a test."; File sourceFile = new File(getTestDirectory(), "source.txt"); FileUtils.fileWrite(sourceFile.getAbsolutePath(), "UTF-8", content); @@ -1227,7 +1228,7 @@ public void testFilteredWithoutFilterAndOlderFile() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testFilteredWithoutFilterAndOlderFileAndOverwrite() throws Exception { + void filteredWithoutFilterAndOlderFileAndOverwrite() throws Exception { String content = "This is a test."; File sourceFile = new File(getTestDirectory(), "source.txt"); FileUtils.fileWrite(sourceFile.getAbsolutePath(), "UTF-8", content); @@ -1258,7 +1259,7 @@ public void testFilteredWithoutFilterAndOlderFileAndOverwrite() throws Exception * @throws java.io.IOException if any. */ @Test - public void testFileRead() throws IOException { + void fileRead() throws IOException { File testFile = new File(getTestDirectory(), "testFileRead.txt"); String testFileName = testFile.getAbsolutePath(); /* @@ -1276,8 +1277,8 @@ public void testFileRead() throws IOException { } finally { IOUtil.close(writer); } - assertEquals("testString should be equal", testString, FileUtils.fileRead(testFile)); - assertEquals("testString should be equal", testString, FileUtils.fileRead(testFileName)); + assertEquals(testString, FileUtils.fileRead(testFile), "testString should be equal"); + assertEquals(testString, FileUtils.fileRead(testFileName), "testString should be equal"); testFile.delete(); } @@ -1287,7 +1288,7 @@ public void testFileRead() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testFileReadWithEncoding() throws IOException { + void fileReadWithEncoding() throws IOException { String encoding = "UTF-8"; File testFile = new File(getTestDirectory(), "testFileRead.txt"); String testFileName = testFile.getAbsolutePath(); @@ -1301,8 +1302,8 @@ public void testFileReadWithEncoding() throws IOException { } finally { IOUtil.close(writer); } - assertEquals("testString should be equal", testString, FileUtils.fileRead(testFile, "UTF-8")); - assertEquals("testString should be equal", testString, FileUtils.fileRead(testFileName, "UTF-8")); + assertEquals(testString, FileUtils.fileRead(testFile, "UTF-8"), "testString should be equal"); + assertEquals(testString, FileUtils.fileRead(testFileName, "UTF-8"), "testString should be equal"); testFile.delete(); } @@ -1312,7 +1313,7 @@ public void testFileReadWithEncoding() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testFileAppend() throws IOException { + void fileAppend() throws IOException { String baseString = "abc"; File testFile = new File(getTestDirectory(), "testFileAppend.txt"); String testFileName = testFile.getAbsolutePath(); @@ -1337,7 +1338,7 @@ public void testFileAppend() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testFileAppendWithEncoding() throws IOException { + void fileAppendWithEncoding() throws IOException { String baseString = "abc"; String encoding = "UTF-8"; File testFile = new File(getTestDirectory(), "testFileAppend.txt"); @@ -1363,7 +1364,7 @@ public void testFileAppendWithEncoding() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testFileWrite() throws IOException { + void fileWrite() throws IOException { File testFile = new File(getTestDirectory(), "testFileWrite.txt"); String testFileName = testFile.getAbsolutePath(); // unicode escaped Japanese hiragana, "aiueo" + Umlaut a @@ -1379,7 +1380,7 @@ public void testFileWrite() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testFileWriteWithEncoding() throws IOException { + void fileWriteWithEncoding() throws IOException { String encoding = "UTF-8"; File testFile = new File(getTestDirectory(), "testFileWrite.txt"); String testFileName = testFile.getAbsolutePath(); @@ -1399,7 +1400,7 @@ public void testFileWriteWithEncoding() throws IOException { * @see Sun bug id=6481955 */ @Test - public void testDeleteLongPathOnWindows() throws Exception { + void deleteLongPathOnWindows() throws Exception { if (!Os.isFamily(Os.FAMILY_WINDOWS)) { return; } @@ -1437,7 +1438,7 @@ public void testDeleteLongPathOnWindows() throws Exception { * @throws java.io.IOException if any. */ @Test - public void testCopyFileOnSameFile() throws IOException { + void copyFileOnSameFile() throws IOException { String content = "ggrgreeeeeeeeeeeeeeeeeeeeeeeoierjgioejrgiojregioejrgufcdxivbsdibgfizgerfyaezgv!zeez"; final File theFile = File.createTempFile("test", ".txt"); theFile.deleteOnExit(); @@ -1457,7 +1458,7 @@ public void testCopyFileOnSameFile() throws IOException { * @throws java.lang.Exception if any. */ @Test - public void testExtensions() throws Exception { + void extensions() throws Exception { String[][] values = { {"fry.frozen", "frozen"}, @@ -1476,7 +1477,7 @@ public void testExtensions() throws Exception { String fileName = values[i][0].replace('/', File.separatorChar); String ext = values[i][1]; String computed = FileUtils.extension(fileName); - assertEquals("case [" + i + "]:" + fileName + " -> " + ext + ", computed : " + computed, ext, computed); + assertEquals(ext, computed, "case [" + i + "]:" + fileName + " -> " + ext + ", computed : " + computed); } } @@ -1486,7 +1487,7 @@ public void testExtensions() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testIsValidWindowsFileName() throws Exception { + void isValidWindowsFileName() throws Exception { File f = new File("c:\test"); assertTrue(FileUtils.isValidWindowsFileName(f)); @@ -1514,7 +1515,7 @@ public void testIsValidWindowsFileName() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testDeleteDirectoryWithValidFileSymlink() throws Exception { + void deleteDirectoryWithValidFileSymlink() throws Exception { File symlinkTarget = new File(getTestDirectory(), "fileSymlinkTarget"); createFile(symlinkTarget, 1); File symlink = new File(getTestDirectory(), "fileSymlink"); @@ -1527,7 +1528,7 @@ public void testDeleteDirectoryWithValidFileSymlink() throws Exception { */ symlink.delete(); } - assertTrue("Failed to delete test directory", !getTestDirectory().exists()); + assertFalse(getTestDirectory().exists(), "Failed to delete test directory"); } /** @@ -1536,7 +1537,7 @@ public void testDeleteDirectoryWithValidFileSymlink() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testDeleteDirectoryWithValidDirSymlink() throws Exception { + void deleteDirectoryWithValidDirSymlink() throws Exception { File symlinkTarget = new File(getTestDirectory(), "dirSymlinkTarget"); symlinkTarget.mkdir(); File symlink = new File(getTestDirectory(), "dirSymlink"); @@ -1549,7 +1550,7 @@ public void testDeleteDirectoryWithValidDirSymlink() throws Exception { */ symlink.delete(); } - assertTrue("Failed to delete test directory", !getTestDirectory().exists()); + assertFalse(getTestDirectory().exists(), "Failed to delete test directory"); } /** @@ -1558,7 +1559,7 @@ public void testDeleteDirectoryWithValidDirSymlink() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testDeleteDirectoryWithDanglingSymlink() throws Exception { + void deleteDirectoryWithDanglingSymlink() throws Exception { File symlinkTarget = new File(getTestDirectory(), "missingSymlinkTarget"); File symlink = new File(getTestDirectory(), "danglingSymlink"); createSymlink(symlink, symlinkTarget); @@ -1570,7 +1571,7 @@ public void testDeleteDirectoryWithDanglingSymlink() throws Exception { */ symlink.delete(); } - assertTrue("Failed to delete test directory", !getTestDirectory().exists()); + assertFalse(getTestDirectory().exists(), "Failed to delete test directory"); } /** @@ -1579,7 +1580,7 @@ public void testDeleteDirectoryWithDanglingSymlink() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testcopyDirectoryLayoutWithExcludesIncludes() throws Exception { + void testcopyDirectoryLayoutWithExcludesIncludes() throws Exception { File destination = new File("target", "copyDirectoryStructureWithExcludesIncludes"); if (!destination.exists()) { destination.mkdirs(); @@ -1613,12 +1614,11 @@ public void testcopyDirectoryLayoutWithExcludesIncludes() throws Exception { * @throws java.lang.Exception if any */ @Test - public void testCreateTempFile() throws Exception { + void createTempFile() throws Exception { File last = FileUtils.createTempFile("unique", ".tmp", null); for (int i = 0; i < 10; i++) { File current = FileUtils.createTempFile("unique", ".tmp", null); - assertTrue( - "No unique name: " + current.getName(), !current.getName().equals(last.getName())); + assertNotEquals(current.getName(), last.getName(), "No unique name: " + current.getName()); last = current; } } diff --git a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java index f235c495..8a9dff50 100644 --- a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java @@ -28,12 +28,14 @@ import java.nio.file.Files; import java.util.Arrays; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * This is used to test IOUtil for correctness. The following checks are performed: @@ -66,8 +68,8 @@ public final class IOUtilTest { /** *setUp.
*/ - @Before - public void setUp() { + @BeforeEach + void setUp() { try { testDirectory = (new File("target/test/io/")).getAbsoluteFile(); if (!testDirectory.exists()) { @@ -102,7 +104,7 @@ private void createFile(File file, long size) throws IOException { /** Assert that the contents of two byte arrays are the same. */ private void assertEqualContent(byte[] b0, byte[] b1) { - assertTrue("Content not equal according to java.util.Arrays#equals()", Arrays.equals(b0, b1)); + assertTrue(Arrays.equals(b0, b1), "Content not equal according to java.util.Arrays#equals()"); } /** Assert that the content of two files is the same. */ @@ -119,11 +121,11 @@ private void assertEqualContent(File f0, File f1) throws IOException { n0 = is0.read(buf0); n1 = is1.read(buf1); assertTrue( + (n0 == n1), "The files " + f0 + " and " + f1 + " have differing number of bytes available (" + n0 + " vs " - + n1 + ")", - (n0 == n1)); + + n1 + ")"); - assertTrue("The files " + f0 + " and " + f1 + " have different content", Arrays.equals(buf0, buf1)); + assertTrue(Arrays.equals(buf0, buf1), "The files " + f0 + " and " + f1 + " have different content"); } } finally { is0.close(); @@ -136,10 +138,10 @@ private void assertEqualContent(byte[] b0, File file) throws IOException { InputStream is = Files.newInputStream(file.toPath()); byte[] b1 = new byte[b0.length]; int numRead = is.read(b1); - assertTrue("Different number of bytes", numRead == b0.length && is.available() == 0); + assertTrue(numRead == b0.length && is.available() == 0, "Different number of bytes"); for (int i = 0; i < numRead; - assertTrue("Byte " + i + " differs (" + b0[i] + " != " + b1[i] + ")", b0[i] == b1[i]), i++) + assertEquals(b0[i], b1[i], "Byte " + i + " differs (" + b0[i] + " != " + b1[i] + ")"), i++) ; is.close(); } @@ -150,13 +152,13 @@ private void assertEqualContent(byte[] b0, File file) throws IOException { * @throws java.lang.Exception if any. */ @Test - public void testInputStreamToOutputStream() throws Exception { + void inputStreamToOutputStream() throws Exception { File destination = newFile("copy1.txt"); InputStream fin = Files.newInputStream(testFile.toPath()); OutputStream fout = Files.newOutputStream(destination.toPath()); IOUtil.copy(fin, fout); - assertTrue("Not all bytes were read", fin.available() == 0); + assertEquals(0, fin.available(), "Not all bytes were read"); fout.flush(); checkFile(destination); @@ -172,14 +174,14 @@ public void testInputStreamToOutputStream() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testInputStreamToWriter() throws Exception { + void inputStreamToWriter() throws Exception { File destination = newFile("copy2.txt"); InputStream fin = Files.newInputStream(testFile.toPath()); Writer fout = Files.newBufferedWriter(destination.toPath()); IOUtil.copy(fin, fout); - assertTrue("Not all bytes were read", fin.available() == 0); + assertEquals(0, fin.available(), "Not all bytes were read"); fout.flush(); checkFile(destination); @@ -195,12 +197,12 @@ public void testInputStreamToWriter() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testInputStreamToString() throws Exception { + void inputStreamToString() throws Exception { InputStream fin = Files.newInputStream(testFile.toPath()); String out = IOUtil.toString(fin); assertNotNull(out); - assertTrue("Not all bytes were read", fin.available() == 0); - assertTrue("Wrong output size: out.length()=" + out.length() + "!=" + FILE_SIZE, out.length() == FILE_SIZE); + assertEquals(0, fin.available(), "Not all bytes were read"); + assertEquals(out.length(), FILE_SIZE, "Wrong output size: out.length()=" + out.length() + "!=" + FILE_SIZE); fin.close(); } @@ -210,7 +212,7 @@ public void testInputStreamToString() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testReaderToOutputStream() throws Exception { + void readerToOutputStream() throws Exception { File destination = newFile("copy3.txt"); Reader fin = Files.newBufferedReader(testFile.toPath()); OutputStream fout = Files.newOutputStream(destination.toPath()); @@ -235,7 +237,7 @@ public void testReaderToOutputStream() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testReaderToWriter() throws Exception { + void readerToWriter() throws Exception { File destination = newFile("copy4.txt"); Reader fin = Files.newBufferedReader(testFile.toPath()); Writer fout = Files.newBufferedWriter(destination.toPath()); @@ -255,11 +257,11 @@ public void testReaderToWriter() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testReaderToString() throws Exception { + void readerToString() throws Exception { Reader fin = Files.newBufferedReader(testFile.toPath()); String out = IOUtil.toString(fin); assertNotNull(out); - assertTrue("Wrong output size: out.length()=" + out.length() + "!=" + FILE_SIZE, out.length() == FILE_SIZE); + assertEquals(out.length(), FILE_SIZE, "Wrong output size: out.length()=" + out.length() + "!=" + FILE_SIZE); fin.close(); } @@ -269,7 +271,7 @@ public void testReaderToString() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testStringToOutputStream() throws Exception { + void stringToOutputStream() throws Exception { File destination = newFile("copy5.txt"); Reader fin = Files.newBufferedReader(testFile.toPath()); // Create our String. Rely on testReaderToString() to make sure this is valid. @@ -296,7 +298,7 @@ public void testStringToOutputStream() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testStringToWriter() throws Exception { + void stringToWriter() throws Exception { File destination = newFile("copy6.txt"); Reader fin = Files.newBufferedReader(testFile.toPath()); // Create our String. Rely on testReaderToString() to make sure this is valid. @@ -319,12 +321,12 @@ public void testStringToWriter() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testInputStreamToByteArray() throws Exception { + void inputStreamToByteArray() throws Exception { InputStream fin = Files.newInputStream(testFile.toPath()); byte[] out = IOUtil.toByteArray(fin); assertNotNull(out); - assertTrue("Not all bytes were read", fin.available() == 0); - assertTrue("Wrong output size: out.length=" + out.length + "!=" + FILE_SIZE, out.length == FILE_SIZE); + assertEquals(0, fin.available(), "Not all bytes were read"); + assertEquals(out.length, FILE_SIZE, "Wrong output size: out.length=" + out.length + "!=" + FILE_SIZE); assertEqualContent(out, testFile); fin.close(); } @@ -335,7 +337,7 @@ public void testInputStreamToByteArray() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testStringToByteArray() throws Exception { + void stringToByteArray() throws Exception { Reader fin = Files.newBufferedReader(testFile.toPath()); // Create our String. Rely on testReaderToString() to make sure this is valid. @@ -352,7 +354,7 @@ public void testStringToByteArray() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testByteArrayToWriter() throws Exception { + void byteArrayToWriter() throws Exception { File destination = newFile("copy7.txt"); Writer fout = Files.newBufferedWriter(destination.toPath()); InputStream fin = Files.newInputStream(testFile.toPath()); @@ -374,7 +376,7 @@ public void testByteArrayToWriter() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testByteArrayToString() throws Exception { + void byteArrayToString() throws Exception { InputStream fin = Files.newInputStream(testFile.toPath()); byte[] in = IOUtil.toByteArray(fin); // Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid. @@ -389,7 +391,7 @@ public void testByteArrayToString() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testByteArrayToOutputStream() throws Exception { + void byteArrayToOutputStream() throws Exception { File destination = newFile("copy8.txt"); OutputStream fout = Files.newOutputStream(destination.toPath()); InputStream fin = Files.newInputStream(testFile.toPath()); @@ -418,7 +420,7 @@ public void testByteArrayToOutputStream() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCloseInputStream() throws Exception { + void closeInputStream() throws Exception { IOUtil.close((InputStream) null); TestInputStream inputStream = new TestInputStream(); @@ -434,7 +436,7 @@ public void testCloseInputStream() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCloseOutputStream() throws Exception { + void closeOutputStream() throws Exception { IOUtil.close((OutputStream) null); TestOutputStream outputStream = new TestOutputStream(); @@ -450,7 +452,7 @@ public void testCloseOutputStream() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCloseReader() throws Exception { + void closeReader() throws Exception { IOUtil.close((Reader) null); TestReader reader = new TestReader(); @@ -466,7 +468,7 @@ public void testCloseReader() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCloseWriter() throws Exception { + void closeWriter() throws Exception { IOUtil.close((Writer) null); TestWriter writer = new TestWriter(); @@ -538,13 +540,13 @@ public void flush() { private File newFile(String filename) throws Exception { File destination = new File(testDirectory, filename); - assertTrue(filename + "Test output data file shouldn't previously exist", !destination.exists()); + assertFalse(destination.exists(), filename + "Test output data file shouldn't previously exist"); return destination; } private void checkFile(File file) throws Exception { - assertTrue("Check existence of output file", file.exists()); + assertTrue(file.exists(), "Check existence of output file"); assertEqualContent(testFile, file); } @@ -565,10 +567,11 @@ private void checkWrite(Writer output) throws Exception { } private void deleteFile(File file) throws Exception { - assertTrue( - "Wrong output size: file.length()=" + file.length() + "!=" + FILE_SIZE + 1, - file.length() == FILE_SIZE + 1); + assertEquals( + file.length(), + FILE_SIZE + 1, + "Wrong output size: file.length()=" + file.length() + "!=" + FILE_SIZE + 1); - assertTrue("File would not delete", (file.delete() || (!file.exists()))); + assertTrue((file.delete() || (!file.exists())), "File would not delete"); } } diff --git a/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java b/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java index 66cec400..20b5bcda 100644 --- a/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java +++ b/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java @@ -20,9 +20,9 @@ import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** *InterpolationFilterReaderTest class.
@@ -31,7 +31,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class InterpolationFilterReaderTest { +class InterpolationFilterReaderTest { /* * Added and commented by jdcasey@03-Feb-2005 because it is a bug in the InterpolationFilterReader. * kenneyw@15-04-2005 fixed the bug. @@ -42,7 +42,7 @@ public class InterpolationFilterReaderTest { * @throws java.lang.Exception if any. */ @Test - public void testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Exception { + void shouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Exception { MapMatchPatternTest class.
@@ -30,12 +14,12 @@ * @version $Id: $Id * @since 3.4.0 */ -public class MatchPatternTest { +class MatchPatternTest { /** *testGetSource
*/ @Test - public void testGetSource() { + void getSource() { MatchPattern mp = MatchPattern.fromString("ABC*"); assertEquals("ABC*", mp.getSource()); mp = MatchPattern.fromString("%ant[some/ABC*]"); @@ -50,7 +34,7 @@ public void testGetSource() { * @throws java.lang.Exception if any. */ @Test - public void testMatchPath() throws Exception { + void matchPath() throws Exception { MatchPattern mp = MatchPattern.fromString("ABC*"); assertTrue(mp.matchPath("ABCD", true)); } @@ -61,7 +45,7 @@ public void testMatchPath() throws Exception { * @see Issue #63 */ @Test - public void testMatchPatternStart() { + void matchPatternStart() { MatchPattern mp = MatchPattern.fromString("ABC*"); assertTrue(mp.matchPatternStart("ABCD", true)); @@ -78,7 +62,7 @@ public void testMatchPatternStart() { *testTokenizePathToString.
*/ @Test - public void testTokenizePathToString() { + void tokenizePathToString() { String[] expected = {"hello", "world"}; String[] actual = MatchPattern.tokenizePathToString("hello/world", "/"); assertArrayEquals(expected, actual); diff --git a/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java b/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java index 58cdcc19..12caa631 100644 --- a/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java +++ b/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java @@ -19,11 +19,11 @@ import java.util.Arrays; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** *MatchPatternsTest class.
@@ -32,12 +32,12 @@ * @version $Id: $Id * @since 3.4.0 */ -public class MatchPatternsTest { +class MatchPatternsTest { /** *testGetSource
*/ @Test - public void testGetSources() { + void getSources() { ListtestUndefinedFamily.
*/ @Test - public void testUndefinedFamily() { + void undefinedFamily() { assertFalse(Os.isFamily("bogus family")); } @@ -44,7 +44,7 @@ public void testUndefinedFamily() { *testOs.
*/ @Test - public void testOs() { + void os() { IteratortestValidList.
*/ @Test - public void testValidList() { + void validList() { assertTrue(Os.isValidFamily("dos")); assertFalse(Os.isValidFamily("")); diff --git a/src/test/java/org/codehaus/plexus/util/PathToolTest.java b/src/test/java/org/codehaus/plexus/util/PathToolTest.java index c8f41080..09c4bd6b 100644 --- a/src/test/java/org/codehaus/plexus/util/PathToolTest.java +++ b/src/test/java/org/codehaus/plexus/util/PathToolTest.java @@ -1,24 +1,8 @@ package org.codehaus.plexus.util; -/* - * Copyright The Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** *PathToolTest class.
@@ -27,20 +11,20 @@ * @version $Id: $Id * @since 3.4.0 */ -public class PathToolTest { +class PathToolTest { /** *testGetRelativePath.
* * @throws java.lang.Exception */ @Test - public void testGetRelativePath() throws Exception { - assertEquals(PathTool.getRelativePath(null, null), ""); - assertEquals(PathTool.getRelativePath(null, "/usr/local/java/bin"), ""); - assertEquals(PathTool.getRelativePath("/usr/local/", null), ""); - assertEquals(PathTool.getRelativePath("/usr/local/", "/usr/local/java/bin"), ".."); - assertEquals(PathTool.getRelativePath("/usr/local/", "/usr/local/java/bin/java.sh"), "../.."); - assertEquals(PathTool.getRelativePath("/usr/local/java/bin/java.sh", "/usr/local/"), ""); + void getRelativePath() throws Exception { + assertEquals("", PathTool.getRelativePath(null, null)); + assertEquals("", PathTool.getRelativePath(null, "/usr/local/java/bin")); + assertEquals("", PathTool.getRelativePath("/usr/local/", null)); + assertEquals("..", PathTool.getRelativePath("/usr/local/", "/usr/local/java/bin")); + assertEquals("../..", PathTool.getRelativePath("/usr/local/", "/usr/local/java/bin/java.sh")); + assertEquals("", PathTool.getRelativePath("/usr/local/java/bin/java.sh", "/usr/local/")); } /** @@ -49,11 +33,11 @@ public void testGetRelativePath() throws Exception { * @throws java.lang.Exception */ @Test - public void testGetDirectoryComponent() throws Exception { - assertEquals(PathTool.getDirectoryComponent(null), ""); - assertEquals(PathTool.getDirectoryComponent("/usr/local/java/bin"), "/usr/local/java"); - assertEquals(PathTool.getDirectoryComponent("/usr/local/java/bin/"), "/usr/local/java/bin"); - assertEquals(PathTool.getDirectoryComponent("/usr/local/java/bin/java.sh"), "/usr/local/java/bin"); + void getDirectoryComponent() throws Exception { + assertEquals("", PathTool.getDirectoryComponent(null)); + assertEquals("/usr/local/java", PathTool.getDirectoryComponent("/usr/local/java/bin")); + assertEquals("/usr/local/java/bin", PathTool.getDirectoryComponent("/usr/local/java/bin/")); + assertEquals("/usr/local/java/bin", PathTool.getDirectoryComponent("/usr/local/java/bin/java.sh")); } /** @@ -62,18 +46,18 @@ public void testGetDirectoryComponent() throws Exception { * @throws java.lang.Exception */ @Test - public void testCalculateLink() throws Exception { - assertEquals(PathTool.calculateLink("/index.html", "../.."), "../../index.html"); + void calculateLink() throws Exception { + assertEquals("../../index.html", PathTool.calculateLink("/index.html", "../..")); assertEquals( - PathTool.calculateLink("http://plexus.codehaus.org/plexus-utils/index.html", "../.."), - "http://plexus.codehaus.org/plexus-utils/index.html"); + "http://plexus.codehaus.org/plexus-utils/index.html", + PathTool.calculateLink("http://plexus.codehaus.org/plexus-utils/index.html", "../..")); assertEquals( - PathTool.calculateLink("/usr/local/java/bin/java.sh", "../.."), "../../usr/local/java/bin/java.sh"); + "../../usr/local/java/bin/java.sh", PathTool.calculateLink("/usr/local/java/bin/java.sh", "../..")); assertEquals( - PathTool.calculateLink("../index.html", "/usr/local/java/bin"), "/usr/local/java/bin/../index.html"); + "/usr/local/java/bin/../index.html", PathTool.calculateLink("../index.html", "/usr/local/java/bin")); assertEquals( - PathTool.calculateLink("../index.html", "http://plexus.codehaus.org/plexus-utils"), - "http://plexus.codehaus.org/plexus-utils/../index.html"); + "http://plexus.codehaus.org/plexus-utils/../index.html", + PathTool.calculateLink("../index.html", "http://plexus.codehaus.org/plexus-utils")); } /** @@ -82,18 +66,18 @@ public void testCalculateLink() throws Exception { * @throws java.lang.Exception */ @Test - public void testGetRelativeWebPath() throws Exception { - assertEquals(PathTool.getRelativeWebPath(null, null), ""); - assertEquals(PathTool.getRelativeWebPath(null, "http://plexus.codehaus.org/"), ""); - assertEquals(PathTool.getRelativeWebPath("http://plexus.codehaus.org/", null), ""); + void getRelativeWebPath() throws Exception { + assertEquals("", PathTool.getRelativeWebPath(null, null)); + assertEquals("", PathTool.getRelativeWebPath(null, "http://plexus.codehaus.org/")); + assertEquals("", PathTool.getRelativeWebPath("http://plexus.codehaus.org/", null)); assertEquals( + "plexus-utils/index.html", PathTool.getRelativeWebPath( - "http://plexus.codehaus.org/", "http://plexus.codehaus.org/plexus-utils/index.html"), - "plexus-utils/index.html"); + "http://plexus.codehaus.org/", "http://plexus.codehaus.org/plexus-utils/index.html")); assertEquals( + "../../", PathTool.getRelativeWebPath( - "http://plexus.codehaus.org/plexus-utils/index.html", "http://plexus.codehaus.org/"), - "../../"); + "http://plexus.codehaus.org/plexus-utils/index.html", "http://plexus.codehaus.org/")); } /** @@ -102,34 +86,34 @@ public void testGetRelativeWebPath() throws Exception { * @throws java.lang.Exception */ @Test - public void testGetRelativeFilePath() throws Exception { + void getRelativeFilePath() throws Exception { if (Os.isFamily(Os.FAMILY_WINDOWS)) { - assertEquals(PathTool.getRelativeFilePath(null, null), ""); - assertEquals(PathTool.getRelativeFilePath(null, "c:\\tools\\java\\bin"), ""); - assertEquals(PathTool.getRelativeFilePath("c:\\tools\\java", null), ""); - assertEquals(PathTool.getRelativeFilePath("c:\\tools", "c:\\tools\\java\\bin"), "java\\bin"); - assertEquals(PathTool.getRelativeFilePath("c:\\tools", "c:\\tools\\java\\bin\\"), "java\\bin\\"); - assertEquals(PathTool.getRelativeFilePath("c:\\tools\\java\\bin", "c:\\tools"), "..\\.."); + assertEquals("", PathTool.getRelativeFilePath(null, null)); + assertEquals("", PathTool.getRelativeFilePath(null, "c:\\tools\\java\\bin")); + assertEquals("", PathTool.getRelativeFilePath("c:\\tools\\java", null)); + assertEquals("java\\bin", PathTool.getRelativeFilePath("c:\\tools", "c:\\tools\\java\\bin")); + assertEquals("java\\bin\\", PathTool.getRelativeFilePath("c:\\tools", "c:\\tools\\java\\bin\\")); + assertEquals("..\\..", PathTool.getRelativeFilePath("c:\\tools\\java\\bin", "c:\\tools")); assertEquals( - PathTool.getRelativeFilePath("c:\\tools\\", "c:\\tools\\java\\bin\\java.exe"), - "java\\bin\\java.exe"); - assertEquals(PathTool.getRelativeFilePath("c:\\tools\\java\\bin\\java.sh", "c:\\tools"), "..\\..\\.."); - assertEquals(PathTool.getRelativeFilePath("c:\\tools", "c:\\bin"), "..\\bin"); - assertEquals(PathTool.getRelativeFilePath("c:\\bin", "c:\\tools"), "..\\tools"); - assertEquals(PathTool.getRelativeFilePath("c:\\bin", "c:\\bin"), ""); + "java\\bin\\java.exe", + PathTool.getRelativeFilePath("c:\\tools\\", "c:\\tools\\java\\bin\\java.exe")); + assertEquals("..\\..\\..", PathTool.getRelativeFilePath("c:\\tools\\java\\bin\\java.sh", "c:\\tools")); + assertEquals("..\\bin", PathTool.getRelativeFilePath("c:\\tools", "c:\\bin")); + assertEquals("..\\tools", PathTool.getRelativeFilePath("c:\\bin", "c:\\tools")); + assertEquals("", PathTool.getRelativeFilePath("c:\\bin", "c:\\bin")); } else { - assertEquals(PathTool.getRelativeFilePath(null, null), ""); - assertEquals(PathTool.getRelativeFilePath(null, "/usr/local/java/bin"), ""); - assertEquals(PathTool.getRelativeFilePath("/usr/local", null), ""); - assertEquals(PathTool.getRelativeFilePath("/usr/local", "/usr/local/java/bin"), "java/bin"); - assertEquals(PathTool.getRelativeFilePath("/usr/local", "/usr/local/java/bin/"), "java/bin/"); - assertEquals(PathTool.getRelativeFilePath("/usr/local/java/bin", "/usr/local/"), "../../"); + assertEquals("", PathTool.getRelativeFilePath(null, null)); + assertEquals("", PathTool.getRelativeFilePath(null, "/usr/local/java/bin")); + assertEquals("", PathTool.getRelativeFilePath("/usr/local", null)); + assertEquals("java/bin", PathTool.getRelativeFilePath("/usr/local", "/usr/local/java/bin")); + assertEquals("java/bin/", PathTool.getRelativeFilePath("/usr/local", "/usr/local/java/bin/")); + assertEquals("../../", PathTool.getRelativeFilePath("/usr/local/java/bin", "/usr/local/")); assertEquals( - PathTool.getRelativeFilePath("/usr/local/", "/usr/local/java/bin/java.sh"), "java/bin/java.sh"); - assertEquals(PathTool.getRelativeFilePath("/usr/local/java/bin/java.sh", "/usr/local/"), "../../../"); - assertEquals(PathTool.getRelativeFilePath("/usr/local/", "/bin"), "../../bin"); - assertEquals(PathTool.getRelativeFilePath("/bin", "/usr/local"), "../usr/local"); - assertEquals(PathTool.getRelativeFilePath("/bin", "/bin"), ""); + "java/bin/java.sh", PathTool.getRelativeFilePath("/usr/local/", "/usr/local/java/bin/java.sh")); + assertEquals("../../../", PathTool.getRelativeFilePath("/usr/local/java/bin/java.sh", "/usr/local/")); + assertEquals("../../bin", PathTool.getRelativeFilePath("/usr/local/", "/bin")); + assertEquals("../usr/local", PathTool.getRelativeFilePath("/bin", "/usr/local")); + assertEquals("", PathTool.getRelativeFilePath("/bin", "/bin")); } } } diff --git a/src/test/java/org/codehaus/plexus/util/PerfTest.java b/src/test/java/org/codehaus/plexus/util/PerfTest.java index e7542e1d..235ccb8c 100644 --- a/src/test/java/org/codehaus/plexus/util/PerfTest.java +++ b/src/test/java/org/codehaus/plexus/util/PerfTest.java @@ -1,22 +1,6 @@ package org.codehaus.plexus.util; -/* - * Copyright 2011 The Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.junit.Test; +import org.junit.jupiter.api.Test; /** *PerfTest class.
@@ -25,7 +9,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class PerfTest { +class PerfTest { String src = "012345578901234556789012345678901234456789012345678901234567890"; private final int oops = 100; @@ -34,7 +18,7 @@ public class PerfTest { *testSubString.
*/ @Test - public void testSubString() { + void subString() { StringBuilder res = new StringBuilder(); int len = src.length(); for (int cnt = 0; cnt < oops; cnt++) { @@ -50,7 +34,7 @@ public void testSubString() { *testResDir.
*/ @Test - public void testResDir() { + void resDir() { StringBuilder res = new StringBuilder(); int len = src.length(); for (int cnt = 0; cnt < oops; cnt++) { diff --git a/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java b/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java index c9e982a1..9817a75a 100644 --- a/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java @@ -19,9 +19,9 @@ import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * This is used to test ReflectionUtils for correctness. @@ -40,7 +40,7 @@ public final class ReflectionUtilsTest { * @throws java.lang.IllegalAccessException if any. */ @Test - public void testSimpleVariableAccess() throws IllegalAccessException { + void simpleVariableAccess() throws IllegalAccessException { assertEquals("woohoo", (String) ReflectionUtils.getValueIncludingSuperclasses("myString", testClass)); } @@ -50,7 +50,7 @@ public void testSimpleVariableAccess() throws IllegalAccessException { * @throws java.lang.IllegalAccessException if any. */ @Test - public void testComplexVariableAccess() throws IllegalAccessException { + void complexVariableAccess() throws IllegalAccessException { MapSelectorUtilsTest class.
@@ -30,12 +30,12 @@ * @author herve * @since 3.4.0 */ -public class SelectorUtilsTest { +class SelectorUtilsTest { /** *testExtractPattern.
*/ @Test - public void testExtractPattern() { + void extractPattern() { assertEquals("[A-Z].*", SelectorUtils.extractPattern("%regex[[A-Z].*]", "/")); assertEquals("ABC*", SelectorUtils.extractPattern("%ant[ABC*]", "/")); assertEquals("some/ABC*", SelectorUtils.extractPattern("%ant[some/ABC*]", "/")); @@ -48,7 +48,7 @@ public void testExtractPattern() { *testIsAntPrefixedPattern.
*/ @Test - public void testIsAntPrefixedPattern() { + void isAntPrefixedPattern() { assertTrue(SelectorUtils.isAntPrefixedPattern("%ant[A]")); // single char not allowed assertTrue(SelectorUtils.isAntPrefixedPattern("%ant[AB]")); assertFalse(SelectorUtils.isAntPrefixedPattern("%ant[]")); @@ -59,7 +59,7 @@ public void testIsAntPrefixedPattern() { *testIsRegexPrefixedPattern.
*/ @Test - public void testIsRegexPrefixedPattern() { + void isRegexPrefixedPattern() { assertTrue(SelectorUtils.isRegexPrefixedPattern("%regex[A]")); // single char not allowed assertTrue(SelectorUtils.isRegexPrefixedPattern("%regex[.*]")); assertFalse(SelectorUtils.isRegexPrefixedPattern("%regex[]")); @@ -70,7 +70,7 @@ public void testIsRegexPrefixedPattern() { *testMatchPath_DefaultFileSeparator.
*/ @Test - public void testMatchPath_DefaultFileSeparator() { + void matchPathDefaultFileSeparator() { String separator = File.separator; // Pattern and target start with file separator @@ -88,7 +88,7 @@ public void testMatchPath_DefaultFileSeparator() { *testMatchPath_UnixFileSeparator.
*/ @Test - public void testMatchPath_UnixFileSeparator() { + void matchPathUnixFileSeparator() { String separator = "/"; // Pattern and target start with file separator @@ -108,7 +108,7 @@ public void testMatchPath_UnixFileSeparator() { *testMatchPath_WindowsFileSeparator.
*/ @Test - public void testMatchPath_WindowsFileSeparator() { + void matchPathWindowsFileSeparator() { String separator = "\\"; // Pattern and target start with file separator @@ -125,29 +125,29 @@ public void testMatchPath_WindowsFileSeparator() { } @Test - public void testPatternMatchSingleWildcardPosix() { + void patternMatchSingleWildcardPosix() { assertFalse(SelectorUtils.matchPath("/com/test/*", "/com/test/test/hallo")); } @Test - public void testPatternMatchDoubleWildcardCaseInsensitivePosix() { + void patternMatchDoubleWildcardCaseInsensitivePosix() { assertTrue(SelectorUtils.matchPath("/com/test/**", "/com/test/test/hallo")); } @Test - public void testPatternMatchDoubleWildcardPosix() { + void patternMatchDoubleWildcardPosix() { assertTrue(SelectorUtils.matchPath("/com/test/**", "/com/test/test/hallo")); } @Test - public void testPatternMatchSingleWildcardWindows() { + void patternMatchSingleWildcardWindows() { assertFalse(SelectorUtils.matchPath("D:\\com\\test\\*", "D:\\com\\test\\test\\hallo")); assertFalse(SelectorUtils.matchPath("D:/com/test/*", "D:/com/test/test/hallo")); } @Test - public void testPatternMatchDoubleWildcardWindows() { + void patternMatchDoubleWildcardWindows() { assertTrue(SelectorUtils.matchPath("D:\\com\\test\\**", "D:\\com\\test\\test\\hallo")); assertTrue(SelectorUtils.matchPath("D:\\com\\test\\**", "D:/com/test/test/hallo")); diff --git a/src/test/java/org/codehaus/plexus/util/StringInputStreamTest.java b/src/test/java/org/codehaus/plexus/util/StringInputStreamTest.java index 0a76f8c8..a9e1ada7 100644 --- a/src/test/java/org/codehaus/plexus/util/StringInputStreamTest.java +++ b/src/test/java/org/codehaus/plexus/util/StringInputStreamTest.java @@ -1,22 +1,6 @@ package org.codehaus.plexus.util; -/* - * Copyright The Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; /** *StringInputStreamTest class.
@@ -25,9 +9,10 @@ * @version $Id: $Id * @since 3.4.0 */ -public class StringInputStreamTest extends TestCase { +class StringInputStreamTest { /** *testFoo.
*/ - public void testFoo() {} + @Test + void foo() {} } diff --git a/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java b/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java index d4ad8856..25a67203 100644 --- a/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java @@ -19,11 +19,12 @@ import java.util.Arrays; import java.util.Locale; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test string utils. @@ -32,34 +33,34 @@ * @version $Id: $Id * @since 3.4.0 */ -public class StringUtilsTest { +class StringUtilsTest { /** *testIsEmpty.
*/ @Test - public void testIsEmpty() { - assertEquals(true, StringUtils.isEmpty(null)); - assertEquals(true, StringUtils.isEmpty("")); - assertEquals(false, StringUtils.isEmpty(" ")); - assertEquals(false, StringUtils.isEmpty("foo")); - assertEquals(false, StringUtils.isEmpty(" foo ")); + void isEmpty() { + assertTrue(StringUtils.isEmpty(null)); + assertTrue(StringUtils.isEmpty("")); + assertFalse(StringUtils.isEmpty(" ")); + assertFalse(StringUtils.isEmpty("foo")); + assertFalse(StringUtils.isEmpty(" foo ")); } /** *testIsNotEmpty.
*/ @Test - public void testIsNotEmpty() { - assertEquals(false, StringUtils.isNotEmpty(null)); - assertEquals(false, StringUtils.isNotEmpty("")); - assertEquals(true, StringUtils.isNotEmpty(" ")); - assertEquals(true, StringUtils.isNotEmpty("foo")); - assertEquals(true, StringUtils.isNotEmpty(" foo ")); + void isNotEmpty() { + assertFalse(StringUtils.isNotEmpty(null)); + assertFalse(StringUtils.isNotEmpty("")); + assertTrue(StringUtils.isNotEmpty(" ")); + assertTrue(StringUtils.isNotEmpty("foo")); + assertTrue(StringUtils.isNotEmpty(" foo ")); } @Test - public void testIsNotEmptyNegatesIsEmpty() { + void isNotEmptyNegatesIsEmpty() { assertEquals(!StringUtils.isEmpty(null), StringUtils.isNotEmpty(null)); assertEquals(!StringUtils.isEmpty(""), StringUtils.isNotEmpty("")); assertEquals(!StringUtils.isEmpty(" "), StringUtils.isNotEmpty(" ")); @@ -71,31 +72,31 @@ public void testIsNotEmptyNegatesIsEmpty() { *testIsBlank.
*/ @Test - public void testIsBlank() { - assertEquals(true, StringUtils.isBlank(null)); - assertEquals(true, StringUtils.isBlank("")); - assertEquals(true, StringUtils.isBlank(" \t\r\n")); - assertEquals(false, StringUtils.isBlank("foo")); - assertEquals(false, StringUtils.isBlank(" foo ")); + void isBlank() { + assertTrue(StringUtils.isBlank(null)); + assertTrue(StringUtils.isBlank("")); + assertTrue(StringUtils.isBlank(" \t\r\n")); + assertFalse(StringUtils.isBlank("foo")); + assertFalse(StringUtils.isBlank(" foo ")); } /** *testIsNotBlank.
*/ @Test - public void testIsNotBlank() { - assertEquals(false, StringUtils.isNotBlank(null)); - assertEquals(false, StringUtils.isNotBlank("")); - assertEquals(false, StringUtils.isNotBlank(" \t\r\n")); - assertEquals(true, StringUtils.isNotBlank("foo")); - assertEquals(true, StringUtils.isNotBlank(" foo ")); + void isNotBlank() { + assertFalse(StringUtils.isNotBlank(null)); + assertFalse(StringUtils.isNotBlank("")); + assertFalse(StringUtils.isNotBlank(" \t\r\n")); + assertTrue(StringUtils.isNotBlank("foo")); + assertTrue(StringUtils.isNotBlank(" foo ")); } /** *testCapitalizeFirstLetter.
*/ @Test - public void testCapitalizeFirstLetter() { + void capitalizeFirstLetter() { assertEquals("Id", StringUtils.capitalizeFirstLetter("id")); assertEquals("Id", StringUtils.capitalizeFirstLetter("Id")); } @@ -104,7 +105,7 @@ public void testCapitalizeFirstLetter() { *testCapitalizeFirstLetterTurkish.
*/ @Test - public void testCapitalizeFirstLetterTurkish() { + void capitalizeFirstLetterTurkish() { Locale l = Locale.getDefault(); Locale.setDefault(new Locale("tr")); assertEquals("Id", StringUtils.capitalizeFirstLetter("id")); @@ -116,7 +117,7 @@ public void testCapitalizeFirstLetterTurkish() { *testLowerCaseFirstLetter.
*/ @Test - public void testLowerCaseFirstLetter() { + void lowerCaseFirstLetter() { assertEquals("id", StringUtils.lowercaseFirstLetter("id")); assertEquals("id", StringUtils.lowercaseFirstLetter("Id")); } @@ -125,7 +126,7 @@ public void testLowerCaseFirstLetter() { *testLowerCaseFirstLetterTurkish.
*/ @Test - public void testLowerCaseFirstLetterTurkish() { + void lowerCaseFirstLetterTurkish() { Locale l = Locale.getDefault(); Locale.setDefault(new Locale("tr")); assertEquals("id", StringUtils.lowercaseFirstLetter("id")); @@ -137,7 +138,7 @@ public void testLowerCaseFirstLetterTurkish() { *testRemoveAndHump.
*/ @Test - public void testRemoveAndHump() { + void removeAndHump() { assertEquals("Id", StringUtils.removeAndHump("id", "-")); assertEquals("SomeId", StringUtils.removeAndHump("some-id", "-")); } @@ -146,7 +147,7 @@ public void testRemoveAndHump() { *testRemoveAndHumpTurkish.
*/ @Test - public void testRemoveAndHumpTurkish() { + void removeAndHumpTurkish() { Locale l = Locale.getDefault(); Locale.setDefault(new Locale("tr")); assertEquals("Id", StringUtils.removeAndHump("id", "-")); @@ -158,7 +159,7 @@ public void testRemoveAndHumpTurkish() { *testQuote_EscapeEmbeddedSingleQuotes.
*/ @Test - public void testQuote_EscapeEmbeddedSingleQuotes() { + void quoteEscapeEmbeddedSingleQuotes() { String src = "This \'is a\' test"; String check = "\'This \\\'is a\\\' test\'"; @@ -172,7 +173,7 @@ public void testQuote_EscapeEmbeddedSingleQuotes() { *testQuote_EscapeEmbeddedSingleQuotesWithPattern.
*/ @Test - public void testQuote_EscapeEmbeddedSingleQuotesWithPattern() { + void quoteEscapeEmbeddedSingleQuotesWithPattern() { String src = "This \'is a\' test"; String check = "\'This pre'postis apre'post test\'"; @@ -186,7 +187,7 @@ public void testQuote_EscapeEmbeddedSingleQuotesWithPattern() { *testQuote_EscapeEmbeddedDoubleQuotesAndSpaces.
*/ @Test - public void testQuote_EscapeEmbeddedDoubleQuotesAndSpaces() { + void quoteEscapeEmbeddedDoubleQuotesAndSpaces() { String src = "This \"is a\" test"; String check = "\'This\\ \\\"is\\ a\\\"\\ test\'"; @@ -200,7 +201,7 @@ public void testQuote_EscapeEmbeddedDoubleQuotesAndSpaces() { *testQuote_DontQuoteIfUnneeded.
*/ @Test - public void testQuote_DontQuoteIfUnneeded() { + void quoteDontQuoteIfUnneeded() { String src = "ThisIsATest"; char[] escaped = {'\'', '\"'}; @@ -213,7 +214,7 @@ public void testQuote_DontQuoteIfUnneeded() { *testQuote_WrapWithSingleQuotes.
*/ @Test - public void testQuote_WrapWithSingleQuotes() { + void quoteWrapWithSingleQuotes() { String src = "This is a test"; String check = "\'This is a test\'"; @@ -227,7 +228,7 @@ public void testQuote_WrapWithSingleQuotes() { *testQuote_PreserveExistingQuotes.
*/ @Test - public void testQuote_PreserveExistingQuotes() { + void quotePreserveExistingQuotes() { String src = "\'This is a test\'"; char[] escaped = {'\'', '\"'}; @@ -240,7 +241,7 @@ public void testQuote_PreserveExistingQuotes() { *testQuote_WrapExistingQuotesWhenForceIsTrue.
*/ @Test - public void testQuote_WrapExistingQuotesWhenForceIsTrue() { + void quoteWrapExistingQuotesWhenForceIsTrue() { String src = "\'This is a test\'"; String check = "\'\\\'This is a test\\\'\'"; @@ -254,7 +255,7 @@ public void testQuote_WrapExistingQuotesWhenForceIsTrue() { *testQuote_ShortVersion_SingleQuotesPreserved.
*/ @Test - public void testQuote_ShortVersion_SingleQuotesPreserved() { + void quoteShortVersionSingleQuotesPreserved() { String src = "\'This is a test\'"; String result = StringUtils.quoteAndEscape(src, '\''); @@ -266,7 +267,7 @@ public void testQuote_ShortVersion_SingleQuotesPreserved() { *testSplit.
*/ @Test - public void testSplit() { + void split() { String[] tokens; tokens = StringUtils.split("", ", "); @@ -300,7 +301,7 @@ public void testSplit() { * @throws java.lang.Exception if any. */ @Test - public void testRemoveDuplicateWhitespace() throws Exception { + void removeDuplicateWhitespace() throws Exception { String s = "this is test "; assertEquals("this is test ", StringUtils.removeDuplicateWhitespace(s)); s = "this \r\n is \n \r test "; @@ -317,14 +318,14 @@ public void testRemoveDuplicateWhitespace() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testUnifyLineSeparators() throws Exception { + void unifyLineSeparators() throws Exception { String s = "this\r\nis\na\r\ntest"; try { StringUtils.unifyLineSeparators(s, "abs"); - assertTrue("Exception NOT catched", false); + assertTrue(false, "Exception NOT catched"); } catch (IllegalArgumentException e) { - assertTrue("Exception catched", true); + assertTrue(true, "Exception catched"); } assertEquals("this\nis\na\ntest", StringUtils.unifyLineSeparators(s, "\n")); diff --git a/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java b/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java index 2ca71500..37805e0a 100644 --- a/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java +++ b/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java @@ -18,16 +18,16 @@ import java.util.Vector; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Created on 21/06/2003 @@ -36,7 +36,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class SweeperPoolTest { +class SweeperPoolTest { /** The pool under test */ TestObjectPool pool; @@ -57,7 +57,7 @@ public class SweeperPoolTest { * Test the pool limits it's size, and disposes unneeded objects correctly */ @Test - public void testMaxSize() { + void maxSize() { int sweepInterval = 0; int initialCapacity = 5; int maxSize = 2; @@ -67,34 +67,31 @@ public void testMaxSize() { pool = new TestObjectPool(maxSize, minSize, initialCapacity, sweepInterval, triggerSize); Object tmp = pool.get(); - assertNull("Expected object from pool to be null", tmp); + assertNull(tmp, "Expected object from pool to be null"); pool.put(o1); - assertEquals("Expected pool to contain 1 object", 1, pool.getSize()); + assertEquals(1, pool.getSize(), "Expected pool to contain 1 object"); tmp = pool.get(); - assertSame("Expected returned pool object to be the same as the one put in", tmp, o1); + assertSame(tmp, o1, "Expected returned pool object to be the same as the one put in"); pool.put(o1); pool.put(o2); - assertEquals("Expected pool to contain 2 objects", 2, pool.getSize()); + assertEquals(2, pool.getSize(), "Expected pool to contain 2 objects"); pool.put(o3); - assertEquals("Expected pool to contain only a maximum of 2 objects.", 2, pool.getSize()); - assertEquals( - "Expected 1 disposed pool object", - 1, - pool.testGetDisposedObjects().size()); + assertEquals(2, pool.getSize(), "Expected pool to contain only a maximum of 2 objects."); + assertEquals(1, pool.testGetDisposedObjects().size(), "Expected 1 disposed pool object"); tmp = pool.testGetDisposedObjects().iterator().next(); tmp = pool.get(); - assertEquals("Expected pool size to be 1 after removing one object", 1, pool.getSize()); + assertEquals(1, pool.getSize(), "Expected pool size to be 1 after removing one object"); Object tmp2 = pool.get(); - assertEquals("Expected pool size to be 0 after removing 2 objects", 0, pool.getSize()); - assertNotSame("Expected returned objects to be different", tmp, tmp2); + assertEquals(0, pool.getSize(), "Expected pool size to be 0 after removing 2 objects"); + assertNotSame(tmp, tmp2, "Expected returned objects to be different"); } /** *testSweepAndTrim1.
*/ @Test - public void testSweepAndTrim1() { + void sweepAndTrim1() { // test trigger int sweepInterval = 1; int initialCapacity = 5; @@ -115,9 +112,8 @@ public void testSweepAndTrim1() { fail("Unexpected exception thrown. e=" + Tracer.traceToString(e)); } } - assertEquals("Expected pool to only contain 1 object", 1, pool.getSize()); - assertEquals( - "Expected 3 disposed objects", 3, pool.testGetDisposedObjects().size()); + assertEquals(1, pool.getSize(), "Expected pool to only contain 1 object"); + assertEquals(3, pool.testGetDisposedObjects().size(), "Expected 3 disposed objects"); } /** @@ -125,8 +121,8 @@ public void testSweepAndTrim1() { * * @throws java.lang.Exception if any. */ - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { o1 = new Object(); o2 = new Object(); o3 = new Object(); @@ -140,8 +136,8 @@ public void setUp() throws Exception { * * @throws java.lang.Exception if any. */ - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() throws Exception { pool.dispose(); assertTrue(pool.isDisposed()); pool = null; diff --git a/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java b/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java index 976551c7..03b31636 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java @@ -21,11 +21,12 @@ import java.util.Properties; import org.codehaus.plexus.util.Os; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; /** *CommandLineUtilsTest class.
@@ -35,14 +36,14 @@ * @since 3.4.0 */ @SuppressWarnings({"JavaDoc", "deprecation"}) -public class CommandLineUtilsTest { +class CommandLineUtilsTest { /** *testQuoteArguments.
*/ @Test - public void testQuoteArguments() { - try { + void quoteArguments() { + Assertions.assertDoesNotThrow(() -> { String result = CommandLineUtils.quote("Hello"); System.out.println(result); assertEquals("Hello", result); @@ -52,9 +53,7 @@ public void testQuoteArguments() { result = CommandLineUtils.quote("\"Hello World\""); System.out.println(result); assertEquals("\'\"Hello World\"\'", result); - } catch (Exception e) { - fail(e.getMessage()); - } + }); try { CommandLineUtils.quote("\"Hello \'World\'\'"); fail(); @@ -68,7 +67,7 @@ public void testQuoteArguments() { * @throws java.lang.Exception if any. */ @Test - public void testGetSystemEnvVarsCaseInsensitive() throws Exception { + void getSystemEnvVarsCaseInsensitive() throws Exception { Properties vars = CommandLineUtils.getSystemEnvVars(false); for (Object o : vars.keySet()) { String variable = (String) o; @@ -82,7 +81,7 @@ public void testGetSystemEnvVarsCaseInsensitive() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testGetSystemEnvVarsWindows() throws Exception { + void getSystemEnvVarsWindows() throws Exception { if (!Os.isFamily(Os.FAMILY_WINDOWS)) { return; } @@ -99,7 +98,7 @@ public void testGetSystemEnvVarsWindows() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testTranslateCommandline() throws Exception { + void translateCommandline() throws Exception { assertCmdLineArgs(new String[] {}, null); assertCmdLineArgs(new String[] {}, ""); diff --git a/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java b/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java index bdcf5556..804c5c50 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java @@ -27,12 +27,12 @@ import org.codehaus.plexus.util.cli.shell.BourneShell; import org.codehaus.plexus.util.cli.shell.CmdShell; import org.codehaus.plexus.util.cli.shell.Shell; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** *CommandlineTest class.
@@ -41,7 +41,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class CommandlineTest { +class CommandlineTest { private String baseDir; /** @@ -49,8 +49,8 @@ public class CommandlineTest { * * @throws java.lang.Exception if any. */ - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { baseDir = System.getProperty("basedir"); if (baseDir == null) { @@ -62,7 +62,7 @@ public void setUp() throws Exception { *testCommandlineWithoutCommandInConstructor.
*/ @Test - public void testCommandlineWithoutCommandInConstructor() { + void commandlineWithoutCommandInConstructor() { Commandline cmd = new Commandline(new Shell()); cmd.setWorkingDirectory(baseDir); cmd.createArgument().setValue("cd"); @@ -76,7 +76,7 @@ public void testCommandlineWithoutCommandInConstructor() { *testCommandlineWithCommandInConstructor.
*/ @Test - public void testCommandlineWithCommandInConstructor() { + void commandlineWithCommandInConstructor() { Commandline cmd = new Commandline("cd .", new Shell()); cmd.setWorkingDirectory(baseDir); @@ -90,7 +90,7 @@ public void testCommandlineWithCommandInConstructor() { * @throws java.lang.Exception if any. */ @Test - public void testExecuteBinaryOnPath() throws Exception { + void executeBinaryOnPath() throws Exception { // Maven startup script on PATH is required for this test Commandline cmd = new Commandline(); cmd.setWorkingDirectory(baseDir); @@ -110,7 +110,7 @@ public void testExecuteBinaryOnPath() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testExecute() throws Exception { + void execute() throws Exception { // allow it to detect the proper shell here. Commandline cmd = new Commandline(); cmd.setWorkingDirectory(baseDir); @@ -126,7 +126,7 @@ public void testExecute() throws Exception { *testSetLine.
*/ @Test - public void testSetLine() { + void setLine() { Commandline cmd = new Commandline(new Shell()); cmd.setWorkingDirectory(baseDir); cmd.setExecutable("echo"); @@ -141,7 +141,7 @@ public void testSetLine() { *testCreateCommandInReverseOrder.
*/ @Test - public void testCreateCommandInReverseOrder() { + void createCommandInReverseOrder() { Commandline cmd = new Commandline(new Shell()); cmd.setWorkingDirectory(baseDir); cmd.createArgument().setValue("."); @@ -155,7 +155,7 @@ public void testCreateCommandInReverseOrder() { *testSetFile.
*/ @Test - public void testSetFile() { + void setFile() { Commandline cmd = new Commandline(new Shell()); cmd.setWorkingDirectory(baseDir); cmd.createArgument().setValue("more"); @@ -176,13 +176,13 @@ public void testSetFile() { * @throws java.lang.Exception if any. */ @Test - public void testGetShellCommandLineWindows() throws Exception { + void getShellCommandLineWindows() throws Exception { Commandline cmd = new Commandline(new CmdShell()); cmd.setExecutable("c:\\Program Files\\xxx"); cmd.addArguments(new String[] {"a", "b"}); String[] shellCommandline = cmd.getShellCommandline(); - assertEquals("Command line size", 4, shellCommandline.length); + assertEquals(4, shellCommandline.length, "Command line size"); assertEquals("cmd.exe", shellCommandline[0]); assertEquals("/X", shellCommandline[1]); @@ -198,13 +198,13 @@ public void testGetShellCommandLineWindows() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testGetShellCommandLineWindowsWithSeveralQuotes() throws Exception { + void getShellCommandLineWindowsWithSeveralQuotes() throws Exception { Commandline cmd = new Commandline(new CmdShell()); cmd.setExecutable("c:\\Program Files\\xxx"); cmd.addArguments(new String[] {"c:\\Documents and Settings\\whatever", "b"}); String[] shellCommandline = cmd.getShellCommandline(); - assertEquals("Command line size", 4, shellCommandline.length); + assertEquals(4, shellCommandline.length, "Command line size"); assertEquals("cmd.exe", shellCommandline[0]); assertEquals("/X", shellCommandline[1]); @@ -221,14 +221,14 @@ public void testGetShellCommandLineWindowsWithSeveralQuotes() throws Exception { * @throws java.lang.Exception */ @Test - public void testGetShellCommandLineBash() throws Exception { + void getShellCommandLineBash() throws Exception { Commandline cmd = new Commandline(new BourneShell()); cmd.setExecutable("/bin/echo"); cmd.addArguments(new String[] {"hello world"}); String[] shellCommandline = cmd.getShellCommandline(); - assertEquals("Command line size", 3, shellCommandline.length); + assertEquals(3, shellCommandline.length, "Command line size"); assertEquals("/bin/sh", shellCommandline[0]); assertEquals("-c", shellCommandline[1]); @@ -245,7 +245,7 @@ public void testGetShellCommandLineBash() throws Exception { * @throws java.lang.Exception */ @Test - public void testGetShellCommandLineBash_WithWorkingDirectory() throws Exception { + void getShellCommandLineBashWithWorkingDirectory() throws Exception { Commandline cmd = new Commandline(new BourneShell()); cmd.setExecutable("/bin/echo"); cmd.addArguments(new String[] {"hello world"}); @@ -255,7 +255,7 @@ public void testGetShellCommandLineBash_WithWorkingDirectory() throws Exception String[] shellCommandline = cmd.getShellCommandline(); - assertEquals("Command line size", 3, shellCommandline.length); + assertEquals(3, shellCommandline.length, "Command line size"); assertEquals("/bin/sh", shellCommandline[0]); assertEquals("-c", shellCommandline[1]); @@ -272,14 +272,14 @@ public void testGetShellCommandLineBash_WithWorkingDirectory() throws Exception * @throws java.lang.Exception */ @Test - public void testGetShellCommandLineBash_WithSingleQuotedArg() throws Exception { + void getShellCommandLineBashWithSingleQuotedArg() throws Exception { Commandline cmd = new Commandline(new BourneShell()); cmd.setExecutable("/bin/echo"); cmd.addArguments(new String[] {"\'hello world\'"}); String[] shellCommandline = cmd.getShellCommandline(); - assertEquals("Command line size", 3, shellCommandline.length); + assertEquals(3, shellCommandline.length, "Command line size"); assertEquals("/bin/sh", shellCommandline[0]); assertEquals("-c", shellCommandline[1]); @@ -296,13 +296,13 @@ public void testGetShellCommandLineBash_WithSingleQuotedArg() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testGetShellCommandLineNonWindows() throws Exception { + void getShellCommandLineNonWindows() throws Exception { Commandline cmd = new Commandline(new BourneShell()); cmd.setExecutable("/usr/bin"); cmd.addArguments(new String[] {"a", "b"}); String[] shellCommandline = cmd.getShellCommandline(); - assertEquals("Command line size", 3, shellCommandline.length); + assertEquals(3, shellCommandline.length, "Command line size"); assertEquals("/bin/sh", shellCommandline[0]); assertEquals("-c", shellCommandline[1]); @@ -320,7 +320,7 @@ public void testGetShellCommandLineNonWindows() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testEnvironment() throws Exception { + void environment() throws Exception { Commandline cmd = new Commandline(); cmd.addEnvironment("name", "value"); assertEquals("name=value", cmd.getEnvironmentVariables()[0]); @@ -332,7 +332,7 @@ public void testEnvironment() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testEnvironmentWitOverrideSystemEnvironment() throws Exception { + void environmentWitOverrideSystemEnvironment() throws Exception { Commandline cmd = new Commandline(); cmd.addSystemEnvironment(); cmd.addEnvironment("JAVA_HOME", "/usr/jdk1.5"); @@ -353,7 +353,7 @@ public void testEnvironmentWitOverrideSystemEnvironment() throws Exception { * @throws java.lang.Exception */ @Test - public void testQuotedPathWithSingleApostrophe() throws Exception { + void quotedPathWithSingleApostrophe() throws Exception { File dir = new File(System.getProperty("basedir"), "target/test/quotedpath'test"); createAndCallScript(dir, "echo Quoted"); @@ -367,7 +367,7 @@ public void testQuotedPathWithSingleApostrophe() throws Exception { * @throws java.lang.Exception */ @Test - public void testPathWithShellExpansionStrings() throws Exception { + void pathWithShellExpansionStrings() throws Exception { File dir = new File(System.getProperty("basedir"), "target/test/dollar$test"); createAndCallScript(dir, "echo Quoted"); } @@ -378,7 +378,7 @@ public void testPathWithShellExpansionStrings() throws Exception { * @throws java.lang.Exception */ @Test - public void testQuotedPathWithQuotationMark() throws Exception { + void quotedPathWithQuotationMark() throws Exception { if (Os.isFamily(Os.FAMILY_WINDOWS)) { System.out.println("testQuotedPathWithQuotationMark() skipped on Windows"); return; @@ -398,7 +398,7 @@ public void testQuotedPathWithQuotationMark() throws Exception { * @throws java.lang.Exception */ @Test - public void testQuotedPathWithQuotationMarkAndApostrophe() throws Exception { + void quotedPathWithQuotationMarkAndApostrophe() throws Exception { if (Os.isFamily(Os.FAMILY_WINDOWS)) { System.out.println("testQuotedPathWithQuotationMarkAndApostrophe() skipped on Windows"); return; @@ -417,7 +417,7 @@ public void testQuotedPathWithQuotationMarkAndApostrophe() throws Exception { * @throws java.lang.Exception */ @Test - public void testOnlyQuotedPath() throws Exception { + void onlyQuotedPath() throws Exception { File dir = new File(System.getProperty("basedir"), "target/test/quotedpath\'test"); File javaHome = new File(System.getProperty("java.home")); @@ -446,10 +446,10 @@ public void testOnlyQuotedPath() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testDollarSignInArgumentPath() throws Exception { + void dollarSignInArgumentPath() throws Exception { File dir = new File(System.getProperty("basedir"), "target/test"); if (!dir.exists()) { - assertTrue("Can't create dir:" + dir.getAbsolutePath(), dir.mkdirs()); + assertTrue(dir.mkdirs(), "Can't create dir:" + dir.getAbsolutePath()); } Writer writer = null; @@ -479,7 +479,7 @@ public void testDollarSignInArgumentPath() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testTimeOutException() throws Exception { + void timeOutException() throws Exception { File javaHome = new File(System.getProperty("java.home")); File java; if (Os.isFamily(Os.FAMILY_WINDOWS)) { @@ -542,7 +542,7 @@ private static void makeExecutable(File path) throws IOException { */ private static void createAndCallScript(File dir, String content) throws Exception { if (!dir.exists()) { - assertTrue("Can't create dir:" + dir.getAbsolutePath(), dir.mkdirs()); + assertTrue(dir.mkdirs(), "Can't create dir:" + dir.getAbsolutePath()); } // Create a script file diff --git a/src/test/java/org/codehaus/plexus/util/cli/DefaultConsumerTest.java b/src/test/java/org/codehaus/plexus/util/cli/DefaultConsumerTest.java index 92dd21db..6f201346 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/DefaultConsumerTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/DefaultConsumerTest.java @@ -1,22 +1,6 @@ package org.codehaus.plexus.util.cli; -/* - * Copyright The Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.junit.Test; +import org.junit.jupiter.api.Test; /** *DefaultConsumerTest class.
@@ -25,14 +9,14 @@ * @version $Id: $Id * @since 3.4.0 */ -public class DefaultConsumerTest { +class DefaultConsumerTest { /** *testConsumeLine.
* * @throws java.lang.Exception if any. */ @Test - public void testConsumeLine() throws Exception { + void consumeLine() throws Exception { DefaultConsumer cons = new DefaultConsumer(); cons.consumeLine("Test DefaultConsumer consumeLine"); } diff --git a/src/test/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizerTest.java b/src/test/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizerTest.java index 8376a2c0..98d19c95 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizerTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizerTest.java @@ -1,25 +1,10 @@ package org.codehaus.plexus.util.cli; -/* - * Copyright The Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.fail; /** *EnhancedStringTokenizerTest class.
@@ -28,12 +13,12 @@ * @version $Id: $Id * @since 3.4.0 */ -public class EnhancedStringTokenizerTest { +class EnhancedStringTokenizerTest { /** *test1.
*/ @Test - public void test1() { + void test1() { EnhancedStringTokenizer est = new EnhancedStringTokenizer("this is a test string"); StringBuilder sb = new StringBuilder(); while (est.hasMoreTokens()) { @@ -47,58 +32,58 @@ public void test1() { *test2.
*/ @Test - public void test2() { + void test2() { EnhancedStringTokenizer est = new EnhancedStringTokenizer("1,,,3,,4", ","); - assertEquals("Token 1", "1", est.nextToken()); - assertEquals("Token 2", "", est.nextToken()); - assertEquals("Token 3", "", est.nextToken()); - assertEquals("Token 4", "3", est.nextToken()); - assertEquals("Token 5", "", est.nextToken()); - assertEquals("Token 6", "4", est.nextToken()); + assertEquals("1", est.nextToken(), "Token 1"); + assertEquals("", est.nextToken(), "Token 2"); + assertEquals("", est.nextToken(), "Token 3"); + assertEquals("3", est.nextToken(), "Token 4"); + assertEquals("", est.nextToken(), "Token 5"); + assertEquals("4", est.nextToken(), "Token 6"); } /** *test3.
*/ @Test - public void test3() { + void test3() { EnhancedStringTokenizer est = new EnhancedStringTokenizer("1,,,3,,4", ",", true); - assertEquals("Token 1", "1", est.nextToken()); - assertEquals("Token 2", ",", est.nextToken()); - assertEquals("Token 3", "", est.nextToken()); - assertEquals("Token 4", ",", est.nextToken()); - assertEquals("Token 5", "", est.nextToken()); - assertEquals("Token 6", ",", est.nextToken()); - assertEquals("Token 7", "3", est.nextToken()); - assertEquals("Token 8", ",", est.nextToken()); - assertEquals("Token 9", "", est.nextToken()); - assertEquals("Token 10", ",", est.nextToken()); - assertEquals("Token 11", "4", est.nextToken()); + assertEquals("1", est.nextToken(), "Token 1"); + assertEquals(",", est.nextToken(), "Token 2"); + assertEquals("", est.nextToken(), "Token 3"); + assertEquals(",", est.nextToken(), "Token 4"); + assertEquals("", est.nextToken(), "Token 5"); + assertEquals(",", est.nextToken(), "Token 6"); + assertEquals("3", est.nextToken(), "Token 7"); + assertEquals(",", est.nextToken(), "Token 8"); + assertEquals("", est.nextToken(), "Token 9"); + assertEquals(",", est.nextToken(), "Token 10"); + assertEquals("4", est.nextToken(), "Token 11"); } /** *testMultipleDelim.
*/ @Test - public void testMultipleDelim() { + void multipleDelim() { EnhancedStringTokenizer est = new EnhancedStringTokenizer("1 2|3|4", " |", true); - assertEquals("Token 1", "1", est.nextToken()); - assertEquals("Token 2", " ", est.nextToken()); - assertEquals("Token 3", "2", est.nextToken()); - assertEquals("Token 4", "|", est.nextToken()); - assertEquals("Token 5", "3", est.nextToken()); - assertEquals("Token 6", "|", est.nextToken()); - assertEquals("Token 7", "4", est.nextToken()); - assertEquals("est.hasMoreTokens()", false, est.hasMoreTokens()); + assertEquals("1", est.nextToken(), "Token 1"); + assertEquals(" ", est.nextToken(), "Token 2"); + assertEquals("2", est.nextToken(), "Token 3"); + assertEquals("|", est.nextToken(), "Token 4"); + assertEquals("3", est.nextToken(), "Token 5"); + assertEquals("|", est.nextToken(), "Token 6"); + assertEquals("4", est.nextToken(), "Token 7"); + assertFalse(est.hasMoreTokens(), "est.hasMoreTokens()"); } /** *testEmptyString.
*/ @Test - public void testEmptyString() { + void emptyString() { EnhancedStringTokenizer est = new EnhancedStringTokenizer(""); - assertEquals("est.hasMoreTokens()", false, est.hasMoreTokens()); + assertFalse(est.hasMoreTokens(), "est.hasMoreTokens()"); try { est.nextToken(); fail(); @@ -110,10 +95,10 @@ public void testEmptyString() { *testSimpleString.
*/ @Test - public void testSimpleString() { + void simpleString() { EnhancedStringTokenizer est = new EnhancedStringTokenizer("a "); - assertEquals("Token 1", "a", est.nextToken()); - assertEquals("Token 2", "", est.nextToken()); - assertEquals("est.hasMoreTokens()", false, est.hasMoreTokens()); + assertEquals("a", est.nextToken(), "Token 1"); + assertEquals("", est.nextToken(), "Token 2"); + assertFalse(est.hasMoreTokens(), "est.hasMoreTokens()"); } } diff --git a/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java b/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java index 2a327933..ef916648 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java @@ -60,11 +60,11 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** *StreamPumperTest class.
@@ -73,14 +73,14 @@ * @version $Id: $Id * @since 3.4.0 */ -public class StreamPumperTest { +class StreamPumperTest { private String lineSeparator = System.lineSeparator(); /** *testPumping.
*/ @Test - public void testPumping() { + void pumping() { String line1 = "line1"; String line2 = "line2"; String lines = line1 + "\n" + line2; @@ -99,7 +99,7 @@ public void testPumping() { *testPumpingWithPrintWriter.
*/ @Test - public void testPumpingWithPrintWriter() { + void pumpingWithPrintWriter() { String inputString = "This a test string"; ByteArrayInputStream bais = new ByteArrayInputStream(inputString.getBytes()); StringWriter sw = new StringWriter(); @@ -116,12 +116,12 @@ public void testPumpingWithPrintWriter() { *testPumperReadsInputStreamUntilEndEvenIfConsumerFails.
*/ @Test - public void testPumperReadsInputStreamUntilEndEvenIfConsumerFails() { + void pumperReadsInputStreamUntilEndEvenIfConsumerFails() { // the number of bytes generated should surely exceed the read buffer used by the pumper GeneratorInputStream gis = new GeneratorInputStream(1024 * 1024 * 4); StreamPumper pumper = new StreamPumper(gis, new FailingConsumer()); pumper.run(); - assertEquals("input stream was not fully consumed, producer deadlocks", gis.size, gis.read); + assertEquals(gis.size, gis.read, "input stream was not fully consumed, producer deadlocks"); assertTrue(gis.closed); assertNotNull(pumper.getException()); } @@ -209,7 +209,7 @@ public void consumeLine(String line) { *testEnabled.
*/ @Test - public void testEnabled() { + void enabled() { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream("AB\nCE\nEF".getBytes()); TestConsumer streamConsumer = new TestConsumer(); StreamPumper streamPumper = new StreamPumper(byteArrayInputStream, streamConsumer); @@ -221,7 +221,7 @@ public void testEnabled() { *testDisabled.
*/ @Test - public void testDisabled() { + void disabled() { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream("AB\nCE\nEF".getBytes()); TestConsumer streamConsumer = new TestConsumer(); StreamPumper streamPumper = new StreamPumper(byteArrayInputStream, streamConsumer); diff --git a/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java b/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java index f20791c7..f45ab268 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java @@ -21,10 +21,10 @@ import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.cli.Commandline; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** *BourneShellTest class.
@@ -33,7 +33,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class BourneShellTest { +class BourneShellTest { /** *newShell.
@@ -48,7 +48,7 @@ protected Shell newShell() { *testQuoteWorkingDirectoryAndExecutable.
*/ @Test - public void testQuoteWorkingDirectoryAndExecutable() { + void quoteWorkingDirectoryAndExecutable() { Shell sh = newShell(); sh.setWorkingDirectory("/usr/local/bin"); @@ -64,7 +64,7 @@ public void testQuoteWorkingDirectoryAndExecutable() { *testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes.
*/ @Test - public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes() { + void quoteWorkingDirectoryAndExecutableWDPathWithSingleQuotes() { Shell sh = newShell(); sh.setWorkingDirectory("/usr/local/'something else'"); @@ -80,7 +80,7 @@ public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes() { *testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes_BackslashFileSep.
*/ @Test - public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes_BackslashFileSep() { + void quoteWorkingDirectoryAndExecutableWDPathWithSingleQuotesBackslashFileSep() { Shell sh = newShell(); sh.setWorkingDirectory("\\usr\\local\\'something else'"); @@ -96,7 +96,7 @@ public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes_Backsl *testPreserveSingleQuotesOnArgument.
*/ @Test - public void testPreserveSingleQuotesOnArgument() { + void preserveSingleQuotesOnArgument() { Shell sh = newShell(); sh.setWorkingDirectory("/usr/bin"); @@ -115,7 +115,7 @@ public void testPreserveSingleQuotesOnArgument() { *testAddSingleQuotesOnArgumentWithSpaces.
*/ @Test - public void testAddSingleQuotesOnArgumentWithSpaces() { + void addSingleQuotesOnArgumentWithSpaces() { Shell sh = newShell(); sh.setWorkingDirectory("/usr/bin"); @@ -134,7 +134,7 @@ public void testAddSingleQuotesOnArgumentWithSpaces() { *testEscapeSingleQuotesOnArgument.
*/ @Test - public void testEscapeSingleQuotesOnArgument() { + void escapeSingleQuotesOnArgument() { Shell sh = newShell(); sh.setWorkingDirectory("/usr/bin"); @@ -154,7 +154,7 @@ public void testEscapeSingleQuotesOnArgument() { *testArgumentsWithsemicolon.
*/ @Test - public void testArgumentsWithsemicolon() { + void argumentsWithsemicolon() { System.out.println("---- semi colon tests ----"); @@ -215,7 +215,7 @@ public void testArgumentsWithsemicolon() { * @throws java.lang.Exception if any. */ @Test - public void testBourneShellQuotingCharacters() throws Exception { + void bourneShellQuotingCharacters() throws Exception { // { ' ', '$', ';', '&', '|', '<', '>', '*', '?', '(', ')' }; // test with values http://steve-parker.org/sh/bourne.shtml Appendix B - Meta-characters and Reserved Words Commandline commandline = new Commandline(newShell()); diff --git a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java index 499fa555..89b67224 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java @@ -19,9 +19,9 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** *CycleDetectedExceptionTest class.
@@ -30,12 +30,12 @@ * @version $Id: $Id * @since 3.4.0 */ -public class CycleDetectedExceptionTest { +class CycleDetectedExceptionTest { /** *testException.
*/ @Test - public void testException() { + void exception() { final ListCycleDetectorTest class.
@@ -33,28 +34,26 @@ * @version $Id: $Id * @since 3.4.0 */ -public class CycleDetectorTest { +class CycleDetectorTest { /** *testCycyleDetection.
*/ @Test - public void testCycyleDetection() { + void cycyleDetection() { // No cycle // // a --> b --->c // - try { - final DAG dag1 = new DAG(); - - dag1.addEdge("a", "b"); + Assertions.assertDoesNotThrow( + () -> { + final DAG dag1 = new DAG(); - dag1.addEdge("b", "c"); + dag1.addEdge("a", "b"); - } catch (CycleDetectedException e) { - - fail("Cycle should not be detected"); - } + dag1.addEdge("b", "c"); + }, + "Cycle should not be detected"); // // a --> b --->c @@ -77,33 +76,32 @@ public void testCycyleDetection() { final ListDAGTest class.
@@ -33,14 +33,14 @@ * @version $Id: $Id * @since 3.4.0 */ -public class DAGTest { +class DAGTest { /** *testDAG.
* * @throws org.codehaus.plexus.util.dag.CycleDetectedException if any. */ @Test - public void testDAG() throws CycleDetectedException { + void dag() throws CycleDetectedException { final DAG dag = new DAG(); dag.addVertex("a"); @@ -146,7 +146,7 @@ public void testDAG() throws CycleDetectedException { * @throws org.codehaus.plexus.util.dag.CycleDetectedException if any. */ @Test - public void testGetPredecessors() throws CycleDetectedException { + void getPredecessors() throws CycleDetectedException { final DAG dag = new DAG(); dag.addEdge("a", "b"); diff --git a/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java b/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java index 87de9142..91c3b1d0 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java @@ -19,9 +19,9 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** *TopologicalSorterTest class.
@@ -30,14 +30,14 @@ * @version $Id: $Id * @since 3.4.0 */ -public class TopologicalSorterTest { +class TopologicalSorterTest { /** *testDfs.
* * @throws org.codehaus.plexus.util.dag.CycleDetectedException if any. */ @Test - public void testDfs() throws CycleDetectedException { + void dfs() throws CycleDetectedException { // a --> b --->c // // result a,b,c @@ -57,7 +57,7 @@ public void testDfs() throws CycleDetectedException { final ListVertexTest class.
@@ -27,12 +11,12 @@ * @version $Id: $Id * @since 3.4.0 */ -public class VertexTest { +class VertexTest { /** *testVertex.
*/ @Test - public void testVertex() { + void vertex() { final Vertex vertex1 = new Vertex("a"); diff --git a/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java b/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java index 2e712149..0b1fb1a3 100644 --- a/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java +++ b/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java @@ -21,13 +21,12 @@ import java.util.List; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -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.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; /** *ReflectionValueExtractorTest class.
@@ -36,7 +35,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class ReflectionValueExtractorTest { +class ReflectionValueExtractorTest { private Project project; /** @@ -44,8 +43,8 @@ public class ReflectionValueExtractorTest { * * @throws java.lang.Exception if any. */ - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { Dependency dependency1 = new Dependency(); dependency1.setArtifactId("dep1"); Dependency dependency2 = new Dependency(); @@ -75,7 +74,7 @@ public void setUp() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testValueExtraction() throws Exception { + void valueExtraction() throws Exception { // ---------------------------------------------------------------------- // Top level values // ---------------------------------------------------------------------- @@ -115,11 +114,11 @@ public void testValueExtraction() throws Exception { assertNotNull(dependency); - assertTrue("dep1".equals(dependency.getArtifactId())); + assertEquals("dep1", dependency.getArtifactId()); String artifactId = (String) ReflectionValueExtractor.evaluate("project.dependencies[1].artifactId", project); - assertTrue("dep2".equals(artifactId)); + assertEquals("dep2", artifactId); // Array @@ -127,11 +126,11 @@ public void testValueExtraction() throws Exception { assertNotNull(dependency); - assertTrue("dep1".equals(dependency.getArtifactId())); + assertEquals("dep1", dependency.getArtifactId()); artifactId = (String) ReflectionValueExtractor.evaluate("project.dependenciesAsArray[1].artifactId", project); - assertTrue("dep2".equals(artifactId)); + assertEquals("dep2", artifactId); // Map @@ -139,11 +138,11 @@ public void testValueExtraction() throws Exception { assertNotNull(dependency); - assertTrue("dep1".equals(dependency.getArtifactId())); + assertEquals("dep1", dependency.getArtifactId()); artifactId = (String) ReflectionValueExtractor.evaluate("project.dependenciesAsMap(dep2).artifactId", project); - assertTrue("dep2".equals(artifactId)); + assertEquals("dep2", artifactId); // ---------------------------------------------------------------------- // Build @@ -160,7 +159,7 @@ public void testValueExtraction() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testValueExtractorWithAInvalidExpression() throws Exception { + void valueExtractorWithAInvalidExpression() throws Exception { assertNull(ReflectionValueExtractor.evaluate("project.foo", project)); assertNull(ReflectionValueExtractor.evaluate("project.dependencies[10]", project)); assertNull(ReflectionValueExtractor.evaluate("project.dependencies[0].foo", project)); @@ -172,7 +171,7 @@ public void testValueExtractorWithAInvalidExpression() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testMappedDottedKey() throws Exception { + void mappedDottedKey() throws Exception { Map