testMergeMaps.
*/ @Test - public void testMergeMaps() { - MaptestMavenPropertiesLoading.
*/ - @org.junit.jupiter.api.Test - public void testMavenPropertiesLoading() { + @Test + void mavenPropertiesLoading() { // Mimic MavenSession properties loading. Properties listed // in dominant order. Properties systemProperties = new Properties(); @@ -175,26 +175,26 @@ public void testMavenPropertiesLoading() { }); // Values that should be taken from systemProperties. - assertEquals("/projects/maven", (String) result.get("maven.home")); + assertEquals("/projects/maven", result.get("maven.home")); // Values that should be taken from userBuildProperties. - assertEquals("/opt/maven/artifact", (String) result.get("maven.repo.local")); - assertEquals("false", (String) result.get("maven.repo.remote.enabled")); - assertEquals("jvanzyl", (String) result.get("maven.username")); + assertEquals("/opt/maven/artifact", result.get("maven.repo.local")); + assertEquals("false", result.get("maven.repo.remote.enabled")); + assertEquals("jvanzyl", result.get("maven.username")); // Values take from projectBuildProperties. - assertEquals("maven", (String) result.get("maven.final.name")); + assertEquals("maven", result.get("maven.final.name")); // Values take from projectProperties. - assertEquals(mavenRepoRemote, (String) result.get("maven.repo.remote")); + assertEquals(mavenRepoRemote, result.get("maven.repo.remote")); } /** *testIteratorToListWithAPopulatedList.
*/ - @org.junit.jupiter.api.Test - public void testIteratorToListWithAPopulatedList() { - ListtestIteratorToListWithAEmptyList.
*/ - @org.junit.jupiter.api.Test - public void testIteratorToListWithAEmptyList() { - ListsetUp.
*/ @BeforeEach - public void setUp() { + void setUp() { try { FileUtils.deleteDirectory(testDir); } catch (IOException e) { @@ -67,7 +67,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()); @@ -93,7 +93,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[] {"**"}); @@ -156,11 +156,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(), getTestMethodName(), 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(), getTestMethodName(), 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])"); @@ -174,7 +173,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"; @@ -194,7 +193,7 @@ public void testGeneral() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testIncludesExcludesWithWhiteSpaces() throws IOException { + void includesExcludesWithWhiteSpaces() throws IOException { this.createTestFiles(); String includes = "scanner1.dat,\n \n,scanner2.dat \n\r, scanner3.dat\n, \tscanner4.dat,scanner5.dat\n,"; @@ -213,7 +212,7 @@ public void testIncludesExcludesWithWhiteSpaces() throws IOException { *testFollowSymlinksFalse.
*/ @Test - public void testFollowSymlinksFalse() { + void followSymlinksFalse() { assumeTrue(checkTestFilesSymlinks()); DirectoryScanner ds = new DirectoryScanner(); @@ -248,7 +247,7 @@ private void assertAlwaysIncluded(ListtestFollowSymlinks.
*/ @Test - public void testFollowSymlinks() { + void followSymlinks() { assumeTrue(checkTestFilesSymlinks()); DirectoryScanner ds = new DirectoryScanner(); @@ -295,7 +294,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(); @@ -317,7 +316,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"); @@ -354,8 +353,8 @@ public void testAntExcludesOverrideIncludes() throws IOException { * * @throws java.io.IOException if any. */ - @org.junit.jupiter.api.Test - public void testAntExcludesOverrideIncludesWithExplicitAntPrefix() throws IOException { + @Test + void antExcludesOverrideIncludesWithExplicitAntPrefix() throws IOException { printTestHeader(); File dir = new File(testDir, "regex-dir"); @@ -393,8 +392,8 @@ public void testAntExcludesOverrideIncludesWithExplicitAntPrefix() throws IOExce * * @throws java.io.IOException if any. */ - @org.junit.jupiter.api.Test - public void testRegexIncludeWithExcludedPrefixDirs() throws IOException { + @Test + void regexIncludeWithExcludedPrefixDirs() throws IOException { printTestHeader(); File dir = new File(testDir, "regex-dir"); @@ -427,14 +426,14 @@ public void testRegexIncludeWithExcludedPrefixDirs() throws IOException { * * @throws java.io.IOException if any. */ - @org.junit.jupiter.api.Test - public void testRegexExcludeWithNegativeLookahead() throws IOException { + @Test + void regexExcludeWithNegativeLookahead() throws IOException { printTestHeader(); File dir = new File(testDir, "regex-dir"); try { FileUtils.deleteDirectory(dir); - } catch (IOException e) { + } catch (IOException ignored) { } dir.mkdirs(); @@ -467,13 +466,13 @@ 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"); try { FileUtils.deleteDirectory(dir); - } catch (IOException e) { + } catch (IOException ignored) { } dir.mkdirs(); @@ -508,7 +507,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 @@ -547,7 +546,7 @@ public void testDoNotScanUnnecesaryDirectories() throws IOException { "directoryTest" + File.separator + "test-dir-123" + File.separator + "file1.dat" }; - final SettestDirectoryWalk.
*/ @Test - public void testDirectoryWalk() { + void directoryWalk() { DirectoryWalker walker = new DirectoryWalker(); walker.addSCMExcludes(); diff --git a/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java b/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java index a2888538..c808adfc 100644 --- a/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java +++ b/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java @@ -72,15 +72,9 @@ protected byte[] createFile(final File file, final long size) throws IOException } byte[] data = generateTestData(size); - - final BufferedOutputStream output = new BufferedOutputStream(Files.newOutputStream(file.toPath())); - - try { + try (BufferedOutputStream output = new BufferedOutputStream(Files.newOutputStream(file.toPath()))) { output.write(data); - return data; - } finally { - output.close(); } } diff --git a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java index 090ed10b..ec19eb5b 100644 --- a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java @@ -25,6 +25,7 @@ import java.io.Reader; import java.io.Writer; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Properties; @@ -34,6 +35,7 @@ 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; @@ -83,7 +85,7 @@ public FileUtilsTest() throws Exception { * @throws java.lang.Exception if any. */ @BeforeEach - public void setUp() throws Exception { + void setUp() throws Exception { getTestDirectory().mkdirs(); createFile(testFile1, testFile1Size); createFile(testFile2, testFile2Size); @@ -99,11 +101,11 @@ public void setUp() throws Exception { *testByteCountToDisplaySize.
*/ @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 @@ -112,7 +114,7 @@ public void testByteCountToDisplaySize() { *testWaitFor.
*/ @Test - public void testWaitFor() { + void waitFor() { FileUtils.waitFor("", -1); FileUtils.waitFor("", 2); @@ -124,7 +126,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); @@ -137,7 +139,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); @@ -149,7 +151,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); } @@ -161,7 +163,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"), }; @@ -183,14 +185,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 @@ -206,7 +208,7 @@ public void testGetFilesFromExtension() { *testMkdir.
*/ @Test - public void testMkdir() { + void mkdir() { final File dir = new File(getTestDirectory(), "testdir"); FileUtils.mkdir(dir.getAbsolutePath()); dir.deleteOnExit(); @@ -216,7 +218,7 @@ public void testMkdir() { File winFile = new File(getTestDirectory(), "bla*bla"); winFile.deleteOnExit(); FileUtils.mkdir(winFile.getAbsolutePath()); - assertTrue(false); + fail(); } catch (IllegalArgumentException e) { assertTrue(true); } @@ -231,14 +233,14 @@ 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(), getTestMethodName()); 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(), getTestMethodName() + ".object"); @@ -249,7 +251,7 @@ public void testContentEquals() throws Exception { objFile2.deleteOnExit(); FileUtils.copyURLToFile(getClass().getResource("/java/util/Collection.class"), objFile2); - assertTrue(!FileUtils.contentEquals(objFile1, objFile2), "Files should not be equal."); + assertFalse(FileUtils.contentEquals(objFile1, objFile2), "Files should not be equal."); // Equal files file.createNewFile(); @@ -262,7 +264,7 @@ public void testContentEquals() throws Exception { *testRemovePath.
*/ @Test - public void testRemovePath() { + void removePath() { final String fileName = FileUtils.removePath(new File(getTestDirectory(), getTestMethodName()).getAbsolutePath()); assertEquals(getTestMethodName(), fileName); @@ -274,7 +276,7 @@ public void testRemovePath() { *testGetPath.
*/ @Test - public void testGetPath() { + void getPath() { final String fileName = FileUtils.getPath(new File(getTestDirectory(), getTestMethodName()).getAbsolutePath()); assertEquals(getTestDirectory().getAbsolutePath(), fileName); } @@ -287,7 +289,7 @@ 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(), getTestMethodName()); file.deleteOnExit(); @@ -297,12 +299,9 @@ public void testCopyURLToFile() throws Exception { FileUtils.copyURLToFile(getClass().getResource(resourceName), file); // Tests that resource was copied correctly - final InputStream fis = Files.newInputStream(file.toPath()); - try { + try (InputStream fis = Files.newInputStream(file.toPath())) { assertTrue( IOUtil.contentEquals(getClass().getResourceAsStream(resourceName), fis), "Content is not equal."); - } finally { - fis.close(); } } @@ -312,7 +311,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")); @@ -329,7 +328,7 @@ 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()); @@ -343,7 +342,7 @@ public void testForceMkdir() throws Exception { try { FileUtils.forceMkdir(testFile); fail("Exception expected."); - } catch (IOException ex) { + } catch (IOException ignored) { } testFile.delete(); @@ -357,7 +356,7 @@ public void testForceMkdir() throws Exception { File winFile = new File(getTestDirectory(), "bla*bla"); winFile.deleteOnExit(); FileUtils.forceMkdir(winFile); - assertTrue(false); + fail(); } catch (IllegalArgumentException e) { assertTrue(true); } @@ -372,14 +371,14 @@ public void testForceMkdir() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testSizeOfDirectory() throws Exception { + void sizeOfDirectory() throws Exception { final File file = new File(getTestDirectory(), getTestMethodName()); // Non-existent file try { FileUtils.sizeOfDirectory(file); fail("Exception expected."); - } catch (IllegalArgumentException ex) { + } catch (IllegalArgumentException ignored) { } // Creates file @@ -390,7 +389,7 @@ public void testSizeOfDirectory() throws Exception { try { FileUtils.sizeOfDirectory(file); fail("Exception expected."); - } catch (IllegalArgumentException ex) { + } catch (IllegalArgumentException ignored) { } // Existing directory @@ -404,11 +403,6 @@ public void testSizeOfDirectory() throws Exception { // TODO Finish test - /** - *XtestIsFileNewer.
- */ - public void XtestIsFileNewer() {} - // copyFile /** *testCopyFile1.
@@ -416,11 +410,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(destination.exists(), "Check Exist"); - assertTrue(destination.length() == testFile1Size, "Check Full copy"); + assertEquals(destination.length(), testFile1Size, "Check Full copy"); } /** @@ -429,11 +423,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(destination.exists(), "Check Exist"); - assertTrue(destination.length() == testFile2Size, "Check Full copy"); + assertEquals(destination.length(), testFile2Size, "Check Full copy"); } /** @@ -442,7 +436,7 @@ 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(); @@ -450,7 +444,7 @@ public void testCopyFile3() throws Exception { final File destination = new File(destDirectory, "copy2.txt"); FileUtils.copyFile(testFile1, destination); assertTrue(destination.exists(), "Check Exist"); - assertTrue(destination.length() == testFile2Size, "Check Full copy"); + assertEquals(destination.length(), testFile2Size, "Check Full copy"); } // linkFile @@ -460,11 +454,11 @@ 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(destination.exists(), "Check Exist"); - assertTrue(destination.length() == testFile1Size, "Check File length"); + assertEquals(destination.length(), testFile1Size, "Check File length"); assertTrue(Files.isSymbolicLink(destination.toPath()), "Check is link"); } @@ -474,11 +468,11 @@ 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(destination.exists(), "Check Exist"); - assertTrue(destination.length() == testFile2Size, "Check File length"); + assertEquals(destination.length(), testFile2Size, "Check File length"); assertTrue(Files.isSymbolicLink(destination.toPath()), "Check is link"); } @@ -488,7 +482,7 @@ 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(); @@ -496,7 +490,7 @@ public void testLinkFile3() throws Exception { final File destination = new File(destDirectory, "link2.txt"); FileUtils.linkFile(testFile1, destination); assertTrue(destination.exists(), "Check Exist"); - assertTrue(destination.length() == testFile2Size, "Check File length"); + assertEquals(destination.length(), testFile2Size, "Check File length"); assertTrue(Files.isSymbolicLink(destination.toPath()), "Check is link"); } @@ -508,7 +502,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 @@ -535,7 +529,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 @@ -559,7 +553,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 @@ -582,12 +576,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(destination.exists(), "Copy1.txt doesn't exist to delete"); FileUtils.forceDelete(destination); - assertTrue(!destination.exists(), "Check No Exist"); + assertFalse(destination.exists(), "Check No Exist"); } /** @@ -596,12 +590,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(destination.exists(), "Copy2.txt doesn't exist to delete"); FileUtils.forceDelete(destination); - assertTrue(!destination.exists(), "Check No Exist"); + assertFalse(destination.exists(), "Check No Exist"); } // copyFileToDirectory @@ -612,7 +606,7 @@ 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(); @@ -620,7 +614,7 @@ public void testCopyFile1ToDir() throws Exception { final File destination = new File(directory, testFile1.getName()); FileUtils.copyFileToDirectory(testFile1, directory); assertTrue(destination.exists(), "Check Exist"); - assertTrue(destination.length() == testFile1Size, "Check Full copy"); + assertEquals(destination.length(), testFile1Size, "Check Full copy"); } /** @@ -629,7 +623,7 @@ 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(); @@ -637,7 +631,7 @@ public void testCopyFile2ToDir() throws Exception { final File destination = new File(directory, testFile1.getName()); FileUtils.copyFileToDirectory(testFile1, directory); assertTrue(destination.exists(), "Check Exist"); - assertTrue(destination.length() == testFile2Size, "Check Full copy"); + assertEquals(destination.length(), testFile2Size, "Check Full copy"); } // copyFileToDirectoryIfModified @@ -648,7 +642,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); @@ -663,11 +657,11 @@ public void testCopyFile1ToDirIfModified() throws Exception { long timestamp = target.lastModified(); assertTrue(destination.exists(), "Check Exist"); - assertTrue(destination.length() == testFile1Size, "Check Full copy"); + assertEquals(destination.length(), testFile1Size, "Check Full copy"); FileUtils.copyFileToDirectoryIfModified(testFile1, directory); - assertTrue(timestamp == target.lastModified(), "Timestamp was changed"); + assertEquals(timestamp, target.lastModified(), "Timestamp was changed"); } /** @@ -676,7 +670,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); @@ -691,11 +685,11 @@ public void testCopyFile2ToDirIfModified() throws Exception { long timestamp = target.lastModified(); assertTrue(destination.exists(), "Check Exist"); - assertTrue(destination.length() == testFile2Size, "Check Full copy"); + assertEquals(destination.length(), testFile2Size, "Check Full copy"); FileUtils.copyFileToDirectoryIfModified(testFile2, directory); - assertTrue(timestamp == target.lastModified(), "Timestamp was changed"); + assertEquals(timestamp, target.lastModified(), "Timestamp was changed"); } // forceDelete @@ -705,10 +699,10 @@ public void testCopyFile2ToDirIfModified() throws Exception { * * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testForceDeleteDir() throws Exception { + @Test + void forceDeleteDir() throws Exception { FileUtils.forceDelete(getTestDirectory().getParentFile()); - assertTrue(!getTestDirectory().getParentFile().exists(), "Check No Exist"); + assertFalse(getTestDirectory().getParentFile().exists(), "Check No Exist"); } // resolveFile @@ -719,7 +713,7 @@ 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(file, getTestDirectory().getParentFile(), "Check .. operator"); } @@ -730,7 +724,7 @@ 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(file, getTestDirectory(), "Check . operator"); } @@ -743,7 +737,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 = { "", "/", @@ -811,7 +805,7 @@ 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); @@ -820,34 +814,33 @@ public void testFileUtils() throws Exception { final String filename = Paths.get(url.toURI()).toString(); final String filename2 = "test2.txt"; - assertTrue(FileUtils.getExtension(filename).equals("txt"), "test.txt extension == \"txt\""); + assertEquals("txt", FileUtils.getExtension(filename), "test.txt extension == \"txt\""); assertTrue(FileUtils.fileExists(filename), "Test file does exist: " + filename); - assertTrue(!FileUtils.fileExists(filename2), "Second test file does not exist"); + assertFalse(FileUtils.fileExists(filename2), "Second test file does not exist"); FileUtils.fileWrite(filename2, filename); assertTrue(FileUtils.fileExists(filename2), "Second file was written"); final String file2contents = FileUtils.fileRead(filename2); - assertTrue(FileUtils.fileRead(filename2).equals(file2contents), "Second file's contents correct"); + assertEquals(FileUtils.fileRead(filename2), file2contents, "Second file's contents correct"); FileUtils.fileAppend(filename2, filename); - assertTrue( - FileUtils.fileRead(filename2).equals(file2contents + file2contents), "Second file's contents correct"); + assertEquals(FileUtils.fileRead(filename2), file2contents + file2contents, "Second file's contents correct"); FileUtils.fileDelete(filename2); - assertTrue(!FileUtils.fileExists(filename2), "Second test file does not exist"); + assertFalse(FileUtils.fileExists(filename2), "Second test file does not exist"); final String contents = FileUtils.fileRead(filename); - assertTrue(contents.equals("This is a test"), "FileUtils.fileRead()"); + assertEquals("This is a test", contents, "FileUtils.fileRead()"); } /** *testGetExtension.
*/ @Test - public void testGetExtension() { + void getExtension() { final String[][] tests = { {"filename.ext", "ext"}, {"README", ""}, @@ -866,17 +859,17 @@ public void testGetExtension() { /** *testGetExtensionWithPaths.
*/ - @org.junit.jupiter.api.Test - public void testGetExtensionWithPaths() { + @Test + 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; final String[][] testsWithPaths = { {sep + "tmp" + sep + "foo" + sep + "filename.ext", "ext"}, {"C:" + sep + "temp" + sep + "foo" + sep + "filename.ext", "ext"}, - {"" + sep + "tmp" + sep + "foo.bar" + sep + "filename.ext", "ext"}, + {sep + "tmp" + sep + "foo.bar" + sep + "filename.ext", "ext"}, {"C:" + sep + "temp" + sep + "foo.bar" + sep + "filename.ext", "ext"}, - {"" + sep + "tmp" + sep + "foo.bar" + sep + "README", ""}, + {sep + "tmp" + sep + "foo.bar" + sep + "README", ""}, {"C:" + sep + "temp" + sep + "foo.bar" + sep + "README", ""}, {".." + sep + "filename.ext", "ext"}, {"blabla", ""} @@ -891,7 +884,7 @@ public void testGetExtensionWithPaths() { *testRemoveExtension.
*/ @Test - public void testRemoveExtension() { + void removeExtension() { final String[][] tests = { {"filename.ext", "filename"}, {"first.second.third.ext", "first.second.third"}, @@ -911,7 +904,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; @@ -946,7 +939,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); @@ -966,7 +959,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"); @@ -1029,7 +1022,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"); @@ -1071,9 +1064,9 @@ public void testCopyDirectoryStructureIfModified() throws Exception { FileUtils.copyDirectoryStructureIfModified(from, to); - File files[] = {new File(to, "root.txt"), new File(to, "2/2.txt"), new File(to, "2/2_1/2_1.txt")}; + File[] files = {new File(to, "root.txt"), new File(to, "2/2.txt"), new File(to, "2/2_1/2_1.txt")}; - long timestamps[] = {files[0].lastModified(), files[1].lastModified(), files[2].lastModified()}; + long[] timestamps = {files[0].lastModified(), files[1].lastModified(), files[2].lastModified()}; checkFile(fRoot, files[0]); @@ -1091,18 +1084,18 @@ public void testCopyDirectoryStructureIfModified() throws Exception { FileUtils.copyDirectoryStructureIfModified(from, to); - assertTrue(timestamps[0] == files[0].lastModified(), "Unmodified file was overwritten"); - assertTrue(timestamps[1] == files[1].lastModified(), "Unmodified file was overwritten"); - assertTrue(timestamps[2] == files[2].lastModified(), "Unmodified file was overwritten"); + 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(timestamps[0] == files[0].lastModified(), "Unmodified file was overwritten"); + assertEquals(timestamps[0], files[0].lastModified(), "Unmodified file was overwritten"); assertTrue(timestamps[1] < files[1].lastModified(), "Outdated file was not overwritten"); - assertTrue(timestamps[2] == files[2].lastModified(), "Unmodified file was overwritten"); + assertEquals(timestamps[2], files[2].lastModified(), "Unmodified file was overwritten"); } /** @@ -1111,7 +1104,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"); @@ -1153,7 +1146,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"); @@ -1188,7 +1181,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); @@ -1198,7 +1191,7 @@ public void testFilteredWithoutFilterAndOlderFile() throws Exception { destFile.delete(); } FileUtils.copyFile(sourceFile, destFile, null, null); - assertEqualContent(content.getBytes("UTF-8"), destFile); + assertEqualContent(content.getBytes(StandardCharsets.UTF_8), destFile); String newercontent = "oldercontent"; File olderFile = new File(getTestDirectory(), "oldersource.txt"); @@ -1219,7 +1212,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); @@ -1229,7 +1222,7 @@ public void testFilteredWithoutFilterAndOlderFileAndOverwrite() throws Exception destFile.delete(); } FileUtils.copyFile(sourceFile, destFile, null, null); - assertEqualContent(content.getBytes("UTF-8"), destFile); + assertEqualContent(content.getBytes(StandardCharsets.UTF_8), destFile); String newercontent = "oldercontent"; File olderFile = new File(getTestDirectory(), "oldersource.txt"); @@ -1250,7 +1243,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(); /* @@ -1279,7 +1272,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(); @@ -1304,7 +1297,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(); @@ -1329,7 +1322,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"); @@ -1355,7 +1348,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 @@ -1371,7 +1364,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(); @@ -1391,7 +1384,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; } @@ -1401,14 +1394,14 @@ public void testDeleteLongPathOnWindows() throws Exception { File a1 = new File(a, "a"); a1.mkdir(); - StringBuilder path = new StringBuilder(""); + StringBuilder path = new StringBuilder(); for (int i = 0; i < 100; i++) { path.append("../a/"); } - File f = new File(a1, path.toString() + "test.txt"); + File f = new File(a1, path + "test.txt"); - InputStream is = new ByteArrayInputStream("Blabla".getBytes("UTF-8")); + InputStream is = new ByteArrayInputStream("Blabla".getBytes(StandardCharsets.UTF_8)); OutputStream os = Files.newOutputStream(f.getCanonicalFile().toPath()); IOUtil.copy(is, os); IOUtil.close(is); @@ -1429,7 +1422,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(); @@ -1449,7 +1442,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"}, @@ -1478,7 +1471,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)); @@ -1506,7 +1499,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"); @@ -1519,7 +1512,7 @@ public void testDeleteDirectoryWithValidFileSymlink() throws Exception { */ symlink.delete(); } - assertTrue(!getTestDirectory().exists(), "Failed to delete test directory"); + assertFalse(getTestDirectory().exists(), "Failed to delete test directory"); } /** @@ -1528,7 +1521,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"); @@ -1541,7 +1534,7 @@ public void testDeleteDirectoryWithValidDirSymlink() throws Exception { */ symlink.delete(); } - assertTrue(!getTestDirectory().exists(), "Failed to delete test directory"); + assertFalse(getTestDirectory().exists(), "Failed to delete test directory"); } /** @@ -1550,7 +1543,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); @@ -1562,7 +1555,7 @@ public void testDeleteDirectoryWithDanglingSymlink() throws Exception { */ symlink.delete(); } - assertTrue(!getTestDirectory().exists(), "Failed to delete test directory"); + assertFalse(getTestDirectory().exists(), "Failed to delete test directory"); } /** @@ -1571,7 +1564,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(); @@ -1605,11 +1598,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(!current.getName().equals(last.getName()), "No unique name: " + current.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 2f73453f..89581a1c 100644 --- a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java @@ -26,12 +26,13 @@ import java.io.Reader; import java.io.Writer; import java.nio.file.Files; -import java.util.Arrays; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertArrayEquals; +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; @@ -58,7 +59,7 @@ public final class IOUtilTest { * methods are called. (JT) */ - private int FILE_SIZE = 1024 * 4 + 1; + private final int FILE_SIZE = 1024 * 4 + 1; private File testDirectory; @@ -68,7 +69,7 @@ public final class IOUtilTest { *setUp.
*/ @BeforeEach - public void setUp() { + void setUp() { try { testDirectory = (new File("target/test/io/")).getAbsoluteFile(); if (!testDirectory.exists()) { @@ -103,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(Arrays.equals(b0, b1), "Content not equal according to java.util.Arrays#equals()"); + assertArrayEquals(b0, b1, "Content not equal according to java.util.Arrays#equals()"); } /** Assert that the content of two files is the same. */ @@ -125,13 +126,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(fin.available() == 0, "Not all bytes were read"); + assertEquals(0, fin.available(), "Not all bytes were read"); fout.flush(); checkFile(destination); @@ -146,15 +147,15 @@ public void testInputStreamToOutputStream() throws Exception { * * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testInputStreamToWriter() throws Exception { + @Test + 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(fin.available() == 0, "Not all bytes were read"); + assertEquals(0, fin.available(), "Not all bytes were read"); fout.flush(); checkFile(destination); @@ -170,12 +171,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(fin.available() == 0, "Not all bytes were read"); - assertTrue(out.length() == FILE_SIZE, "Wrong output size: out.length()=" + 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(); } @@ -185,7 +186,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()); @@ -209,8 +210,8 @@ public void testReaderToOutputStream() throws Exception { * * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testReaderToWriter() throws Exception { + @Test + void readerToWriter() throws Exception { File destination = newFile("copy4.txt"); Reader fin = Files.newBufferedReader(testFile.toPath()); Writer fout = Files.newBufferedWriter(destination.toPath()); @@ -229,12 +230,12 @@ public void testReaderToWriter() throws Exception { * * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testReaderToString() throws Exception { + @Test + void readerToString() throws Exception { Reader fin = Files.newBufferedReader(testFile.toPath()); String out = IOUtil.toString(fin); assertNotNull(out); - assertTrue(out.length() == FILE_SIZE, "Wrong output size: out.length()=" + out.length() + "!=" + FILE_SIZE); + assertEquals(out.length(), FILE_SIZE, "Wrong output size: out.length()=" + out.length() + "!=" + FILE_SIZE); fin.close(); } @@ -243,8 +244,8 @@ public void testReaderToString() throws Exception { * * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testStringToOutputStream() throws Exception { + @Test + 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. @@ -270,8 +271,8 @@ public void testStringToOutputStream() throws Exception { * * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testStringToWriter() throws Exception { + @Test + 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. @@ -294,12 +295,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(fin.available() == 0, "Not all bytes were read"); - assertTrue(out.length == FILE_SIZE, "Wrong output size: out.length=" + 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(); } @@ -310,7 +311,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. @@ -327,7 +328,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()); @@ -348,8 +349,8 @@ public void testByteArrayToWriter() throws Exception { * * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testByteArrayToString() throws Exception { + @Test + 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. @@ -364,7 +365,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()); @@ -390,10 +391,9 @@ public void testByteArrayToOutputStream() throws Exception { /** *testCloseInputStream.
* - * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testCloseInputStream() throws Exception { + @Test + void closeInputStream() { IOUtil.close((InputStream) null); TestInputStream inputStream = new TestInputStream(); @@ -408,8 +408,8 @@ public void testCloseInputStream() throws Exception { * * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testCloseOutputStream() throws Exception { + @Test + void closeOutputStream() throws Exception { IOUtil.close((OutputStream) null); TestOutputStream outputStream = new TestOutputStream(); @@ -425,7 +425,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(); @@ -441,7 +441,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(); @@ -484,21 +484,21 @@ public void close() { closed = true; } - public int read(char cbuf[], int off, int len) { + public int read(char[] cbuf, int off, int len) { fail("This method shouldn't be called"); return 0; } } - private class TestWriter extends Writer { + private static class TestWriter extends Writer { boolean closed; public void close() { closed = true; } - public void write(char cbuf[], int off, int len) { + public void write(char[] cbuf, int off, int len) { fail("This method shouldn't be called"); } @@ -513,7 +513,7 @@ public void flush() { private File newFile(String filename) throws Exception { File destination = new File(testDirectory, filename); - assertTrue(!destination.exists(), filename + "Test output data file shouldn't previously exist"); + assertFalse(destination.exists(), filename + "Test output data file shouldn't previously exist"); return destination; } @@ -540,8 +540,9 @@ private void checkWrite(Writer output) throws Exception { } private void deleteFile(File file) throws Exception { - assertTrue( - file.length() == FILE_SIZE + 1, + assertEquals( + file.length(), + FILE_SIZE + 1, "Wrong output size: file.length()=" + file.length() + "!=" + FILE_SIZE + 1); 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 04f9924c..a8f86410 100644 --- a/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java +++ b/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java @@ -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,8 +42,8 @@ public class InterpolationFilterReaderTest { * @throws java.lang.Exception if any. */ @Test - public void testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Exception { - MaptestGetSource
*/ @Test - public void testGetSource() { + void getSource() { MatchPattern mp = MatchPattern.fromString("ABC*"); assertEquals("ABC*", mp.getSource()); mp = MatchPattern.fromString("%ant[some/ABC*]"); @@ -51,7 +51,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,8 +61,8 @@ public void testMatchPath() throws Exception { * * @see Issue #63 */ - @org.junit.jupiter.api.Test - public void testMatchPatternStart() { + @Test + void matchPatternStart() { MatchPattern mp = MatchPattern.fromString("ABC*"); assertTrue(mp.matchPatternStart("ABCD", true)); @@ -79,7 +79,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 b31b5b2f..12caa631 100644 --- a/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java +++ b/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java @@ -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.
*/ - @org.junit.jupiter.api.Test - public void testValidList() { + @Test + 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 c415a6dd..0f5ec253 100644 --- a/src/test/java/org/codehaus/plexus/util/PathToolTest.java +++ b/src/test/java/org/codehaus/plexus/util/PathToolTest.java @@ -27,20 +27,20 @@ * @version $Id: $Id * @since 3.4.0 */ -public class PathToolTest { +class PathToolTest { /** *testGetRelativePath.
* * @throws java.lang.Exception */ - @org.junit.jupiter.api.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/"), ""); + @Test + 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,31 +49,30 @@ 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")); } /** *testCalculateLink.
* - * @throws java.lang.Exception */ - @org.junit.jupiter.api.Test - public void testCalculateLink() throws Exception { - assertEquals(PathTool.calculateLink("/index.html", "../.."), "../../index.html"); + @Test + void calculateLink() { + 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 +81,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 +101,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 30676752..be29bd1b 100644 --- a/src/test/java/org/codehaus/plexus/util/PerfTest.java +++ b/src/test/java/org/codehaus/plexus/util/PerfTest.java @@ -25,7 +25,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class PerfTest { +class PerfTest { String src = "012345578901234556789012345678901234456789012345678901234567890"; private final int oops = 100; @@ -34,12 +34,12 @@ 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++) { for (int i = 0; i < len - 5; i++) { - res.append(src.substring(i, i + 4)); + res.append(src, i, i + 4); } } int i = res.length(); @@ -50,7 +50,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 53f1441f..527f7d1a 100644 --- a/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java @@ -32,7 +32,7 @@ * @since 3.4.0 */ public final class ReflectionUtilsTest { - public ReflectionUtilsTestClass testClass = new ReflectionUtilsTestClass(); + private final ReflectionUtilsTestClass testClass = new ReflectionUtilsTestClass(); /** *testSimpleVariableAccess.
@@ -40,8 +40,8 @@ public final class ReflectionUtilsTest { * @throws java.lang.IllegalAccessException if any. */ @Test - public void testSimpleVariableAccess() throws IllegalAccessException { - assertEquals("woohoo", (String) ReflectionUtils.getValueIncludingSuperclasses("myString", testClass)); + void simpleVariableAccess() throws IllegalAccessException { + assertEquals("woohoo", ReflectionUtils.getValueIncludingSuperclasses("myString", testClass)); } /** @@ -49,14 +49,14 @@ public void testSimpleVariableAccess() throws IllegalAccessException { * * @throws java.lang.IllegalAccessException if any. */ - @org.junit.jupiter.api.Test - public void testComplexVariableAccess() throws IllegalAccessException { + @Test + void complexVariableAccess() throws IllegalAccessException { MaptestExtractPattern.
*/ @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 @@ -124,30 +124,30 @@ public void testMatchPath_WindowsFileSeparator() { assertTrue(SelectorUtils.matchPath("*" + separator + "a.txt", "b" + separator + "a.txt", separator, false)); } - @org.junit.jupiter.api.Test - public void testPatternMatchSingleWildcardPosix() { + @Test + 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")); } - @org.junit.jupiter.api.Test - public void testPatternMatchSingleWildcardWindows() { + @Test + 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/StringUtilsTest.java b/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java index f8a114a1..8640fa45 100644 --- a/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java @@ -17,13 +17,12 @@ */ import java.util.Arrays; +import java.util.Collections; import java.util.Locale; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Test string utils. @@ -32,34 +31,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 ")); } - @org.junit.jupiter.api.Test - public void testIsNotEmptyNegatesIsEmpty() { + @Test + void isNotEmptyNegatesIsEmpty() { assertEquals(!StringUtils.isEmpty(null), StringUtils.isNotEmpty(null)); assertEquals(!StringUtils.isEmpty(""), StringUtils.isNotEmpty("")); assertEquals(!StringUtils.isEmpty(" "), StringUtils.isNotEmpty(" ")); @@ -71,31 +70,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 +103,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")); @@ -115,8 +114,8 @@ public void testCapitalizeFirstLetterTurkish() { /** *testLowerCaseFirstLetter.
*/ - @org.junit.jupiter.api.Test - public void testLowerCaseFirstLetter() { + @Test + void lowerCaseFirstLetter() { assertEquals("id", StringUtils.lowercaseFirstLetter("id")); assertEquals("id", StringUtils.lowercaseFirstLetter("Id")); } @@ -124,8 +123,8 @@ public void testLowerCaseFirstLetter() { /** *testLowerCaseFirstLetterTurkish.
*/ - @org.junit.jupiter.api.Test - public void testLowerCaseFirstLetterTurkish() { + @Test + void lowerCaseFirstLetterTurkish() { Locale l = Locale.getDefault(); Locale.setDefault(new Locale("tr")); assertEquals("id", StringUtils.lowercaseFirstLetter("id")); @@ -136,8 +135,8 @@ public void testLowerCaseFirstLetterTurkish() { /** *testRemoveAndHump.
*/ - @org.junit.jupiter.api.Test - public void testRemoveAndHump() { + @Test + void removeAndHump() { assertEquals("Id", StringUtils.removeAndHump("id", "-")); assertEquals("SomeId", StringUtils.removeAndHump("some-id", "-")); } @@ -146,7 +145,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,9 +157,9 @@ public void testRemoveAndHumpTurkish() { *testQuote_EscapeEmbeddedSingleQuotes.
*/ @Test - public void testQuote_EscapeEmbeddedSingleQuotes() { - String src = "This \'is a\' test"; - String check = "\'This \\\'is a\\\' test\'"; + void quoteEscapeEmbeddedSingleQuotes() { + String src = "This 'is a' test"; + String check = "'This \\'is a\\' test'"; char[] escaped = {'\'', '\"'}; String result = StringUtils.quoteAndEscape(src, '\'', escaped, '\\', false); @@ -171,10 +170,10 @@ public void testQuote_EscapeEmbeddedSingleQuotes() { /** *testQuote_EscapeEmbeddedSingleQuotesWithPattern.
*/ - @org.junit.jupiter.api.Test - public void testQuote_EscapeEmbeddedSingleQuotesWithPattern() { - String src = "This \'is a\' test"; - String check = "\'This pre'postis apre'post test\'"; + @Test + void quoteEscapeEmbeddedSingleQuotesWithPattern() { + String src = "This 'is a' test"; + String check = "'This pre'postis apre'post test'"; char[] escaped = {'\'', '\"'}; String result = StringUtils.quoteAndEscape(src, '\'', escaped, new char[] {' '}, "pre%spost", false); @@ -186,9 +185,9 @@ 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\'"; + String check = "'This\\ \\\"is\\ a\\\"\\ test'"; char[] escaped = {'\'', '\"', ' '}; String result = StringUtils.quoteAndEscape(src, '\'', escaped, '\\', false); @@ -199,8 +198,8 @@ public void testQuote_EscapeEmbeddedDoubleQuotesAndSpaces() { /** *testQuote_DontQuoteIfUnneeded.
*/ - @org.junit.jupiter.api.Test - public void testQuote_DontQuoteIfUnneeded() { + @Test + void quoteDontQuoteIfUnneeded() { String src = "ThisIsATest"; char[] escaped = {'\'', '\"'}; @@ -213,9 +212,9 @@ 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\'"; + String check = "'This is a test'"; char[] escaped = {'\'', '\"'}; String result = StringUtils.quoteAndEscape(src, '\'', escaped, '\\', false); @@ -226,9 +225,9 @@ public void testQuote_WrapWithSingleQuotes() { /** *testQuote_PreserveExistingQuotes.
*/ - @org.junit.jupiter.api.Test - public void testQuote_PreserveExistingQuotes() { - String src = "\'This is a test\'"; + @Test + void quotePreserveExistingQuotes() { + String src = "'This is a test'"; char[] escaped = {'\'', '\"'}; String result = StringUtils.quoteAndEscape(src, '\'', escaped, '\\', false); @@ -239,10 +238,10 @@ public void testQuote_PreserveExistingQuotes() { /** *testQuote_WrapExistingQuotesWhenForceIsTrue.
*/ - @org.junit.jupiter.api.Test - public void testQuote_WrapExistingQuotesWhenForceIsTrue() { - String src = "\'This is a test\'"; - String check = "\'\\\'This is a test\\\'\'"; + @Test + void quoteWrapExistingQuotesWhenForceIsTrue() { + String src = "'This is a test'"; + String check = "'\\'This is a test\\''"; char[] escaped = {'\'', '\"'}; String result = StringUtils.quoteAndEscape(src, '\'', escaped, '\\', true); @@ -253,9 +252,9 @@ public void testQuote_WrapExistingQuotesWhenForceIsTrue() { /** *testQuote_ShortVersion_SingleQuotesPreserved.
*/ - @org.junit.jupiter.api.Test - public void testQuote_ShortVersion_SingleQuotesPreserved() { - String src = "\'This is a test\'"; + @Test + void quoteShortVersionSingleQuotesPreserved() { + String src = "'This is a test'"; String result = StringUtils.quoteAndEscape(src, '\''); @@ -265,33 +264,33 @@ public void testQuote_ShortVersion_SingleQuotesPreserved() { /** *testSplit.
*/ - @org.junit.jupiter.api.Test - public void testSplit() { + @Test + void split() { String[] tokens; tokens = StringUtils.split("", ", "); assertNotNull(tokens); - assertEquals(Arrays.asList(new String[0]), Arrays.asList(tokens)); + assertEquals(Collections.emptyList(), Arrays.asList(tokens)); tokens = StringUtils.split(", ,,, ,", ", "); assertNotNull(tokens); - assertEquals(Arrays.asList(new String[0]), Arrays.asList(tokens)); + assertEquals(Collections.emptyList(), Arrays.asList(tokens)); tokens = StringUtils.split("this", ", "); assertNotNull(tokens); - assertEquals(Arrays.asList(new String[] {"this"}), Arrays.asList(tokens)); + assertEquals(Collections.singletonList("this"), Arrays.asList(tokens)); tokens = StringUtils.split("this is a test", ", "); assertNotNull(tokens); - assertEquals(Arrays.asList(new String[] {"this", "is", "a", "test"}), Arrays.asList(tokens)); + assertEquals(Arrays.asList("this", "is", "a", "test"), Arrays.asList(tokens)); tokens = StringUtils.split(" this is a test ", ", "); assertNotNull(tokens); - assertEquals(Arrays.asList(new String[] {"this", "is", "a", "test"}), Arrays.asList(tokens)); + assertEquals(Arrays.asList("this", "is", "a", "test"), Arrays.asList(tokens)); tokens = StringUtils.split("this is a test, really", ", "); assertNotNull(tokens); - assertEquals(Arrays.asList(new String[] {"this", "is", "a", "test", "really"}), Arrays.asList(tokens)); + assertEquals(Arrays.asList("this", "is", "a", "test", "really"), Arrays.asList(tokens)); } /** @@ -299,8 +298,8 @@ public void testSplit() { * * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testRemoveDuplicateWhitespace() throws Exception { + @Test + 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,12 +316,12 @@ 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(false, "Exception NOT catched"); + fail("Exception NOT catched"); } catch (IllegalArgumentException e) { assertTrue(true, "Exception catched"); } diff --git a/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java b/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java index 63a39607..3c3bb778 100644 --- a/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java +++ b/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java @@ -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; @@ -90,8 +90,8 @@ public void testMaxSize() { /** *testSweepAndTrim1.
*/ - @org.junit.jupiter.api.Test - public void testSweepAndTrim1() { + @Test + void sweepAndTrim1() { // test trigger int sweepInterval = 1; int initialCapacity = 5; @@ -122,7 +122,7 @@ public void testSweepAndTrim1() { * @throws java.lang.Exception if any. */ @BeforeEach - public void setUp() throws Exception { + void setUp() throws Exception { o1 = new Object(); o2 = new Object(); o3 = new Object(); @@ -137,14 +137,14 @@ public void setUp() throws Exception { * @throws java.lang.Exception if any. */ @AfterEach - public void tearDown() throws Exception { + void tearDown() throws Exception { pool.dispose(); assertTrue(pool.isDisposed()); pool = null; } class TestObjectPool extends SweeperPool { - private Vector