diff --git a/pom.xml b/pom.xml index d5b15af3..e9da17d9 100644 --- a/pom.xml +++ b/pom.xml @@ -97,16 +97,6 @@ limitations under the License. org/codehaus/plexus/util/FileBasedTestCase.java **/Test*.java - - - JAVA_HOME - ${JAVA_HOME} - - - M2_HOME - ${M2_HOME} - - diff --git a/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java b/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java index 765e536a..953576ef 100644 --- a/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java @@ -35,13 +35,13 @@ * @version $Id: $Id * @since 3.4.0 */ -public class CollectionUtilsTest { +class CollectionUtilsTest { /** *

testMergeMaps.

*/ @Test - public void testMergeMaps() { - Map dominantMap = new HashMap(); + void mergeMaps() { + Map dominantMap = new HashMap<>(); dominantMap.put("a", "a"); dominantMap.put("b", "b"); dominantMap.put("c", "c"); @@ -49,7 +49,7 @@ public void testMergeMaps() { dominantMap.put("e", "e"); dominantMap.put("f", "f"); - Map recessiveMap = new HashMap(); + Map recessiveMap = new HashMap<>(); recessiveMap.put("a", "invalid"); recessiveMap.put("b", "invalid"); recessiveMap.put("c", "invalid"); @@ -60,7 +60,7 @@ public void testMergeMaps() { Map result = CollectionUtils.mergeMaps(dominantMap, recessiveMap); // We should have 9 elements - assertEquals(9, result.keySet().size()); + assertEquals(9, result.size()); // Check the elements. assertEquals("a", result.get("a")); @@ -79,14 +79,14 @@ public void testMergeMaps() { */ @SuppressWarnings("unchecked") @Test - public void testMergeMapArray() { + void mergeMapArray() { // Test empty array of Maps Map result0 = CollectionUtils.mergeMaps(new Map[] {}); assertNull(result0); // Test with an array with a single element. - Map map1 = new HashMap(); + Map map1 = new HashMap<>(); map1.put("a", "a"); Map result1 = CollectionUtils.mergeMaps(new Map[] {map1}); @@ -94,7 +94,7 @@ public void testMergeMapArray() { assertEquals("a", result1.get("a")); // Test with an array with two elements. - Map map2 = new HashMap(); + Map map2 = new HashMap<>(); map2.put("a", "aa"); map2.put("b", "bb"); @@ -110,7 +110,7 @@ public void testMergeMapArray() { assertEquals("bb", result3.get("b")); // Test with an array with three elements. - Map map3 = new HashMap(); + Map map3 = new HashMap<>(); map3.put("a", "aaa"); map3.put("b", "bbb"); map3.put("c", "ccc"); @@ -132,8 +132,8 @@ public void testMergeMapArray() { /** *

testMavenPropertiesLoading.

*/ - @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() { - List original = new ArrayList(); + @Test + void iteratorToListWithAPopulatedList() { + List original = new ArrayList<>(); original.add("en"); original.add("to"); @@ -214,9 +214,9 @@ public void testIteratorToListWithAPopulatedList() { /** *

testIteratorToListWithAEmptyList.

*/ - @org.junit.jupiter.api.Test - public void testIteratorToListWithAEmptyList() { - List original = new ArrayList(); + @Test + void iteratorToListWithAEmptyList() { + List original = new ArrayList<>(); List copy = CollectionUtils.iteratorToList(original.iterator()); diff --git a/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java b/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java index e437922a..5d12b620 100644 --- a/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java +++ b/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java @@ -45,14 +45,14 @@ * @version $Id: $Id * @since 3.4.0 */ -public class DirectoryScannerTest extends FileBasedTestCase { - private static String testDir = getTestDirectory().getPath(); +class DirectoryScannerTest extends FileBasedTestCase { + private static final String testDir = getTestDirectory().getPath(); /** *

setUp.

*/ @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(List included) { *

testFollowSymlinks.

*/ @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 Set scannedDirSet = new HashSet(); + final Set scannedDirSet = new HashSet<>(); DirectoryScanner ds = new DirectoryScanner() { @Override @@ -566,7 +565,7 @@ protected void scandir(File dir, String vpath, boolean fast) { assertInclusionsAndExclusions(ds.getIncludedFiles(), excludedPaths, includedPaths); Set expectedScannedDirSet = - new HashSet(Arrays.asList("io", "directoryTest", "testDir123", "test_dir_123", "test-dir-123")); + new HashSet<>(Arrays.asList("io", "directoryTest", "testDir123", "test_dir_123", "test-dir-123")); assertEquals(expectedScannedDirSet, scannedDirSet); } @@ -577,7 +576,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"); @@ -594,7 +593,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"); @@ -622,7 +621,7 @@ private void assertInclusionsAndExclusions(String[] files, String[] excludedPath System.out.println(file); } - List failedToExclude = new ArrayList(); + List failedToExclude = new ArrayList<>(); for (String excludedPath : excludedPaths) { String alt = excludedPath.replace('/', '\\'); System.out.println("Searching for exclusion as: " + excludedPath + "\nor: " + alt); @@ -631,7 +630,7 @@ private void assertInclusionsAndExclusions(String[] files, String[] excludedPath } } - List failedToInclude = new ArrayList(); + List failedToInclude = new ArrayList<>(); for (String includedPath : includedPaths) { String alt = includedPath.replace('/', '\\'); System.out.println("Searching for inclusion as: " + includedPath + "\nor: " + alt); diff --git a/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java b/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java index ef59ba7c..f35062d7 100644 --- a/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java +++ b/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java @@ -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(); 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 { - Map m = new HashMap(); + void shouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Exception { + Map m = new HashMap<>(); m.put("test", "TestValue"); String testStr = "This is a ${test"; @@ -59,9 +59,9 @@ public void testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() t * * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testShouldNotInterpolateExpressionWithMissingEndToken() throws Exception { - Map m = new HashMap(); + @Test + void shouldNotInterpolateExpressionWithMissingEndToken() throws Exception { + Map m = new HashMap<>(); m.put("test", "TestValue"); String testStr = "This is a ${test, really"; @@ -75,8 +75,8 @@ public void testShouldNotInterpolateExpressionWithMissingEndToken() throws Excep * @throws java.lang.Exception if any. */ @Test - public void testShouldNotInterpolateWithMalformedStartToken() throws Exception { - Map m = new HashMap(); + void shouldNotInterpolateWithMalformedStartToken() throws Exception { + Map m = new HashMap<>(); m.put("test", "testValue"); String foo = "This is a $!test} again"; @@ -90,8 +90,8 @@ public void testShouldNotInterpolateWithMalformedStartToken() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testShouldNotInterpolateWithMalformedEndToken() throws Exception { - Map m = new HashMap(); + void shouldNotInterpolateWithMalformedEndToken() throws Exception { + Map m = new HashMap<>(); m.put("test", "testValue"); String foo = "This is a ${test!} again"; @@ -105,8 +105,8 @@ public void testShouldNotInterpolateWithMalformedEndToken() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testInterpolationWithMulticharDelimiters() throws Exception { - Map m = new HashMap(); + void interpolationWithMulticharDelimiters() throws Exception { + Map m = new HashMap<>(); m.put("test", "testValue"); String foo = "This is a ${test$} again"; @@ -120,8 +120,8 @@ public void testInterpolationWithMulticharDelimiters() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { - Map m = new HashMap(); + void defaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -136,8 +136,8 @@ public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Excep * @throws java.lang.Exception if any. */ @Test - public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exception { - Map m = new HashMap(); + void defaultInterpolationWithInterpolatedValueAtEnd() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -152,8 +152,8 @@ public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exceptio * @throws java.lang.Exception if any. */ @Test - public void testInterpolationWithSpecifiedBoundaryTokens() throws Exception { - Map m = new HashMap(); + void interpolationWithSpecifiedBoundaryTokens() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -168,8 +168,8 @@ public void testInterpolationWithSpecifiedBoundaryTokens() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd() throws Exception { - Map m = new HashMap(); + void interpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -184,8 +184,8 @@ public void testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValue * @throws java.lang.Exception if any. */ @Test - public void testInterpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd() throws Exception { - Map m = new HashMap(); + void interpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -200,8 +200,8 @@ public void testInterpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtE * @throws java.lang.Exception if any. */ @Test - public void testInterpolationWithSpecifiedBoundaryTokensAndAdditionalTokenCharacter() throws Exception { - Map m = new HashMap(); + void interpolationWithSpecifiedBoundaryTokensAndAdditionalTokenCharacter() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); diff --git a/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java b/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java index f05bff0b..612d41a8 100644 --- a/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java +++ b/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java @@ -36,7 +36,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class LineOrientedInterpolatingReaderTest { +class LineOrientedInterpolatingReaderTest { /* * Added and commented by jdcasey@03-Feb-2005 because it is a bug in the InterpolationFilterReader. */ @@ -45,8 +45,8 @@ public class LineOrientedInterpolatingReaderTest { * * @throws java.io.IOException if any. */ - @org.junit.jupiter.api.Test - public void testShouldInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws IOException { + @Test + void shouldInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws IOException { String testStr = "This is a ${test"; LineOrientedInterpolatingReader iReader = new LineOrientedInterpolatingReader( new StringReader(testStr), Collections.singletonMap("test", "TestValue")); @@ -63,7 +63,7 @@ public void testShouldInterpolateExpressionAtEndOfDataWithInvalidEndToken() thro * @throws java.lang.Exception if any. */ @Test - public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { + void defaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { Map m = getStandardMap(); String foo = "${name} is an ${noun}. ${not.interpolated}"; @@ -78,7 +78,7 @@ public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Excep } private Map getStandardMap() { - Map m = new HashMap(); + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); return m; @@ -89,8 +89,8 @@ private Map getStandardMap() { * * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testDefaultInterpolationWithEscapedExpression() throws Exception { + @Test + void defaultInterpolationWithEscapedExpression() throws Exception { Map m = getStandardMap(); String foo = "${name} is an ${noun}. \\${noun} value"; @@ -109,8 +109,8 @@ public void testDefaultInterpolationWithEscapedExpression() throws Exception { * * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exception { + @Test + void defaultInterpolationWithInterpolatedValueAtEnd() throws Exception { Map m = getStandardMap(); String foo = "${name} is an ${noun}"; @@ -129,8 +129,8 @@ public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exceptio * * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testInterpolationWithSpecifiedBoundaryTokens() throws Exception { + @Test + void interpolationWithSpecifiedBoundaryTokens() throws Exception { Map m = getStandardMap(); String foo = "@name@ is an @noun@. @not.interpolated@ baby @foo@. @bar@"; @@ -150,8 +150,8 @@ public void testInterpolationWithSpecifiedBoundaryTokens() throws Exception { * * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd() throws Exception { + @Test + void interpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd() throws Exception { Map m = getStandardMap(); String foo = "@name@ is an @foobarred@"; @@ -171,8 +171,8 @@ public void testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValue * * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testInterpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd() throws Exception { + @Test + void interpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd() throws Exception { Map m = getStandardMap(); String foo = "@name@ is an @noun@"; diff --git a/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java b/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java index 809b8ad4..2d67e0bf 100644 --- a/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java +++ b/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java @@ -30,13 +30,13 @@ * @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*]"); @@ -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() { List expected = Arrays.asList("ABC**", "some/ABC*", "[ABC].*"); MatchPatterns from = MatchPatterns.from("ABC**", "%ant[some/ABC*]", "%regex[[ABC].*]"); List actual = from.getSources(); @@ -50,7 +50,7 @@ public void testGetSources() { * @throws java.lang.Exception if any. */ @Test - public void testMatches() throws Exception { + void matches() throws Exception { MatchPatterns from = MatchPatterns.from("ABC**", "CDE**"); assertTrue(from.matches("ABCDE", true)); assertTrue(from.matches("CDEF", true)); diff --git a/src/test/java/org/codehaus/plexus/util/OsTest.java b/src/test/java/org/codehaus/plexus/util/OsTest.java index 0c5a8592..41bd5f53 100644 --- a/src/test/java/org/codehaus/plexus/util/OsTest.java +++ b/src/test/java/org/codehaus/plexus/util/OsTest.java @@ -31,12 +31,12 @@ * @version $Id: $Id * @since 3.4.0 */ -public class OsTest { +class OsTest { /** *

testUndefinedFamily.

*/ @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() { Iterator iter = Os.getValidFamilies().iterator(); String currentFamily = null; String notCurrentFamily = null; @@ -58,7 +58,7 @@ public void testOs() { } // make sure the OS_FAMILY is set right. - assertEquals(currentFamily, Os.OS_FAMILY); + assertEquals(Os.OS_FAMILY, currentFamily); // check the current family and one of the others assertTrue(Os.isOs(currentFamily, null, null, null)); @@ -85,8 +85,8 @@ public void testOs() { /** *

testValidList.

*/ - @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 { Map map = ReflectionUtils.getVariablesAndValuesIncludingSuperclasses(testClass); Map myMap = (Map) map.get("myMap"); - assertEquals("myValue", (String) myMap.get("myKey")); - assertEquals("myOtherValue", (String) myMap.get("myOtherKey")); + assertEquals("myValue", myMap.get("myKey")); + assertEquals("myOtherValue", myMap.get("myOtherKey")); } /** @@ -65,8 +65,8 @@ public void testComplexVariableAccess() throws IllegalAccessException { * @throws java.lang.IllegalAccessException if any. */ @Test - public void testSuperClassVariableAccess() throws IllegalAccessException { - assertEquals("super-duper", (String) ReflectionUtils.getValueIncludingSuperclasses("mySuperString", testClass)); + void superClassVariableAccess() throws IllegalAccessException { + assertEquals("super-duper", ReflectionUtils.getValueIncludingSuperclasses("mySuperString", testClass)); } /** @@ -75,15 +75,15 @@ public void testSuperClassVariableAccess() throws IllegalAccessException { * @throws java.lang.IllegalAccessException if any. */ @Test - public void testSettingVariableValue() throws IllegalAccessException { + void settingVariableValue() throws IllegalAccessException { ReflectionUtils.setVariableValueInObject(testClass, "mySettableString", "mySetString"); - assertEquals( - "mySetString", (String) ReflectionUtils.getValueIncludingSuperclasses("mySettableString", testClass)); + assertEquals("mySetString", ReflectionUtils.getValueIncludingSuperclasses("mySettableString", testClass)); ReflectionUtils.setVariableValueInObject(testClass, "myParentsSettableString", "myParentsSetString"); - assertEquals("myParentsSetString", (String) + assertEquals( + "myParentsSetString", ReflectionUtils.getValueIncludingSuperclasses("myParentsSettableString", testClass)); } @@ -93,7 +93,7 @@ private class ReflectionUtilsTestClass extends AbstractReflectionUtilsTestClass private String mySettableString; - private Map myMap = new HashMap(); + private Map myMap = new HashMap<>(); public ReflectionUtilsTestClass() { myMap.put("myKey", "myValue"); diff --git a/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java b/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java index 0cb98efe..1185d60d 100644 --- a/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java @@ -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 @@ -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 disposedObjects = new Vector(); + private final Vector disposedObjects = new Vector<>(); public TestObjectPool(int maxSize, int minSize, int intialCapacity, int sweepInterval, int triggerSize) { super(maxSize, minSize, intialCapacity, sweepInterval, triggerSize); diff --git a/src/test/java/org/codehaus/plexus/util/TestThreadManager.java b/src/test/java/org/codehaus/plexus/util/TestThreadManager.java index dda5b3b6..b9ee75b8 100644 --- a/src/test/java/org/codehaus/plexus/util/TestThreadManager.java +++ b/src/test/java/org/codehaus/plexus/util/TestThreadManager.java @@ -191,10 +191,9 @@ public final void registerThread(AbstractTestThread thread) { */ public void reset() { toRunThreads.clear(); - for (Object runThread : runThreads) { - AbstractTestThread test = (AbstractTestThread) runThread; - test.reset(); - registerThread(test); + for (AbstractTestThread runThread : runThreads) { + runThread.reset(); + registerThread(runThread); } runThreads.clear(); 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 fb6ddf3d..a63adfab 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java @@ -21,6 +21,7 @@ import java.util.Properties; import org.codehaus.plexus.util.Os; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -34,15 +35,15 @@ * @version $Id: $Id * @since 3.4.0 */ -@SuppressWarnings({"JavaDoc", "deprecation"}) -public class CommandLineUtilsTest { +@SuppressWarnings({"deprecation"}) +class CommandLineUtilsTest { /** *

testQuoteArguments.

*/ @Test - public void testQuoteArguments() { - try { + void quoteArguments() { + Assertions.assertDoesNotThrow(() -> { String result = CommandLineUtils.quote("Hello"); System.out.println(result); assertEquals("Hello", result); @@ -51,14 +52,12 @@ public void testQuoteArguments() { assertEquals("\"Hello World\"", result); result = CommandLineUtils.quote("\"Hello World\""); System.out.println(result); - assertEquals("\'\"Hello World\"\'", result); - } catch (Exception e) { - fail(e.getMessage()); - } + assertEquals("'\"Hello World\"'", result); + }); try { - CommandLineUtils.quote("\"Hello \'World\'\'"); + CommandLineUtils.quote("\"Hello 'World''"); fail(); - } catch (Exception e) { + } catch (Exception ignored) { } } @@ -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; } @@ -98,8 +97,8 @@ public void testGetSystemEnvVarsWindows() throws Exception { * * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testTranslateCommandline() throws Exception { + @Test + 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 6518c950..ac2ef781 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java @@ -41,7 +41,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class CommandlineTest { +class CommandlineTest { private String baseDir; /** @@ -50,7 +50,7 @@ public class CommandlineTest { * @throws java.lang.Exception if any. */ @BeforeEach - public void setUp() throws Exception { + 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); @@ -109,8 +109,8 @@ public void testExecuteBinaryOnPath() throws Exception { * * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testExecute() throws Exception { + @Test + 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,7 +176,7 @@ 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"}); @@ -199,7 +199,7 @@ 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"}); @@ -223,7 +223,7 @@ 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"}); @@ -236,7 +236,7 @@ public void testGetShellCommandLineBash() throws Exception { assertEquals("-c", shellCommandline[1]); String expectedShellCmd = "'/bin/echo' 'hello world'"; if (Os.isFamily(Os.FAMILY_WINDOWS)) { - expectedShellCmd = "'\\bin\\echo' \'hello world\'"; + expectedShellCmd = "'\\bin\\echo' 'hello world'"; } assertEquals(expectedShellCmd, shellCommandline[2]); } @@ -247,7 +247,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"}); @@ -274,10 +274,10 @@ 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\'"}); + cmd.addArguments(new String[] {"'hello world'"}); String[] shellCommandline = cmd.getShellCommandline(); @@ -298,7 +298,7 @@ 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"}); @@ -322,7 +322,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]); @@ -334,7 +334,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"); @@ -355,7 +355,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"); @@ -369,7 +369,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"); } @@ -380,7 +380,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; @@ -400,7 +400,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; @@ -419,8 +419,8 @@ public void testQuotedPathWithQuotationMarkAndApostrophe() throws Exception { * @throws java.lang.Exception */ @Test - public void testOnlyQuotedPath() throws Exception { - File dir = new File(System.getProperty("basedir"), "target/test/quotedpath\'test"); + void onlyQuotedPath() throws Exception { + File dir = new File(System.getProperty("basedir"), "target/test/quotedpath'test"); File javaHome = new File(System.getProperty("java.home")); File java; @@ -448,7 +448,7 @@ 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(dir.mkdirs(), "Can't create dir:" + dir.getAbsolutePath()); @@ -481,7 +481,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)) { @@ -588,8 +588,7 @@ private static void executeCommandLine(Commandline cmd) throws Exception { int exitCode = CommandLineUtils.executeCommandLine(cmd, new DefaultConsumer(), err); if (exitCode != 0) { - String msg = "Exit code: " + exitCode + " - " + err.getOutput(); - throw new Exception(msg.toString()); + throw new Exception("Exit code: " + exitCode + " - " + err.getOutput()); } } catch (CommandLineException e) { throw new Exception("Unable to execute command: " + e.getMessage(), e); 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 968b2d2e..fae942ef 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/DefaultConsumerTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/DefaultConsumerTest.java @@ -25,14 +25,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 dd95dd3b..4f7b6ddd 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizerTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizerTest.java @@ -29,12 +29,12 @@ * @version $Id: $Id * @since 3.4.0 */ -public class EnhancedStringTokenizerTest { +class EnhancedStringTokenizerTest { /** *

test1.

*/ - @org.junit.jupiter.api.Test - public void test1() { + @Test + void test1() { EnhancedStringTokenizer est = new EnhancedStringTokenizer("this is a test string"); StringBuilder sb = new StringBuilder(); while (est.hasMoreTokens()) { @@ -48,7 +48,7 @@ public void test1() { *

test2.

*/ @Test - public void test2() { + void test2() { EnhancedStringTokenizer est = new EnhancedStringTokenizer("1,,,3,,4", ","); assertEquals("1", est.nextToken(), "Token 1"); assertEquals("", est.nextToken(), "Token 2"); @@ -61,8 +61,8 @@ public void test2() { /** *

test3.

*/ - @org.junit.jupiter.api.Test - public void test3() { + @Test + void test3() { EnhancedStringTokenizer est = new EnhancedStringTokenizer("1,,,3,,4", ",", true); assertEquals("1", est.nextToken(), "Token 1"); assertEquals(",", est.nextToken(), "Token 2"); @@ -80,8 +80,8 @@ public void test3() { /** *

testMultipleDelim.

*/ - @org.junit.jupiter.api.Test - public void testMultipleDelim() { + @Test + void multipleDelim() { EnhancedStringTokenizer est = new EnhancedStringTokenizer("1 2|3|4", " |", true); assertEquals("1", est.nextToken(), "Token 1"); assertEquals(" ", est.nextToken(), "Token 2"); @@ -96,22 +96,22 @@ public void testMultipleDelim() { /** *

testEmptyString.

*/ - @org.junit.jupiter.api.Test - public void testEmptyString() { + @Test + void emptyString() { EnhancedStringTokenizer est = new EnhancedStringTokenizer(""); assertFalse(est.hasMoreTokens(), "est.hasMoreTokens()"); try { est.nextToken(); fail(); - } catch (Exception e) { + } catch (Exception ignored) { } } /** *

testSimpleString.

*/ - @org.junit.jupiter.api.Test - public void testSimpleString() { + @Test + void simpleString() { EnhancedStringTokenizer est = new EnhancedStringTokenizer("a "); assertEquals("a", est.nextToken(), "Token 1"); assertEquals("", est.nextToken(), "Token 2"); 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 94cde1ff..7cbba879 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java @@ -73,14 +73,14 @@ * @version $Id: $Id * @since 3.4.0 */ -public class StreamPumperTest { - private String lineSeparator = System.lineSeparator(); +class StreamPumperTest { + private final String lineSeparator = System.lineSeparator(); /** *

testPumping.

*/ @Test - public void testPumping() { + void pumping() { String line1 = "line1"; String line2 = "line2"; String lines = line1 + "\n" + line2; @@ -98,8 +98,8 @@ public void testPumping() { /** *

testPumpingWithPrintWriter.

*/ - @org.junit.jupiter.api.Test - public void testPumpingWithPrintWriter() { + @Test + void pumpingWithPrintWriter() { String inputString = "This a test string"; ByteArrayInputStream bais = new ByteArrayInputStream(inputString.getBytes()); StringWriter sw = new StringWriter(); @@ -107,7 +107,7 @@ public void testPumpingWithPrintWriter() { StreamPumper pumper = new StreamPumper(bais, pw); pumper.run(); pumper.flush(); - System.out.println("aaa" + sw.toString()); + System.out.println("aaa" + sw); assertEquals("This a test string" + lineSeparator, sw.toString()); pumper.close(); } @@ -116,7 +116,7 @@ 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()); @@ -164,7 +164,7 @@ public void consumeLine(String line) { */ static class TestConsumer implements StreamConsumer { - private List lines = new ArrayList(); + private final List lines = new ArrayList<>(); /** * Checks to see if this consumer consumed a particular line. This method will wait up to timeout number of @@ -208,8 +208,8 @@ public void consumeLine(String line) { /** *

testEnabled.

*/ - @org.junit.jupiter.api.Test - public void testEnabled() { + @Test + 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 c00d6471..6c2e3a8e 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 @@ -33,7 +33,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class BourneShellTest { +class BourneShellTest { /** *

newShell.

@@ -47,8 +47,8 @@ protected Shell newShell() { /** *

testQuoteWorkingDirectoryAndExecutable.

*/ - @org.junit.jupiter.api.Test - public void testQuoteWorkingDirectoryAndExecutable() { + @Test + 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'"); @@ -79,8 +79,8 @@ public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes() { /** *

testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes_BackslashFileSep.

*/ - @org.junit.jupiter.api.Test - public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes_BackslashFileSep() { + @Test + void quoteWorkingDirectoryAndExecutableWDPathWithSingleQuotesBackslashFileSep() { Shell sh = newShell(); sh.setWorkingDirectory("\\usr\\local\\'something else'"); @@ -89,20 +89,20 @@ public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes_Backsl String executable = StringUtils.join(sh.getShellCommandLine(new String[] {}).iterator(), " "); - assertEquals("/bin/sh -c cd '\\usr\\local\\\'\"'\"'something else'\"'\"'' && 'chmod'", executable); + assertEquals("/bin/sh -c cd '\\usr\\local\\'\"'\"'something else'\"'\"'' && 'chmod'", executable); } /** *

testPreserveSingleQuotesOnArgument.

*/ @Test - public void testPreserveSingleQuotesOnArgument() { + void preserveSingleQuotesOnArgument() { Shell sh = newShell(); sh.setWorkingDirectory("/usr/bin"); sh.setExecutable("chmod"); - String[] args = {"\'some arg with spaces\'"}; + String[] args = {"'some arg with spaces'"}; List shellCommandLine = sh.getShellCommandLine(args); @@ -115,7 +115,7 @@ public void testPreserveSingleQuotesOnArgument() { *

testAddSingleQuotesOnArgumentWithSpaces.

*/ @Test - public void testAddSingleQuotesOnArgumentWithSpaces() { + void addSingleQuotesOnArgumentWithSpaces() { Shell sh = newShell(); sh.setWorkingDirectory("/usr/bin"); @@ -127,14 +127,14 @@ public void testAddSingleQuotesOnArgumentWithSpaces() { String cli = StringUtils.join(shellCommandLine.iterator(), " "); System.out.println(cli); - assertTrue(cli.endsWith("\'" + args[0] + "\'")); + assertTrue(cli.endsWith("'" + args[0] + "'")); } /** *

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 ----"); @@ -169,7 +169,7 @@ public void testArgumentsWithsemicolon() { String cli = StringUtils.join(shellCommandLine.iterator(), " "); System.out.println(cli); - assertTrue(cli.endsWith("\'" + args[0] + "\'")); + assertTrue(cli.endsWith("'" + args[0] + "'")); Commandline commandline = new Commandline(newShell()); commandline.setExecutable("chmod"); @@ -216,7 +216,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 dac7e57c..97ddfcec 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java @@ -30,13 +30,13 @@ * @version $Id: $Id * @since 3.4.0 */ -public class CycleDetectedExceptionTest { +class CycleDetectedExceptionTest { /** *

testException.

*/ @Test - public void testException() { - final List cycle = new ArrayList(); + void exception() { + final List cycle = new ArrayList<>(); cycle.add("a"); diff --git a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java index 0d088193..e900ca83 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java @@ -18,6 +18,7 @@ import java.util.List; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -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 @@ -90,20 +89,19 @@ public void testCycyleDetection() { // a --> b // | | --> d // ---------> - try { - final DAG dag3 = new DAG(); - - dag3.addEdge("a", "b"); + Assertions.assertDoesNotThrow( + () -> { + final DAG dag3 = new DAG(); - dag3.addEdge("b", "c"); + dag3.addEdge("a", "b"); - dag3.addEdge("b", "d"); + dag3.addEdge("b", "c"); - dag3.addEdge("a", "d"); + dag3.addEdge("b", "d"); - } catch (CycleDetectedException e) { - fail("Cycle should not be detected"); - } + dag3.addEdge("a", "d"); + }, + "Cycle should not be detected"); // ------------ // | | @@ -131,13 +129,13 @@ public void testCycyleDetection() { assertNotNull(cycle, "Cycle should be not null"); - assertEquals("a", (String) cycle.get(0), "Cycle contains 'a'"); + assertEquals("a", cycle.get(0), "Cycle contains 'a'"); assertEquals("b", cycle.get(1), "Cycle contains 'b'"); assertEquals("c", cycle.get(2), "Cycle contains 'c'"); - assertEquals("a", (String) cycle.get(3), "Cycle contains 'a'"); + assertEquals("a", cycle.get(3), "Cycle contains 'a'"); } // f --> g --> h @@ -177,15 +175,15 @@ public void testCycyleDetection() { assertEquals(5, cycle.size(), "Cycle contains 5 elements"); - assertEquals("b", (String) cycle.get(0), "Cycle contains 'b'"); + assertEquals("b", cycle.get(0), "Cycle contains 'b'"); assertEquals("c", cycle.get(1), "Cycle contains 'c'"); assertEquals("d", cycle.get(2), "Cycle contains 'd'"); - assertEquals("e", (String) cycle.get(3), "Cycle contains 'e'"); + assertEquals("e", cycle.get(3), "Cycle contains 'e'"); - assertEquals("b", (String) cycle.get(4), "Cycle contains 'b'"); + assertEquals("b", cycle.get(4), "Cycle contains 'b'"); assertTrue(dag5.hasEdge("a", "b"), "Edge exists"); diff --git a/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java b/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java index 7c12d9dc..7f0cf922 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java @@ -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 321fe1c6..02bd14cd 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java @@ -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 @@ -47,7 +47,7 @@ public void testDfs() throws CycleDetectedException { dag1.addEdge("b", "c"); - final List expected1 = new ArrayList(); + final List expected1 = new ArrayList<>(); expected1.add("c"); @@ -75,7 +75,7 @@ public void testDfs() throws CycleDetectedException { dag2.addEdge("c", "b"); - final List expected2 = new ArrayList(); + final List expected2 = new ArrayList<>(); expected2.add("a"); @@ -124,7 +124,7 @@ public void testDfs() throws CycleDetectedException { dag3.addEdge("f", "g"); - final List expected3 = new ArrayList(); + final List expected3 = new ArrayList<>(); expected3.add("d"); @@ -179,7 +179,7 @@ public void testDfs() throws CycleDetectedException { dag4.addEdge("e", "f"); - final List expected4 = new ArrayList(); + final List expected4 = new ArrayList<>(); expected4.add("d"); diff --git a/src/test/java/org/codehaus/plexus/util/dag/VertexTest.java b/src/test/java/org/codehaus/plexus/util/dag/VertexTest.java index 3274a11f..9263d46e 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/VertexTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/VertexTest.java @@ -27,12 +27,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 0967b496..69aa1d5c 100644 --- a/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java +++ b/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java @@ -27,7 +27,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; /** *

ReflectionValueExtractorTest class.

@@ -36,7 +35,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class ReflectionValueExtractorTest { +class ReflectionValueExtractorTest { private Project project; /** @@ -45,7 +44,7 @@ public class ReflectionValueExtractorTest { * @throws java.lang.Exception if any. */ @BeforeEach - public void setUp() throws Exception { + 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)); @@ -171,9 +170,9 @@ public void testValueExtractorWithAInvalidExpression() throws Exception { * * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testMappedDottedKey() throws Exception { - Map map = new HashMap(); + @Test + void mappedDottedKey() throws Exception { + Map map = new HashMap<>(); map.put("a.b", "a.b-value"); assertEquals("a.b-value", ReflectionValueExtractor.evaluate("h.value(a.b)", new ValueHolder(map))); @@ -185,10 +184,10 @@ public void testMappedDottedKey() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testIndexedMapped() throws Exception { - Map map = new HashMap(); + void indexedMapped() throws Exception { + Map map = new HashMap<>(); map.put("a", "a-value"); - List list = new ArrayList(); + List list = new ArrayList<>(); list.add(map); assertEquals("a-value", ReflectionValueExtractor.evaluate("h.value[0](a)", new ValueHolder(list))); @@ -200,10 +199,10 @@ public void testIndexedMapped() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testMappedIndexed() throws Exception { - List list = new ArrayList(); + void mappedIndexed() throws Exception { + List list = new ArrayList<>(); list.add("a-value"); - Map map = new HashMap(); + Map map = new HashMap<>(); map.put("a", list); assertEquals("a-value", ReflectionValueExtractor.evaluate("h.value(a)[0]", new ValueHolder(map))); } @@ -213,9 +212,9 @@ public void testMappedIndexed() throws Exception { * * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testMappedMissingDot() throws Exception { - Map map = new HashMap(); + @Test + void mappedMissingDot() throws Exception { + Map map = new HashMap<>(); map.put("a", new ValueHolder("a-value")); assertNull(ReflectionValueExtractor.evaluate("h.value(a)value", new ValueHolder(map))); } @@ -226,8 +225,8 @@ public void testMappedMissingDot() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testIndexedMissingDot() throws Exception { - List list = new ArrayList(); + void indexedMissingDot() throws Exception { + List list = new ArrayList<>(); list.add(new ValueHolder("a-value")); assertNull(ReflectionValueExtractor.evaluate("h.value[0]value", new ValueHolder(list))); } @@ -238,7 +237,7 @@ public void testIndexedMissingDot() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testDotDot() throws Exception { + void dotDot() throws Exception { assertNull(ReflectionValueExtractor.evaluate("h..value", new ValueHolder("value"))); } @@ -248,8 +247,8 @@ public void testDotDot() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testBadIndexedSyntax() throws Exception { - List list = new ArrayList(); + void badIndexedSyntax() throws Exception { + List list = new ArrayList<>(); list.add("a-value"); Object value = new ValueHolder(list); @@ -266,9 +265,9 @@ public void testBadIndexedSyntax() throws Exception { * * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testBadMappedSyntax() throws Exception { - Map map = new HashMap(); + @Test + void badMappedSyntax() throws Exception { + Map map = new HashMap<>(); map.put("a", "a-value"); Object value = new ValueHolder(map); @@ -283,8 +282,8 @@ public void testBadMappedSyntax() throws Exception { * * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testIllegalIndexedType() throws Exception { + @Test + void illegalIndexedType() throws Exception { try { ReflectionValueExtractor.evaluate("h.value[1]", new ValueHolder("string")); } catch (Exception e) { @@ -298,7 +297,7 @@ public void testIllegalIndexedType() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testIllegalMappedType() throws Exception { + void illegalMappedType() throws Exception { try { ReflectionValueExtractor.evaluate("h.value(key)", new ValueHolder("string")); } catch (Exception e) { @@ -312,7 +311,7 @@ public void testIllegalMappedType() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testTrimRootToken() throws Exception { + void trimRootToken() throws Exception { assertNull(ReflectionValueExtractor.evaluate("project", project, true)); } @@ -322,7 +321,7 @@ public void testTrimRootToken() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testArtifactMap() throws Exception { + void artifactMap() throws Exception { assertEquals( "g0", ((Artifact) ReflectionValueExtractor.evaluate("project.artifactMap(g0:a0:c0)", project)).getGroupId()); @@ -403,7 +402,7 @@ public static class Project { private Scm scm; - private List dependencies = new ArrayList(); + private final List dependencies = new ArrayList<>(); private Build build; @@ -413,7 +412,7 @@ public static class Project { private String version; - private Map artifactMap = new HashMap(); + private final Map artifactMap = new HashMap<>(); private String description; public void setModelVersion(String modelVersion) { @@ -460,7 +459,7 @@ public String getGroupId() { return groupId; } - public List getDependencies() { + public List getDependencies() { return dependencies; } @@ -481,14 +480,13 @@ public String getVersion() { } public Dependency[] getDependenciesAsArray() { - return (Dependency[]) getDependencies().toArray(new Dependency[0]); + return getDependencies().toArray(new Dependency[0]); } - public Map getDependenciesAsMap() { - Map ret = new HashMap(); - for (Object o : getDependencies()) { - Dependency dep = (Dependency) o; - ret.put(dep.getArtifactId(), dep); + public Map getDependenciesAsMap() { + Map ret = new HashMap<>(); + for (Dependency d : getDependencies()) { + ret.put(d.getArtifactId(), d); } return ret; } @@ -555,7 +553,7 @@ public Object getValue() { * @throws java.lang.Exception if any. */ @Test - public void testRootPropertyRegression() throws Exception { + void rootPropertyRegression() throws Exception { Project project = new Project(); project.setDescription("c:\\\\org\\apache\\test"); Object evalued = ReflectionValueExtractor.evaluate("description", project); diff --git a/src/test/java/org/codehaus/plexus/util/io/CachingOutputStreamTest.java b/src/test/java/org/codehaus/plexus/util/io/CachingOutputStreamTest.java index d0959593..11da4e05 100644 --- a/src/test/java/org/codehaus/plexus/util/io/CachingOutputStreamTest.java +++ b/src/test/java/org/codehaus/plexus/util/io/CachingOutputStreamTest.java @@ -33,13 +33,13 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -public class CachingOutputStreamTest { +class CachingOutputStreamTest { Path tempDir; Path checkLastModified; @BeforeEach - public void setup() throws IOException { + void setup() throws IOException { Path dir = Paths.get("target/io"); Files.createDirectories(dir); tempDir = Files.createTempDirectory(dir, "temp-"); @@ -60,7 +60,7 @@ private void waitLastModified() throws IOException, InterruptedException { } @Test - public void testWriteNoExistingFile() throws IOException, InterruptedException { + void writeNoExistingFile() throws IOException, InterruptedException { byte[] data = "Hello world!".getBytes(StandardCharsets.UTF_8); Path path = tempDir.resolve("file.txt"); assertFalse(Files.exists(path)); diff --git a/src/test/java/org/codehaus/plexus/util/io/CachingWriterTest.java b/src/test/java/org/codehaus/plexus/util/io/CachingWriterTest.java index f94e90b0..5172547b 100644 --- a/src/test/java/org/codehaus/plexus/util/io/CachingWriterTest.java +++ b/src/test/java/org/codehaus/plexus/util/io/CachingWriterTest.java @@ -33,13 +33,13 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -public class CachingWriterTest { +class CachingWriterTest { Path tempDir; Path checkLastModified; @BeforeEach - public void setup() throws IOException { + void setup() throws IOException { Path dir = Paths.get("target/io"); Files.createDirectories(dir); tempDir = Files.createTempDirectory(dir, "temp-"); @@ -60,7 +60,7 @@ private void waitLastModified() throws IOException, InterruptedException { } @Test - public void testNoOverwriteWithFlush() throws IOException, InterruptedException { + void noOverwriteWithFlush() throws IOException, InterruptedException { String data = "Hello world!"; Path path = tempDir.resolve("file-bigger.txt"); assertFalse(Files.exists(path)); @@ -85,7 +85,7 @@ public void testNoOverwriteWithFlush() throws IOException, InterruptedException } @Test - public void testWriteNoExistingFile() throws IOException, InterruptedException { + void writeNoExistingFile() throws IOException, InterruptedException { String data = "Hello world!"; Path path = tempDir.resolve("file.txt"); assertFalse(Files.exists(path)); diff --git a/src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java b/src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java index f860d36b..932254f6 100644 --- a/src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java +++ b/src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java @@ -28,7 +28,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class ReflectorTest { +class ReflectorTest { private Project project; private Reflector reflector; @@ -39,7 +39,7 @@ public class ReflectorTest { * @throws java.lang.Exception if any. */ @BeforeEach - public void setUp() throws Exception { + void setUp() throws Exception { project = new Project(); project.setModelVersion("1.0.0"); project.setVersion("42"); @@ -53,7 +53,7 @@ public void setUp() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testObjectPropertyFromName() throws Exception { + void objectPropertyFromName() throws Exception { assertEquals("1.0.0", reflector.getObjectProperty(project, "modelVersion")); } @@ -62,8 +62,8 @@ public void testObjectPropertyFromName() throws Exception { * * @throws java.lang.Exception if any. */ - @org.junit.jupiter.api.Test - public void testObjectPropertyFromBean() throws Exception { + @Test + void objectPropertyFromBean() throws Exception { assertEquals("Foo", reflector.getObjectProperty(project, "name")); } @@ -73,7 +73,7 @@ public void testObjectPropertyFromBean() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testObjectPropertyFromField() throws Exception { + void objectPropertyFromField() throws Exception { assertEquals("42", reflector.getObjectProperty(project, "version")); }