diff --git a/src/main/java/org/codehaus/plexus/util/Base64.java b/src/main/java/org/codehaus/plexus/util/Base64.java index e574a287..97a4fd90 100644 --- a/src/main/java/org/codehaus/plexus/util/Base64.java +++ b/src/main/java/org/codehaus/plexus/util/Base64.java @@ -28,6 +28,7 @@ * @since 1.0-dev * */ +@Deprecated public class Base64 { // @@ -283,9 +284,6 @@ public static byte[] encodeBase64(byte[] binaryData, boolean isChunked) { byte val3 = ((b3 & SIGN) == 0) ? (byte) (b3 >> 6) : (byte) ((b3) >> 6 ^ 0xfc); encodedData[encodedIndex] = lookUpBase64Alphabet[val1]; - // log.debug( "val2 = " + val2 ); - // log.debug( "k4 = " + (k<<4) ); - // log.debug( "vak = " + (val2 | (k<<4)) ); encodedData[encodedIndex + 1] = lookUpBase64Alphabet[val2 | (k << 4)]; encodedData[encodedIndex + 2] = lookUpBase64Alphabet[(l << 2) | val3]; encodedData[encodedIndex + 3] = lookUpBase64Alphabet[b3 & 0x3f]; @@ -310,8 +308,6 @@ public static byte[] encodeBase64(byte[] binaryData, boolean isChunked) { if (fewerThan24bits == EIGHTBIT) { b1 = binaryData[dataIndex]; k = (byte) (b1 & 0x03); - // log.debug("b1=" + b1); - // log.debug("b1<<2 = " + (b1>>2) ); byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0); encodedData[encodedIndex] = lookUpBase64Alphabet[val1]; encodedData[encodedIndex + 1] = lookUpBase64Alphabet[k << 4]; diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java index fceb191e..b411272a 100644 --- a/src/main/java/org/codehaus/plexus/util/FileUtils.java +++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java @@ -1921,7 +1921,9 @@ public static void copyFile(File from, File to, String encoding, FilterWrapper[] fileReader.close(); fileReader = null; } finally { + //noinspection deprecation IOUtil.close(fileReader); + //noinspection deprecation IOUtil.close(fileWriter); } } else { diff --git a/src/main/java/org/codehaus/plexus/util/NioFiles.java b/src/main/java/org/codehaus/plexus/util/NioFiles.java index d7a00a78..b0365c61 100644 --- a/src/main/java/org/codehaus/plexus/util/NioFiles.java +++ b/src/main/java/org/codehaus/plexus/util/NioFiles.java @@ -30,7 +30,6 @@ /** * Encapsulates use of java7 features, exposing mostly backward compatible types */ -@SuppressWarnings("Since15") public class NioFiles { public static boolean isSymbolicLink(File file) { return Files.isSymbolicLink(file.toPath()); diff --git a/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java b/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java index 81b053b9..b2ac489e 100644 --- a/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java +++ b/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java @@ -423,7 +423,7 @@ public static String[] translateCommandline(String toProcess) throws Exception { * {@link StringUtils#quoteAndEscape(String, char)} instead. */ @Deprecated - @SuppressWarnings({"JavaDoc", "deprecation"}) + @SuppressWarnings({"JavaDoc"}) public static String quote(String argument) throws CommandLineException { return quote(argument, false, false, true); } @@ -445,7 +445,7 @@ public static String quote(String argument) throws CommandLineException { * {@link StringUtils#quoteAndEscape(String, char)} instead. */ @Deprecated - @SuppressWarnings({"JavaDoc", "UnusedDeclaration", "deprecation"}) + @SuppressWarnings({"JavaDoc", "UnusedDeclaration"}) public static String quote(String argument, boolean wrapExistingQuotes) throws CommandLineException { return quote(argument, false, false, wrapExistingQuotes); } diff --git a/src/test/java/org/codehaus/plexus/util/AbstractTestThread.java b/src/test/java/org/codehaus/plexus/util/AbstractTestThread.java index 1a67c001..112f5b79 100644 --- a/src/test/java/org/codehaus/plexus/util/AbstractTestThread.java +++ b/src/test/java/org/codehaus/plexus/util/AbstractTestThread.java @@ -24,14 +24,12 @@ *
* * @author Bert van Brakel - * @version $Id: $Id * @since 3.4.0 */ public abstract class AbstractTestThread implements Runnable { - // ~ Instance fields ---------------------------------------------------------------------------- + private String name; - /** ConstantDEBUG=true */
public static final boolean DEBUG = true;
private boolean isRunning = false;
@@ -56,8 +54,6 @@ public abstract class AbstractTestThread implements Runnable {
*/
private boolean passed = false;
- // ~ Constructors -------------------------------------------------------------------------------
-
/**
* Constructor
* @@ -77,13 +73,6 @@ public AbstractTestThread(TestThreadManager registry) { setThreadRegistry(registry); } - // ~ Methods ------------------------------------------------------------------------------------ - - /** - *
Getter for the field error.
Getter for the field errorMsg.
hasFailed.
- * - * @return a boolean. - */ public boolean hasFailed() { return !passed; } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ public boolean hasPassed() { return passed; } @@ -177,11 +150,6 @@ public final void run() { } } - /** - * Override this to run your custom test - * - * @throws java.lang.Throwable - */ public abstract void doRun() throws Throwable; /** @@ -190,7 +158,6 @@ public final void run() { * @param registry a {@link org.codehaus.plexus.util.TestThreadManager} object. */ public void setThreadRegistry(TestThreadManager registry) { - this.registry = registry; } @@ -203,52 +170,27 @@ public boolean hasRun() { return hasRun; } - /** - *Setter for the field error.
Setter for the field errorMsg.
Setter for the field passed.
Getter for the field name.
Setter for the field name.
CollectionUtilsTest class.
* * @author herve - * @version $Id: $Id * @since 3.4.0 */ class CollectionUtilsTest { - /** - *testMergeMaps.
- */ + @Test void mergeMaps() { MaptestMergeMapArray.
- */ @SuppressWarnings("unchecked") @Test void mergeMapArray() { @@ -129,9 +123,6 @@ void mergeMapArray() { assertEquals("ccc", result5.get("c")); } - /** - *testMavenPropertiesLoading.
- */ @Test void mavenPropertiesLoading() { // Mimic MavenSession properties loading. Properties listed @@ -189,9 +180,6 @@ void mavenPropertiesLoading() { assertEquals(mavenRepoRemote, result.get("maven.repo.remote")); } - /** - *testIteratorToListWithAPopulatedList.
- */ @Test void iteratorToListWithAPopulatedList() { ListtestIteratorToListWithAEmptyList.
- */ @Test void iteratorToListWithAEmptyList() { ListsetUp.
- */ @BeforeEach void setUp() { try { @@ -60,14 +56,8 @@ void setUp() { } } - /** - *testCrossPlatformIncludesString.
- * - * @throws java.io.IOException if any. - * @throws java.net.URISyntaxException if any. - */ @Test - void crossPlatformIncludesString() throws IOException, URISyntaxException { + void crossPlatformIncludesString() throws Exception { DirectoryScanner ds = new DirectoryScanner(); ds.setBasedir(new File(getTestResourcesDir() + File.separator + "directory-scanner").getCanonicalFile()); @@ -86,14 +76,8 @@ void crossPlatformIncludesString() throws IOException, URISyntaxException { assertEquals(1, files.length); } - /** - *testCrossPlatformExcludesString.
- * - * @throws java.io.IOException if any. - * @throws java.net.URISyntaxException if any. - */ @Test - void crossPlatformExcludesString() throws IOException, URISyntaxException { + void crossPlatformExcludesString() throws Exception { DirectoryScanner ds = new DirectoryScanner(); ds.setBasedir(new File(getTestResourcesDir() + File.separator + "directory-scanner").getCanonicalFile()); ds.setIncludes(new String[] {"**"}); @@ -167,13 +151,8 @@ private boolean checkTestFilesSymlinks() { } } - /** - *testGeneral.
- * - * @throws java.io.IOException if any. - */ @Test - void general() throws IOException { + void general() throws Exception { this.createTestFiles(); String includes = "scanner1.dat,scanner2.dat,scanner3.dat,scanner4.dat,scanner5.dat"; @@ -187,13 +166,8 @@ void general() throws IOException { assertTrue(fileNames.contains(new File("scanner5.dat")), "5 not found."); } - /** - *testIncludesExcludesWithWhiteSpaces.
- * - * @throws java.io.IOException if any. - */ @Test - void includesExcludesWithWhiteSpaces() throws IOException { + void includesExcludesWithWhiteSpaces() throws Exception { this.createTestFiles(); String includes = "scanner1.dat,\n \n,scanner2.dat \n\r, scanner3.dat\n, \tscanner4.dat,scanner5.dat\n,"; @@ -208,9 +182,6 @@ void includesExcludesWithWhiteSpaces() throws IOException { assertTrue(fileNames.contains(new File("scanner5.dat")), "5 not found."); } - /** - *testFollowSymlinksFalse.
- */ @Test void followSymlinksFalse() { assumeTrue(checkTestFilesSymlinks()); @@ -243,9 +214,6 @@ private void assertAlwaysIncluded(ListtestFollowSymlinks.
- */ @Test void followSymlinks() { assumeTrue(checkTestFilesSymlinks()); @@ -288,13 +256,8 @@ private void createTestDirectories() throws IOException { 0); } - /** - *testDirectoriesWithHyphens.
- * - * @throws java.io.IOException if any. - */ @Test - void directoriesWithHyphens() throws IOException { + void directoriesWithHyphens() throws Exception { this.createTestDirectories(); DirectoryScanner ds = new DirectoryScanner(); @@ -310,13 +273,8 @@ void directoriesWithHyphens() throws IOException { assertEquals(3, files.length, "Wrong number of results."); } - /** - *testAntExcludesOverrideIncludes.
- * - * @throws java.io.IOException if any. - */ @Test - void antExcludesOverrideIncludes() throws IOException { + void antExcludesOverrideIncludes() throws Exception { printTestHeader(); File dir = new File(testDir, "regex-dir"); @@ -348,13 +306,8 @@ void antExcludesOverrideIncludes() throws IOException { assertInclusionsAndExclusions(ds.getIncludedFiles(), excludedPaths, includedPaths); } - /** - *testAntExcludesOverrideIncludesWithExplicitAntPrefix.
- * - * @throws java.io.IOException if any. - */ @Test - void antExcludesOverrideIncludesWithExplicitAntPrefix() throws IOException { + void antExcludesOverrideIncludesWithExplicitAntPrefix() throws Exception { printTestHeader(); File dir = new File(testDir, "regex-dir"); @@ -387,13 +340,8 @@ void antExcludesOverrideIncludesWithExplicitAntPrefix() throws IOException { assertInclusionsAndExclusions(ds.getIncludedFiles(), excludedPaths, includedPaths); } - /** - *testRegexIncludeWithExcludedPrefixDirs.
- * - * @throws java.io.IOException if any. - */ @Test - void regexIncludeWithExcludedPrefixDirs() throws IOException { + void regexIncludeWithExcludedPrefixDirs() throws Exception { printTestHeader(); File dir = new File(testDir, "regex-dir"); @@ -421,13 +369,8 @@ void regexIncludeWithExcludedPrefixDirs() throws IOException { assertInclusionsAndExclusions(ds.getIncludedFiles(), excludedPaths, includedPaths); } - /** - *testRegexExcludeWithNegativeLookahead.
- * - * @throws java.io.IOException if any. - */ @Test - void regexExcludeWithNegativeLookahead() throws IOException { + void regexExcludeWithNegativeLookahead() throws Exception { printTestHeader(); File dir = new File(testDir, "regex-dir"); @@ -460,13 +403,8 @@ void regexExcludeWithNegativeLookahead() throws IOException { assertInclusionsAndExclusions(ds.getIncludedFiles(), excludedPaths, includedPaths); } - /** - *testRegexWithSlashInsideCharacterClass.
- * - * @throws java.io.IOException if any. - */ @Test - void regexWithSlashInsideCharacterClass() throws IOException { + void regexWithSlashInsideCharacterClass() throws Exception { printTestHeader(); File dir = new File(testDir, "regex-dir"); @@ -507,7 +445,7 @@ void regexWithSlashInsideCharacterClass() throws IOException { * @throws java.io.IOException if occurs an I/O error. */ @Test - void doNotScanUnnecesaryDirectories() throws IOException { + void doNotScanUnnecesaryDirectories() throws Exception { createTestDirectories(); // create additional directories 'anotherDir1', 'anotherDir2' and 'anotherDir3' with a 'file1.dat' file @@ -570,13 +508,8 @@ protected void scandir(File dir, String vpath, boolean fast) { assertEquals(expectedScannedDirSet, scannedDirSet); } - /** - *testIsSymbolicLink.
- * - * @throws java.io.IOException if any. - */ @Test - void isSymbolicLink() throws IOException { + void isSymbolicLink() throws Exception { assumeTrue(checkTestFilesSymlinks()); final File directory = new File("src/test/resources/symlinks/src"); @@ -587,13 +520,8 @@ void isSymbolicLink() throws IOException { assertFalse(ds.isSymbolicLink(directory, "aRegularDir")); } - /** - *testIsParentSymbolicLink.
- * - * @throws java.io.IOException if any. - */ @Test - void isParentSymbolicLink() throws IOException { + void isParentSymbolicLink() throws Exception { assumeTrue(checkTestFilesSymlinks()); final File directory = new File("src/test/resources/symlinks/src"); diff --git a/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java b/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java index f35062d7..ef629502 100644 --- a/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java +++ b/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java @@ -28,13 +28,10 @@ *DirectoryWalkerTest class.
* * @author herve - * @version $Id: $Id * @since 3.4.0 */ class DirectoryWalkerTest { - /** - *testDirectoryWalk.
- */ + @Test void directoryWalk() { DirectoryWalker walker = new DirectoryWalker(); diff --git a/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java b/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java index c808adfc..716ee688 100644 --- a/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java +++ b/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java @@ -21,9 +21,6 @@ import java.io.File; import java.io.IOException; import java.io.OutputStream; -import java.io.PrintStream; -import java.io.PrintWriter; -import java.io.Writer; import java.lang.reflect.Method; import java.nio.file.Files; @@ -32,13 +29,11 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; /** * Base class for testcases doing tests with files. * * @author Jeremias Maerki - * @version $Id: $Id * @since 3.4.0 */ public abstract class FileBasedTestCase { @@ -46,11 +41,6 @@ public abstract class FileBasedTestCase { private TestInfo testInfo; - /** - *getTestDirectory.
- * - * @return a {@link java.io.File} object. - */ public static File getTestDirectory() { if (testDir == null) { testDir = (new File("target/test/io/")).getAbsoluteFile(); @@ -63,10 +53,9 @@ public static File getTestDirectory() { * * @param file a {@link java.io.File} object. * @param size a long. - * @return an array of {@link byte} objects. * @throws java.io.IOException if any. */ - protected byte[] createFile(final File file, final long size) throws IOException { + protected void createFile(final File file, final long size) throws IOException { if (!file.getParentFile().exists()) { throw new IOException("Cannot create file " + file + " as the parent directory does not exist"); } @@ -74,38 +63,25 @@ protected byte[] createFile(final File file, final long size) throws IOException byte[] data = generateTestData(size); try (BufferedOutputStream output = new BufferedOutputStream(Files.newOutputStream(file.toPath()))) { output.write(data); - return data; } } /** *createSymlink.
* - * @param link a {@link java.io.File} object. + * @param link a {@link java.io.File} object. * @param target a {@link java.io.File} object. - * @return a boolean. */ - protected boolean createSymlink(final File link, final File target) { + protected void createSymlink(final File link, final File target) { try { String[] args = {"ln", "-s", target.getAbsolutePath(), link.getAbsolutePath()}; Process process = Runtime.getRuntime().exec(args); process.waitFor(); - if (0 != process.exitValue()) { - return false; - } } catch (Exception e) { // assume platform does not support "ln" command, tests should be skipped - return false; } - return true; } - /** - *generateTestData.
- * - * @param size a long. - * @return an array of {@link byte} objects. - */ protected byte[] generateTestData(final long size) { try { ByteArrayOutputStream baout = new ByteArrayOutputStream(); @@ -116,13 +92,6 @@ protected byte[] generateTestData(final long size) { } } - /** - *generateTestData.
- * - * @param out a {@link java.io.OutputStream} object. - * @param size a long. - * @throws java.io.IOException if any. - */ protected void generateTestData(final OutputStream out, final long size) throws IOException { for (int i = 0; i < size; i++) { // output.write((byte)'X'); @@ -132,80 +101,11 @@ protected void generateTestData(final OutputStream out, final long size) throws } } - /** - *newFile.
- * - * @param filename a {@link java.lang.String} object. - * @return a {@link java.io.File} object. - * @throws java.io.IOException if any. - */ - protected File newFile(String filename) throws IOException { - final File destination = new File(getTestDirectory(), filename); - /* - * assertTrue( filename + "Test output data file shouldn't previously exist", !destination.exists() ); - */ - if (destination.exists()) { - FileUtils.forceDelete(destination); - } - return destination; - } - - /** - *checkFile.
- * - * @param file a {@link java.io.File} object. - * @param referenceFile a {@link java.io.File} object. - * @throws java.lang.Exception if any. - */ protected void checkFile(final File file, final File referenceFile) throws Exception { assertTrue(file.exists(), "Check existence of output file"); assertEqualContent(referenceFile, file); } - /** - *checkWrite.
- * - * @param output a {@link java.io.OutputStream} object. - * @throws java.lang.Exception if any. - */ - protected void checkWrite(final OutputStream output) throws Exception { - try { - new PrintStream(output).write(0); - } catch (final Throwable t) { - fail("The copy() method closed the stream " + "when it shouldn't have. " + t.getMessage()); - } - } - - /** - *checkWrite.
- * - * @param output a {@link java.io.Writer} object. - * @throws java.lang.Exception if any. - */ - protected void checkWrite(final Writer output) throws Exception { - try { - new PrintWriter(output).write('a'); - } catch (final Throwable t) { - fail("The copy() method closed the stream " + "when it shouldn't have. " + t.getMessage()); - } - } - - /** - *deleteFile.
- * - * @param file a {@link java.io.File} object. - * @throws java.lang.Exception if any. - */ - protected void deleteFile(final File file) throws Exception { - if (file.exists()) { - assertTrue(file.delete(), "Couldn't delete file: " + file); - } - } - - // ---------------------------------------------------------------------- - // Assertions - // ---------------------------------------------------------------------- - /** Assert that the content of two files is the same. */ private void assertEqualContent(final File f0, final File f1) throws IOException { /* @@ -230,28 +130,12 @@ protected void assertEqualContent(final byte[] b0, final File file) throws IOExc assertArrayEquals(b0, b1, "Content differs"); } - /** - *assertIsDirectory.
- * - * @param file a {@link java.io.File} object. - */ protected void assertIsDirectory(File file) { assertTrue(file.exists(), "The File doesn't exists: " + file.getAbsolutePath()); assertTrue(file.isDirectory(), "The File isn't a directory: " + file.getAbsolutePath()); } - /** - *assertIsFile.
- * - * @param file a {@link java.io.File} object. - */ - protected void assertIsFile(File file) { - assertTrue(file.exists(), "The File doesn't exists: " + file.getAbsolutePath()); - - assertTrue(file.isFile(), "The File isn't a file: " + file.getAbsolutePath()); - } - @BeforeEach void init(TestInfo testInfo) { this.testInfo = testInfo; diff --git a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java index 97420a92..5bdaf97c 100644 --- a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java @@ -32,14 +32,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledOnOs; +import org.junit.jupiter.api.condition.OS; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.*; /** * This is used to test FileUtils for correctness. @@ -47,7 +43,6 @@ * @author Peter Donald * @author Matthew Hawthorne * @see FileUtils - * @version $Id: $Id * @since 3.4.0 */ public final class FileUtilsTest extends FileBasedTestCase { @@ -66,12 +61,7 @@ public final class FileUtilsTest extends FileBasedTestCase { private static int testFile2Size; - /** - *Constructor for FileUtilsTest.
- * - * @throws java.lang.Exception if any. - */ - public FileUtilsTest() throws Exception { + public FileUtilsTest() { testFile1 = new File(getTestDirectory(), "file1-test.txt"); testFile2 = new File(getTestDirectory(), "file1a-test.txt"); @@ -79,11 +69,6 @@ public FileUtilsTest() throws Exception { testFile2Size = (int) testFile2.length(); } - /** - *setUp.
- * - * @throws java.lang.Exception if any. - */ @BeforeEach void setUp() throws Exception { getTestDirectory().mkdirs(); @@ -95,11 +80,6 @@ void setUp() throws Exception { createFile(testFile2, testFile2Size); } - // byteCountToDisplaySize - - /** - *testByteCountToDisplaySize.
- */ @Test void byteCountToDisplaySize() { assertEquals("0 bytes", FileUtils.byteCountToDisplaySize(0)); @@ -108,23 +88,12 @@ void byteCountToDisplaySize() { assertEquals("1 GB", FileUtils.byteCountToDisplaySize(1024 * 1024 * 1024)); } - // waitFor - - /** - *testWaitFor.
- */ @Test void waitFor() { FileUtils.waitFor("", -1); - FileUtils.waitFor("", 2); } - /** - *testToFile.
- * - * @throws java.lang.Exception if any. - */ @Test void toFile() throws Exception { URL url = getClass().getResource("/test.txt"); @@ -133,35 +102,19 @@ void toFile() throws Exception { assertEquals("name #%20?{}[]<>.txt", file.getName()); } - /** - *testToFileBadProtocol.
- * - * @throws java.lang.Exception if any. - */ @Test void toFileBadProtocol() throws Exception { URL url = new URL("http://maven.apache.org/"); - File file = FileUtils.toFile(url); - assertNull(file); + assertNull(FileUtils.toFile(url)); } - /** - *testToFileNull.
- * - * @throws java.lang.Exception if any. - */ @Test - void toFileNull() throws Exception { + void toFileNull() { File file = FileUtils.toFile(null); assertNull(file); } // Hacked to sanity by Trygve - /** - *testToURLs.
- * - * @throws java.lang.Exception if any. - */ @Test void toURLs() throws Exception { File[] files = new File[] { @@ -181,16 +134,13 @@ void toURLs() throws Exception { } } - /** - *testGetFilesFromExtension.
- */ @Test void getFilesFromExtension() { // TODO I'm not sure what is supposed to happen here FileUtils.getFilesFromExtension("dir", null); // Non-existent files - final String[] emptyFileNames = + String[] emptyFileNames = FileUtils.getFilesFromExtension(getTestDirectory().getAbsolutePath(), new String[] {"java"}); assertEquals(0, emptyFileNames.length); @@ -202,11 +152,6 @@ void getFilesFromExtension() { */ } - // mkdir - - /** - *testMkdir.
- */ @Test void mkdir() { final File dir = new File(getTestDirectory(), "testdir"); @@ -214,24 +159,14 @@ void mkdir() { dir.deleteOnExit(); if (Os.isFamily(Os.FAMILY_WINDOWS)) { - try { + assertThrows(IllegalArgumentException.class, () -> { File winFile = new File(getTestDirectory(), "bla*bla"); winFile.deleteOnExit(); FileUtils.mkdir(winFile.getAbsolutePath()); - fail(); - } catch (IllegalArgumentException e) { - assertTrue(true); - } + }); } } - // contentEquals - - /** - *testContentEquals.
- * - * @throws java.lang.Exception if any. - */ @Test void contentEquals() throws Exception { // Non-existent files @@ -258,36 +193,18 @@ void contentEquals() throws Exception { assertTrue(FileUtils.contentEquals(file, file)); } - // removePath - - /** - *testRemovePath.
- */ @Test void removePath() { - final String fileName = - FileUtils.removePath(new File(getTestDirectory(), getTestMethodName()).getAbsolutePath()); + String fileName = FileUtils.removePath(new File(getTestDirectory(), getTestMethodName()).getAbsolutePath()); assertEquals(getTestMethodName(), fileName); } - // getPath - - /** - *testGetPath.
- */ @Test void getPath() { final String fileName = FileUtils.getPath(new File(getTestDirectory(), getTestMethodName()).getAbsolutePath()); assertEquals(getTestDirectory().getAbsolutePath(), fileName); } - // copyURLToFile - - /** - *testCopyURLToFile.
- * - * @throws java.lang.Exception if any. - */ @Test void copyURLToFile() throws Exception { // Creates file @@ -305,11 +222,6 @@ void copyURLToFile() throws Exception { } } - // catPath - - /** - *testCatPath.
- */ @Test void catPath() { // TODO StringIndexOutOfBoundsException thrown if file doesn't contain slash. @@ -320,13 +232,6 @@ void catPath() { assertEquals("/a/d", FileUtils.catPath("/a/b/c", "../d")); } - // forceMkdir - - /** - *testForceMkdir.
- * - * @throws java.lang.Exception if any. - */ @Test void forceMkdir() throws Exception { // Tests with existing directory @@ -339,11 +244,7 @@ void forceMkdir() throws Exception { assertTrue(testFile.exists(), "Test file does not exist."); // Tests with existing file - try { - FileUtils.forceMkdir(testFile); - fail("Exception expected."); - } catch (IOException ignored) { - } + assertThrows(IOException.class, () -> FileUtils.forceMkdir(testFile)); testFile.delete(); @@ -352,45 +253,29 @@ void forceMkdir() throws Exception { assertTrue(testFile.exists(), "Directory was not created."); if (Os.isFamily(Os.FAMILY_WINDOWS)) { - try { + assertThrows(IllegalArgumentException.class, () -> { File winFile = new File(getTestDirectory(), "bla*bla"); winFile.deleteOnExit(); FileUtils.forceMkdir(winFile); - fail(); - } catch (IllegalArgumentException e) { - assertTrue(true); - } + }); } } - // sizeOfDirectory - - /** - *testSizeOfDirectory.
- * - * @throws java.lang.Exception if any. - */ @Test void sizeOfDirectory() throws Exception { final File file = new File(getTestDirectory(), getTestMethodName()); - // Non-existent file - try { + assertThrows(IllegalArgumentException.class, () -> { + // Non-existent file FileUtils.sizeOfDirectory(file); - fail("Exception expected."); - } catch (IllegalArgumentException ignored) { - } + }); // Creates file file.createNewFile(); file.deleteOnExit(); // Existing file - try { - FileUtils.sizeOfDirectory(file); - fail("Exception expected."); - } catch (IllegalArgumentException ignored) { - } + assertThrows(IllegalArgumentException.class, () -> FileUtils.sizeOfDirectory(file)); // Existing directory file.delete(); @@ -399,16 +284,6 @@ void sizeOfDirectory() throws Exception { assertEquals(TEST_DIRECTORY_SIZE, FileUtils.sizeOfDirectory(file), "Unexpected directory size"); } - // isFileNewer - - // TODO Finish test - - // copyFile - /** - *testCopyFile1.
- * - * @throws java.lang.Exception if any. - */ @Test void copyFile1() throws Exception { final File destination = new File(getTestDirectory(), "copy1.txt"); @@ -417,11 +292,6 @@ void copyFile1() throws Exception { assertEquals(destination.length(), testFile1Size, "Check Full copy"); } - /** - *testCopyFile2.
- * - * @throws java.lang.Exception if any. - */ @Test void copyFile2() throws Exception { final File destination = new File(getTestDirectory(), "copy2.txt"); @@ -432,8 +302,6 @@ void copyFile2() throws Exception { /** * ensure we create directory tree for destination - * - * @throws java.lang.Exception */ @Test void copyFile3() throws Exception { @@ -447,12 +315,6 @@ void copyFile3() throws Exception { assertEquals(destination.length(), testFile2Size, "Check Full copy"); } - // linkFile - /** - *testLinkFile1.
- * - * @throws java.lang.Exception if any. - */ @Test void linkFile1() throws Exception { final File destination = new File(getTestDirectory(), "link1.txt"); @@ -462,11 +324,6 @@ void linkFile1() throws Exception { assertTrue(Files.isSymbolicLink(destination.toPath()), "Check is link"); } - /** - *testLinkFile2.
- * - * @throws java.lang.Exception if any. - */ @Test void linkFile2() throws Exception { final File destination = new File(getTestDirectory(), "link2.txt"); @@ -478,8 +335,6 @@ void linkFile2() throws Exception { /** * ensure we create directory tree for destination - * - * @throws java.lang.Exception */ @Test void linkFile3() throws Exception { @@ -494,13 +349,6 @@ void linkFile3() throws Exception { assertTrue(Files.isSymbolicLink(destination.toPath()), "Check is link"); } - // copyFileIfModified - - /** - *testCopyIfModifiedWhenSourceIsNewer.
- * - * @throws java.lang.Exception if any. - */ @Test void copyIfModifiedWhenSourceIsNewer() throws Exception { FileUtils.forceMkdir(new File(getTestDirectory() + "/temp")); @@ -523,11 +371,6 @@ void copyIfModifiedWhenSourceIsNewer() throws Exception { "Failed copy. Target file should have been updated."); } - /** - *testCopyIfModifiedWhenSourceIsOlder.
- * - * @throws java.lang.Exception if any. - */ @Test void copyIfModifiedWhenSourceIsOlder() throws Exception { FileUtils.forceMkdir(new File(getTestDirectory() + "/temp")); @@ -547,11 +390,6 @@ void copyIfModifiedWhenSourceIsOlder() throws Exception { assertFalse(FileUtils.copyFileIfModified(source, destination), "Source file should not have been copied."); } - /** - *testCopyIfModifiedWhenSourceHasZeroDate.
- * - * @throws java.lang.Exception if any. - */ @Test void copyIfModifiedWhenSourceHasZeroDate() throws Exception { FileUtils.forceMkdir(new File(getTestDirectory(), "temp")); @@ -568,13 +406,6 @@ void copyIfModifiedWhenSourceHasZeroDate() throws Exception { assertTrue(FileUtils.copyFileIfModified(source, destination), "Source file should have been copied."); } - // forceDelete - - /** - *testForceDeleteAFile1.
- * - * @throws java.lang.Exception if any. - */ @Test void forceDeleteAFile1() throws Exception { final File destination = new File(getTestDirectory(), "copy1.txt"); @@ -584,11 +415,6 @@ void forceDeleteAFile1() throws Exception { assertFalse(destination.exists(), "Check No Exist"); } - /** - *testForceDeleteAFile2.
- * - * @throws java.lang.Exception if any. - */ @Test void forceDeleteAFile2() throws Exception { final File destination = new File(getTestDirectory(), "copy2.txt"); @@ -598,13 +424,6 @@ void forceDeleteAFile2() throws Exception { assertFalse(destination.exists(), "Check No Exist"); } - // copyFileToDirectory - - /** - *testCopyFile1ToDir.
- * - * @throws java.lang.Exception if any. - */ @Test void copyFile1ToDir() throws Exception { final File directory = new File(getTestDirectory(), "subdir"); @@ -617,11 +436,6 @@ void copyFile1ToDir() throws Exception { assertEquals(destination.length(), testFile1Size, "Check Full copy"); } - /** - *testCopyFile2ToDir.
- * - * @throws java.lang.Exception if any. - */ @Test void copyFile2ToDir() throws Exception { final File directory = new File(getTestDirectory(), "subdir"); @@ -634,13 +448,6 @@ void copyFile2ToDir() throws Exception { assertEquals(destination.length(), testFile2Size, "Check Full copy"); } - // copyFileToDirectoryIfModified - - /** - *testCopyFile1ToDirIfModified.
- * - * @throws java.lang.Exception if any. - */ @Test void copyFile1ToDirIfModified() throws Exception { final File directory = new File(getTestDirectory(), "subdir"); @@ -664,11 +471,6 @@ void copyFile1ToDirIfModified() throws Exception { assertEquals(timestamp, target.lastModified(), "Timestamp was changed"); } - /** - *testCopyFile2ToDirIfModified.
- * - * @throws java.lang.Exception if any. - */ @Test void copyFile2ToDirIfModified() throws Exception { final File directory = new File(getTestDirectory(), "subdir"); @@ -692,52 +494,26 @@ void copyFile2ToDirIfModified() throws Exception { assertEquals(timestamp, target.lastModified(), "Timestamp was changed"); } - // forceDelete - - /** - *testForceDeleteDir.
- * - * @throws java.lang.Exception if any. - */ @Test void forceDeleteDir() throws Exception { FileUtils.forceDelete(getTestDirectory().getParentFile()); assertFalse(getTestDirectory().getParentFile().exists(), "Check No Exist"); } - // resolveFile - - /** - *testResolveFileDotDot.
- * - * @throws java.lang.Exception if any. - */ @Test - void resolveFileDotDot() throws Exception { + void resolveFileDotDot() { final File file = FileUtils.resolveFile(getTestDirectory(), ".."); assertEquals(file, getTestDirectory().getParentFile(), "Check .. operator"); } - /** - *testResolveFileDot.
- * - * @throws java.lang.Exception if any. - */ @Test - void resolveFileDot() throws Exception { + void resolveFileDot() { final File file = FileUtils.resolveFile(getTestDirectory(), "."); assertEquals(file, getTestDirectory(), "Check . operator"); } - // normalize - - /** - *testNormalize.
- * - * @throws java.lang.Exception if any. - */ @Test - void normalize() throws Exception { + void normalize() { final String[] src = { "", "/", @@ -786,24 +562,7 @@ void normalize() throws Exception { } } - private String replaceAll(String text, String lookFor, String replaceWith) { - StringBuilder sb = new StringBuilder(text); - while (true) { - int idx = sb.indexOf(lookFor); - if (idx < 0) { - break; - } - sb.replace(idx, idx + lookFor.length(), replaceWith); - } - return sb.toString(); - } - - /** - * Test the FileUtils implementation. - * - * @throws java.lang.Exception if any. - */ - // Used to exist as IOTestCase class + @SuppressWarnings("deprecation") @Test void fileUtils() throws Exception { // Loads file from classpath @@ -836,9 +595,6 @@ void fileUtils() throws Exception { assertEquals("This is a test", contents, "FileUtils.fileRead()"); } - /** - *testGetExtension.
- */ @Test void getExtension() { final String[][] tests = { @@ -856,9 +612,6 @@ void getExtension() { } } - /** - *testGetExtensionWithPaths.
- */ @Test void getExtensionWithPaths() { // Since the utilities are based on the separator for the platform @@ -880,9 +633,6 @@ void getExtensionWithPaths() { } } - /** - *testRemoveExtension.
- */ @Test void removeExtension() { final String[][] tests = { @@ -899,10 +649,6 @@ void removeExtension() { } } - /* TODO: Reenable this test */ - /** - *testRemoveExtensionWithPaths.
- */ @Test void removeExtensionWithPaths() { // Since the utilities are based on the separator for the platform @@ -933,11 +679,6 @@ void removeExtensionWithPaths() { } } - /** - *testCopyDirectoryStructureWithAEmptyDirectoryStructure.
- * - * @throws java.lang.Exception if any. - */ @Test void copyDirectoryStructureWithAEmptyDirectoryStructure() throws Exception { File from = new File(getTestDirectory(), "from"); @@ -953,11 +694,6 @@ void copyDirectoryStructureWithAEmptyDirectoryStructure() throws Exception { FileUtils.copyDirectoryStructure(from, to); } - /** - *testCopyDirectoryStructureWithAPopulatedStructure.
- * - * @throws java.lang.Exception if any. - */ @Test void copyDirectoryStructureWithAPopulatedStructure() throws Exception { // Make a structure to copy @@ -1016,11 +752,6 @@ void copyDirectoryStructureWithAPopulatedStructure() throws Exception { checkFile(f2_1, new File(to, "2/2_1/2_1.txt")); } - /** - *testCopyDirectoryStructureIfModified.
- * - * @throws java.lang.Exception if any. - */ @Test void copyDirectoryStructureIfModified() throws Exception { // Make a structure to copy @@ -1098,11 +829,6 @@ void copyDirectoryStructureIfModified() throws Exception { assertEquals(timestamps[2], files[2].lastModified(), "Unmodified file was overwritten"); } - /** - *testCopyDirectoryStructureToSelf.
- * - * @throws java.lang.Exception if any. - */ @Test void copyDirectoryStructureToSelf() throws Exception { // Make a structure to copy @@ -1132,19 +858,9 @@ void copyDirectoryStructureToSelf() throws Exception { createFile(f2, 100); - try { - FileUtils.copyDirectoryStructure(toFrom, toFrom); - fail("An exception must be thrown."); - } catch (IOException e) { - // expected - } + assertThrows(IOException.class, () -> FileUtils.copyDirectoryStructure(toFrom, toFrom)); } - /** - *testFilteredFileCopy.
- * - * @throws java.lang.Exception if any. - */ @Test void filteredFileCopy() throws Exception { File compareFile = new File(getTestDirectory(), "compare.txt"); @@ -1175,11 +891,6 @@ public Reader getReader(Reader reader) { compareFile.delete(); } - /** - *testFilteredWithoutFilterAndOlderFile.
- * - * @throws java.lang.Exception if any. - */ @Test void filteredWithoutFilterAndOlderFile() throws Exception { String content = "This is a test."; @@ -1206,11 +917,6 @@ void filteredWithoutFilterAndOlderFile() throws Exception { assertEquals(content, destFileContent); } - /** - *testFilteredWithoutFilterAndOlderFileAndOverwrite.
- * - * @throws java.lang.Exception if any. - */ @Test void filteredWithoutFilterAndOlderFileAndOverwrite() throws Exception { String content = "This is a test."; @@ -1237,13 +943,8 @@ void filteredWithoutFilterAndOlderFileAndOverwrite() throws Exception { assertEquals(newercontent, destFileContent); } - /** - *testFileRead.
- * - * @throws java.io.IOException if any. - */ @Test - void fileRead() throws IOException { + void fileRead() throws Exception { File testFile = new File(getTestDirectory(), "testFileRead.txt"); String testFileName = testFile.getAbsolutePath(); /* @@ -1253,123 +954,84 @@ void fileRead() throws IOException { * survive the roundtrip test. */ String testString = "Only US-ASCII characters here, see comment above!"; - Writer writer = null; - try { - writer = new OutputStreamWriter(Files.newOutputStream(testFile.toPath())); + try (Writer writer = new OutputStreamWriter(Files.newOutputStream(testFile.toPath()))) { writer.write(testString); writer.flush(); - } finally { - IOUtil.close(writer); } assertEquals(testString, FileUtils.fileRead(testFile), "testString should be equal"); assertEquals(testString, FileUtils.fileRead(testFileName), "testString should be equal"); testFile.delete(); } - /** - *testFileReadWithEncoding.
- * - * @throws java.io.IOException if any. - */ @Test - void fileReadWithEncoding() throws IOException { + void fileReadWithEncoding() throws Exception { String encoding = "UTF-8"; File testFile = new File(getTestDirectory(), "testFileRead.txt"); String testFileName = testFile.getAbsolutePath(); // unicode escaped Japanese hiragana, "aiueo" + Umlaut a - String testString = "\u3042\u3044\u3046\u3048\u304a\u00e4"; - Writer writer = null; - try { - writer = new OutputStreamWriter(Files.newOutputStream(testFile.toPath()), encoding); + String testString = "あいうえおä"; + try (Writer writer = new OutputStreamWriter(Files.newOutputStream(testFile.toPath()), encoding)) { writer.write(testString); writer.flush(); - } finally { - IOUtil.close(writer); } assertEquals(testString, FileUtils.fileRead(testFile, "UTF-8"), "testString should be equal"); assertEquals(testString, FileUtils.fileRead(testFileName, "UTF-8"), "testString should be equal"); testFile.delete(); } - /** - *testFileAppend.
- * - * @throws java.io.IOException if any. - */ + @SuppressWarnings("deprecation") @Test - void fileAppend() throws IOException { + void fileAppend() throws Exception { String baseString = "abc"; File testFile = new File(getTestDirectory(), "testFileAppend.txt"); String testFileName = testFile.getAbsolutePath(); - Writer writer = null; - try { - writer = new OutputStreamWriter(Files.newOutputStream(testFile.toPath())); + try (Writer writer = new OutputStreamWriter(Files.newOutputStream(testFile.toPath()))) { writer.write(baseString); writer.flush(); - } finally { - IOUtil.close(writer); } // unicode escaped Japanese hiragana, "aiueo" + Umlaut a - String testString = "\u3042\u3044\u3046\u3048\u304a\u00e4"; + String testString = "あいうえおä"; FileUtils.fileAppend(testFileName, testString); assertEqualContent((baseString + testString).getBytes(), testFile); testFile.delete(); } - /** - *testFileAppendWithEncoding.
- * - * @throws java.io.IOException if any. - */ + @SuppressWarnings("deprecation") @Test - void fileAppendWithEncoding() throws IOException { + void fileAppendWithEncoding() throws Exception { String baseString = "abc"; String encoding = "UTF-8"; File testFile = new File(getTestDirectory(), "testFileAppend.txt"); String testFileName = testFile.getAbsolutePath(); - Writer writer = null; - try { - writer = new OutputStreamWriter(Files.newOutputStream(testFile.toPath()), encoding); + try (Writer writer = new OutputStreamWriter(Files.newOutputStream(testFile.toPath()), encoding)) { writer.write(baseString); writer.flush(); - } finally { - IOUtil.close(writer); } // unicode escaped Japanese hiragana, "aiueo" + Umlaut a - String testString = "\u3042\u3044\u3046\u3048\u304a\u00e4"; + String testString = "あいうえおä"; FileUtils.fileAppend(testFileName, encoding, testString); assertEqualContent((baseString + testString).getBytes(encoding), testFile); testFile.delete(); } - /** - *testFileWrite.
- * - * @throws java.io.IOException if any. - */ @Test - void fileWrite() throws IOException { + void fileWrite() throws Exception { File testFile = new File(getTestDirectory(), "testFileWrite.txt"); String testFileName = testFile.getAbsolutePath(); // unicode escaped Japanese hiragana, "aiueo" + Umlaut a - String testString = "\u3042\u3044\u3046\u3048\u304a\u00e4"; + String testString = "あいうえおä"; FileUtils.fileWrite(testFileName, testString); assertEqualContent(testString.getBytes(), testFile); testFile.delete(); } - /** - *testFileWriteWithEncoding.
- * - * @throws java.io.IOException if any. - */ @Test - void fileWriteWithEncoding() throws IOException { + void fileWriteWithEncoding() throws Exception { String encoding = "UTF-8"; File testFile = new File(getTestDirectory(), "testFileWrite.txt"); String testFileName = testFile.getAbsolutePath(); // unicode escaped Japanese hiragana, "aiueo" + Umlaut a - String testString = "\u3042\u3044\u3046\u3048\u304a\u00e4"; + String testString = "あいうえおä"; FileUtils.fileWrite(testFileName, encoding, testString); assertEqualContent(testString.getBytes(encoding), testFile); testFile.delete(); @@ -1378,17 +1040,13 @@ void fileWriteWithEncoding() throws IOException { /** * Workaround for the following Sun bugs. They are fixed in JDK 6u1 and JDK 5u11. * - * @throws java.lang.Exception * @see Sun bug id=4403166 * @see Sun bug id=6182812 * @see Sun bug id=6481955 */ @Test + @EnabledOnOs(OS.WINDOWS) void deleteLongPathOnWindows() throws Exception { - if (!Os.isFamily(Os.FAMILY_WINDOWS)) { - return; - } - File a = new File(getTestDirectory(), "longpath"); a.mkdir(); File a1 = new File(a, "a"); @@ -1401,11 +1059,10 @@ void deleteLongPathOnWindows() throws Exception { File f = new File(a1, path + "test.txt"); - InputStream is = new ByteArrayInputStream("Blabla".getBytes(StandardCharsets.UTF_8)); - OutputStream os = Files.newOutputStream(f.getCanonicalFile().toPath()); - IOUtil.copy(is, os); - IOUtil.close(is); - IOUtil.close(os); + try (InputStream is = new ByteArrayInputStream("Blabla".getBytes(StandardCharsets.UTF_8)); + OutputStream os = Files.newOutputStream(f.getCanonicalFile().toPath())) { + IOUtil.copy(is, os); + } FileUtils.forceDelete(f); @@ -1415,14 +1072,9 @@ void deleteLongPathOnWindows() throws Exception { } } - // Test for bug PLXUTILS-10 - /** - *testCopyFileOnSameFile.
- * - * @throws java.io.IOException if any. - */ + @SuppressWarnings("deprecation") @Test - void copyFileOnSameFile() throws IOException { + void copyFileOnSameFile() throws Exception { String content = "ggrgreeeeeeeeeeeeeeeeeeeeeeeoierjgioejrgiojregioejrgufcdxivbsdibgfizgerfyaezgv!zeez"; final File theFile = File.createTempFile("test", ".txt"); theFile.deleteOnExit(); @@ -1436,13 +1088,8 @@ void copyFileOnSameFile() throws IOException { assertTrue(theFile.length() > 0); } - /** - *testExtensions.
- * - * @throws java.lang.Exception if any. - */ @Test - void extensions() throws Exception { + void extensions() { String[][] values = { {"fry.frozen", "frozen"}, @@ -1465,13 +1112,8 @@ void extensions() throws Exception { } } - /** - *testIsValidWindowsFileName.
- * - * @throws java.lang.Exception if any. - */ @Test - void isValidWindowsFileName() throws Exception { + void isValidWindowsFileName() { File f = new File("c:\test"); assertTrue(FileUtils.isValidWindowsFileName(f)); @@ -1493,11 +1135,6 @@ void isValidWindowsFileName() throws Exception { } } - /** - *testDeleteDirectoryWithValidFileSymlink.
- * - * @throws java.lang.Exception if any. - */ @Test void deleteDirectoryWithValidFileSymlink() throws Exception { File symlinkTarget = new File(getTestDirectory(), "fileSymlinkTarget"); @@ -1515,11 +1152,6 @@ void deleteDirectoryWithValidFileSymlink() throws Exception { assertFalse(getTestDirectory().exists(), "Failed to delete test directory"); } - /** - *testDeleteDirectoryWithValidDirSymlink.
- * - * @throws java.lang.Exception if any. - */ @Test void deleteDirectoryWithValidDirSymlink() throws Exception { File symlinkTarget = new File(getTestDirectory(), "dirSymlinkTarget"); @@ -1537,11 +1169,6 @@ void deleteDirectoryWithValidDirSymlink() throws Exception { assertFalse(getTestDirectory().exists(), "Failed to delete test directory"); } - /** - *testDeleteDirectoryWithDanglingSymlink.
- * - * @throws java.lang.Exception if any. - */ @Test void deleteDirectoryWithDanglingSymlink() throws Exception { File symlinkTarget = new File(getTestDirectory(), "missingSymlinkTarget"); @@ -1558,11 +1185,6 @@ void deleteDirectoryWithDanglingSymlink() throws Exception { assertFalse(getTestDirectory().exists(), "Failed to delete test directory"); } - /** - *testcopyDirectoryLayoutWithExcludesIncludes.
- * - * @throws java.lang.Exception if any. - */ @Test void testcopyDirectoryLayoutWithExcludesIncludes() throws Exception { File destination = new File("target", "copyDirectoryStructureWithExcludesIncludes"); @@ -1578,13 +1200,16 @@ void testcopyDirectoryLayoutWithExcludesIncludes() throws Exception { assertTrue(destination.exists()); File[] childs = destination.listFiles(); + assertNotNull(childs); assertEquals(2, childs.length); for (File current : childs) { if (current.getName().endsWith("empty-dir") || current.getName().endsWith("dir1")) { if (current.getName().endsWith("dir1")) { - assertEquals(1, current.listFiles().length); - assertTrue(current.listFiles()[0].getName().endsWith("dir2")); + File[] listFiles = current.listFiles(); + assertNotNull(listFiles); + assertEquals(1, listFiles.length); + assertTrue(listFiles[0].getName().endsWith("dir2")); } } else { fail("not empty-dir or dir1"); @@ -1594,11 +1219,9 @@ void testcopyDirectoryLayoutWithExcludesIncludes() throws Exception { /** * Be sure that {@link org.codehaus.plexus.util.FileUtils#createTempFile(String, String, File)} is always unique. - * - * @throws java.lang.Exception if any */ @Test - void createTempFile() throws Exception { + void createTempFile() { File last = FileUtils.createTempFile("unique", ".tmp", null); for (int i = 0; i < 10; i++) { File current = FileUtils.createTempFile("unique", ".tmp", null); @@ -1611,7 +1234,6 @@ void createTempFile() throws Exception { * Because windows(tm) quite frequently sleeps less than the advertised time * * @param time The amount of time to sleep - * @throws InterruptedException */ private void reallySleep(int time) throws InterruptedException { long until = System.currentTimeMillis() + time; diff --git a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java index 89581a1c..0d44851e 100644 --- a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java @@ -49,9 +49,9 @@ * Due to interdependencies in IOUtils and IOUtilsTestlet, one bug may cause multiple tests to fail. * * @author Jeff Turner - * @version $Id: $Id * @since 3.4.0 */ +@SuppressWarnings("deprecation") public final class IOUtilTest { /* * Note: this is not particularly beautiful code. A better way to check for flush and close status would be to @@ -65,9 +65,6 @@ public final class IOUtilTest { private File testFile; - /** - *setUp.
- */ @BeforeEach void setUp() { try { @@ -78,75 +75,59 @@ void setUp() { testFile = new File(testDirectory, "file2-test.txt"); - createFile(testFile, FILE_SIZE); + createFile(testFile); } catch (IOException ioe) { throw new RuntimeException("Can't run this test because environment could not be built"); } } - /** - *tearDown.
- */ public void tearDown() { testFile.delete(); testDirectory.delete(); } - private void createFile(File file, long size) throws IOException { + private void createFile(File file) throws IOException { BufferedOutputStream output = new BufferedOutputStream(Files.newOutputStream(file.toPath())); - for (int i = 0; i < size; i++) { + for (int i = 0; i < FILE_SIZE; i++) { output.write((byte) (i % 128)); // nice varied byte pattern compatible with Readers and Writers } output.close(); } - /** Assert that the contents of two byte arrays are the same. */ private void assertEqualContent(byte[] b0, byte[] b1) { assertArrayEquals(b0, b1, "Content not equal according to java.util.Arrays#equals()"); } - /** Assert that the content of two files is the same. */ private void assertEqualContent(File f0, File f1) throws IOException { byte[] buf0 = Files.readAllBytes(f0.toPath()); byte[] buf1 = Files.readAllBytes(f1.toPath()); assertArrayEquals(buf0, buf1, "The files " + f0 + " and " + f1 + " have different content"); } - /** Assert that the content of a file is equal to that in a byte[]. */ private void assertEqualContent(byte[] b0, File file) throws IOException { byte[] b1 = Files.readAllBytes(file.toPath()); assertArrayEquals(b0, b1, "Content differs"); } - /** - *testInputStreamToOutputStream.
- * - * @throws java.lang.Exception if any. - */ @Test void inputStreamToOutputStream() throws Exception { File destination = newFile("copy1.txt"); - InputStream fin = Files.newInputStream(testFile.toPath()); - OutputStream fout = Files.newOutputStream(destination.toPath()); + try (InputStream fin = Files.newInputStream(testFile.toPath()); + OutputStream fout = Files.newOutputStream(destination.toPath())) { - IOUtil.copy(fin, fout); - assertEquals(0, fin.available(), "Not all bytes were read"); - fout.flush(); + IOUtil.copy(fin, fout); - checkFile(destination); - checkWrite(fout); - fout.close(); - fin.close(); + assertEquals(0, fin.available(), "Not all bytes were read"); + fout.flush(); + + checkFile(destination); + checkWrite(fout); + } deleteFile(destination); } - /** - *testInputStreamToWriter.
- * - * @throws java.lang.Exception if any. - */ @Test void inputStreamToWriter() throws Exception { File destination = newFile("copy2.txt"); @@ -165,11 +146,6 @@ void inputStreamToWriter() throws Exception { deleteFile(destination); } - /** - *testInputStreamToString.
- * - * @throws java.lang.Exception if any. - */ @Test void inputStreamToString() throws Exception { InputStream fin = Files.newInputStream(testFile.toPath()); @@ -180,11 +156,6 @@ void inputStreamToString() throws Exception { fin.close(); } - /** - *testReaderToOutputStream.
- * - * @throws java.lang.Exception if any. - */ @Test void readerToOutputStream() throws Exception { File destination = newFile("copy3.txt"); @@ -205,11 +176,6 @@ void readerToOutputStream() throws Exception { deleteFile(destination); } - /** - *testReaderToWriter.
- * - * @throws java.lang.Exception if any. - */ @Test void readerToWriter() throws Exception { File destination = newFile("copy4.txt"); @@ -225,11 +191,6 @@ void readerToWriter() throws Exception { deleteFile(destination); } - /** - *testReaderToString.
- * - * @throws java.lang.Exception if any. - */ @Test void readerToString() throws Exception { Reader fin = Files.newBufferedReader(testFile.toPath()); @@ -239,11 +200,6 @@ void readerToString() throws Exception { fin.close(); } - /** - *testStringToOutputStream.
- * - * @throws java.lang.Exception if any. - */ @Test void stringToOutputStream() throws Exception { File destination = newFile("copy5.txt"); @@ -266,11 +222,6 @@ void stringToOutputStream() throws Exception { deleteFile(destination); } - /** - *testStringToWriter.
- * - * @throws java.lang.Exception if any. - */ @Test void stringToWriter() throws Exception { File destination = newFile("copy6.txt"); @@ -289,11 +240,6 @@ void stringToWriter() throws Exception { deleteFile(destination); } - /** - *testInputStreamToByteArray.
- * - * @throws java.lang.Exception if any. - */ @Test void inputStreamToByteArray() throws Exception { InputStream fin = Files.newInputStream(testFile.toPath()); @@ -305,11 +251,6 @@ void inputStreamToByteArray() throws Exception { fin.close(); } - /** - *testStringToByteArray.
- * - * @throws java.lang.Exception if any. - */ @Test void stringToByteArray() throws Exception { Reader fin = Files.newBufferedReader(testFile.toPath()); @@ -322,11 +263,6 @@ void stringToByteArray() throws Exception { fin.close(); } - /** - *testByteArrayToWriter.
- * - * @throws java.lang.Exception if any. - */ @Test void byteArrayToWriter() throws Exception { File destination = newFile("copy7.txt"); @@ -344,11 +280,6 @@ void byteArrayToWriter() throws Exception { deleteFile(destination); } - /** - *testByteArrayToString.
- * - * @throws java.lang.Exception if any. - */ @Test void byteArrayToString() throws Exception { InputStream fin = Files.newInputStream(testFile.toPath()); @@ -359,11 +290,6 @@ void byteArrayToString() throws Exception { fin.close(); } - /** - *testByteArrayToOutputStream.
- * - * @throws java.lang.Exception if any. - */ @Test void byteArrayToOutputStream() throws Exception { File destination = newFile("copy8.txt"); @@ -384,14 +310,6 @@ void byteArrayToOutputStream() throws Exception { deleteFile(destination); } - // ---------------------------------------------------------------------- - // Test closeXXX() - // ---------------------------------------------------------------------- - - /** - *testCloseInputStream.
- * - */ @Test void closeInputStream() { IOUtil.close((InputStream) null); @@ -403,11 +321,6 @@ void closeInputStream() { assertTrue(inputStream.closed); } - /** - *testCloseOutputStream.
- * - * @throws java.lang.Exception if any. - */ @Test void closeOutputStream() throws Exception { IOUtil.close((OutputStream) null); @@ -419,11 +332,6 @@ void closeOutputStream() throws Exception { assertTrue(outputStream.closed); } - /** - *testCloseReader.
- * - * @throws java.lang.Exception if any. - */ @Test void closeReader() throws Exception { IOUtil.close((Reader) null); @@ -435,11 +343,6 @@ void closeReader() throws Exception { assertTrue(reader.closed); } - /** - *testCloseWriter.
- * - * @throws java.lang.Exception if any. - */ @Test void closeWriter() throws Exception { IOUtil.close((Writer) null); @@ -451,7 +354,7 @@ void closeWriter() throws Exception { assertTrue(writer.closed); } - private class TestInputStream extends InputStream { + private static class TestInputStream extends InputStream { boolean closed; public void close() { @@ -465,7 +368,7 @@ public int read() { } } - private class TestOutputStream extends OutputStream { + private static class TestOutputStream extends OutputStream { boolean closed; public void close() { @@ -477,7 +380,7 @@ public void write(int value) { } } - private class TestReader extends Reader { + private static class TestReader extends Reader { boolean closed; public void close() { @@ -507,10 +410,6 @@ public void flush() { } } - // ---------------------------------------------------------------------- - // Utility methods - // ---------------------------------------------------------------------- - private File newFile(String filename) throws Exception { File destination = new File(testDirectory, filename); assertFalse(destination.exists(), filename + "Test output data file shouldn't previously exist"); diff --git a/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java b/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java index a8f86410..1da97507 100644 --- a/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java +++ b/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java @@ -28,7 +28,6 @@ *InterpolationFilterReaderTest class.
* * @author herve - * @version $Id: $Id * @since 3.4.0 */ class InterpolationFilterReaderTest { @@ -36,11 +35,6 @@ 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. */ - /** - *testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken.
- * - * @throws java.lang.Exception if any. - */ @Test void shouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Exception { MaptestShouldNotInterpolateExpressionWithMissingEndToken.
- * - * @throws java.lang.Exception if any. - */ @Test void shouldNotInterpolateExpressionWithMissingEndToken() throws Exception { MaptestShouldNotInterpolateWithMalformedStartToken.
- * - * @throws java.lang.Exception if any. - */ @Test void shouldNotInterpolateWithMalformedStartToken() throws Exception { MaptestShouldNotInterpolateWithMalformedEndToken.
- * - * @throws java.lang.Exception if any. - */ @Test void shouldNotInterpolateWithMalformedEndToken() throws Exception { MaptestInterpolationWithMulticharDelimiters.
- * - * @throws java.lang.Exception if any. - */ @Test void interpolationWithMulticharDelimiters() throws Exception { MaptestDefaultInterpolationWithNonInterpolatedValueAtEnd.
- * - * @throws java.lang.Exception if any. - */ @Test void defaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { MaptestDefaultInterpolationWithInterpolatedValueAtEnd.
- * - * @throws java.lang.Exception if any. - */ @Test void defaultInterpolationWithInterpolatedValueAtEnd() throws Exception { MaptestInterpolationWithSpecifiedBoundaryTokens.
- * - * @throws java.lang.Exception if any. - */ @Test void interpolationWithSpecifiedBoundaryTokens() throws Exception { MaptestInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd.
- * - * @throws java.lang.Exception if any. - */ @Test void interpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd() throws Exception { MaptestInterpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd.
- * - * @throws java.lang.Exception if any. - */ @Test void interpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd() throws Exception { MaptestInterpolationWithSpecifiedBoundaryTokensAndAdditionalTokenCharacter.
- * - * @throws java.lang.Exception if any. - */ @Test void interpolationWithSpecifiedBoundaryTokensAndAdditionalTokenCharacter() throws Exception { MaptestShouldInterpolateExpressionAtEndOfDataWithInvalidEndToken.
- * - * @throws java.io.IOException if any. - */ + @Test - void shouldInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws IOException { + void shouldInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Exception { String testStr = "This is a ${test"; LineOrientedInterpolatingReader iReader = new LineOrientedInterpolatingReader( new StringReader(testStr), Collections.singletonMap("test", "TestValue")); @@ -57,11 +48,6 @@ void shouldInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws IOExcept assertEquals("This is a ${test", result); } - /** - *testDefaultInterpolationWithNonInterpolatedValueAtEnd.
- * - * @throws java.lang.Exception if any. - */ @Test void defaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { MaptestDefaultInterpolationWithEscapedExpression.
- * - * @throws java.lang.Exception if any. - */ @Test void defaultInterpolationWithEscapedExpression() throws Exception { MaptestDefaultInterpolationWithInterpolatedValueAtEnd.
- * - * @throws java.lang.Exception if any. - */ @Test void defaultInterpolationWithInterpolatedValueAtEnd() throws Exception { MaptestInterpolationWithSpecifiedBoundaryTokens.
- * - * @throws java.lang.Exception if any. - */ @Test void interpolationWithSpecifiedBoundaryTokens() throws Exception { MaptestInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd.
- * - * @throws java.lang.Exception if any. - */ @Test void interpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd() throws Exception { MaptestInterpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd.
- * - * @throws java.lang.Exception if any. - */ @Test void interpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd() throws Exception { MapMatchPatternTest class.
* * @author Kristian Rosenvold - * @version $Id: $Id * @since 3.4.0 */ class MatchPatternTest { - /** - *testGetSource
- */ @Test void getSource() { MatchPattern mp = MatchPattern.fromString("ABC*"); @@ -45,20 +41,13 @@ void getSource() { assertEquals("[ABC].*", mp.getSource()); } - /** - *testMatchPath.
- * - * @throws java.lang.Exception if any. - */ @Test - void matchPath() throws Exception { + void matchPath() { MatchPattern mp = MatchPattern.fromString("ABC*"); assertTrue(mp.matchPath("ABCD", true)); } /** - *testMatchPatternStart.
- * * @see Issue #63 */ @Test @@ -75,9 +64,6 @@ void matchPatternStart() { assertFalse(mp.matchPatternStart("XXXX", false)); } - /** - *testTokenizePathToString.
- */ @Test void tokenizePathToString() { String[] expected = {"hello", "world"}; diff --git a/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java b/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java index 12caa631..54a4caf2 100644 --- a/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java +++ b/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java @@ -29,13 +29,10 @@ *MatchPatternsTest class.
* * @author herve - * @version $Id: $Id * @since 3.4.0 */ class MatchPatternsTest { - /** - *testGetSource
- */ + @Test void getSources() { ListtestMatches.
- * - * @throws java.lang.Exception if any. - */ @Test - void matches() throws Exception { + void matches() { 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 41bd5f53..3b19ea94 100644 --- a/src/test/java/org/codehaus/plexus/util/OsTest.java +++ b/src/test/java/org/codehaus/plexus/util/OsTest.java @@ -28,21 +28,15 @@ * Test Case for Os * * @author herve - * @version $Id: $Id * @since 3.4.0 */ class OsTest { - /** - *testUndefinedFamily.
- */ + @Test void undefinedFamily() { assertFalse(Os.isFamily("bogus family")); } - /** - *testOs.
- */ @Test void os() { IteratortestValidList.
- */ @Test void validList() { assertTrue(Os.isValidFamily("dos")); diff --git a/src/test/java/org/codehaus/plexus/util/PathToolTest.java b/src/test/java/org/codehaus/plexus/util/PathToolTest.java index 0f5ec253..e829575f 100644 --- a/src/test/java/org/codehaus/plexus/util/PathToolTest.java +++ b/src/test/java/org/codehaus/plexus/util/PathToolTest.java @@ -17,6 +17,9 @@ */ import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.EnabledOnOs; +import org.junit.jupiter.api.condition.OS; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -24,17 +27,12 @@ *PathToolTest class.
* * @author Vincent Siveton - * @version $Id: $Id * @since 3.4.0 */ class PathToolTest { - /** - *testGetRelativePath.
- * - * @throws java.lang.Exception - */ + @Test - void getRelativePath() throws Exception { + void getRelativePath() { assertEquals("", PathTool.getRelativePath(null, null)); assertEquals("", PathTool.getRelativePath(null, "/usr/local/java/bin")); assertEquals("", PathTool.getRelativePath("/usr/local/", null)); @@ -43,23 +41,14 @@ void getRelativePath() throws Exception { assertEquals("", PathTool.getRelativePath("/usr/local/java/bin/java.sh", "/usr/local/")); } - /** - *testGetDirectoryComponent.
- * - * @throws java.lang.Exception - */ @Test - void getDirectoryComponent() throws Exception { + void getDirectoryComponent() { 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.
- * - */ @Test void calculateLink() { assertEquals("../../index.html", PathTool.calculateLink("/index.html", "../..")); @@ -75,13 +64,8 @@ void calculateLink() { PathTool.calculateLink("../index.html", "http://plexus.codehaus.org/plexus-utils")); } - /** - *testGetRelativeWebPath.
- * - * @throws java.lang.Exception - */ @Test - void getRelativeWebPath() throws Exception { + void getRelativeWebPath() { assertEquals("", PathTool.getRelativeWebPath(null, null)); assertEquals("", PathTool.getRelativeWebPath(null, "http://plexus.codehaus.org/")); assertEquals("", PathTool.getRelativeWebPath("http://plexus.codehaus.org/", null)); @@ -95,40 +79,36 @@ void getRelativeWebPath() throws Exception { "http://plexus.codehaus.org/plexus-utils/index.html", "http://plexus.codehaus.org/")); } - /** - *testGetRelativeFilePath.
- * - * @throws java.lang.Exception - */ @Test - 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("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( - "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("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( - "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")); - } + @EnabledOnOs(OS.WINDOWS) + void getRelativeFilePathOnWindows() { + 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( + "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")); + } + + @Test + @DisabledOnOs(OS.WINDOWS) + void getRelativeFilePath() { + 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("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 be29bd1b..bb56ce7e 100644 --- a/src/test/java/org/codehaus/plexus/util/PerfTest.java +++ b/src/test/java/org/codehaus/plexus/util/PerfTest.java @@ -22,7 +22,6 @@ *PerfTest class.
* * @author herve - * @version $Id: $Id * @since 3.4.0 */ class PerfTest { @@ -30,9 +29,6 @@ class PerfTest { private final int oops = 100; - /** - *testSubString.
- */ @Test void subString() { StringBuilder res = new StringBuilder(); @@ -46,9 +42,6 @@ void subString() { System.out.println("i = " + i); } - /** - *testResDir.
- */ @Test void resDir() { StringBuilder res = new StringBuilder(); diff --git a/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java b/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java index 527f7d1a..8565fc61 100644 --- a/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java @@ -27,30 +27,19 @@ * This is used to test ReflectionUtils for correctness. * * @author Jesse McConnell - * @version $Id:$ * @see org.codehaus.plexus.util.ReflectionUtils * @since 3.4.0 */ -public final class ReflectionUtilsTest { +final class ReflectionUtilsTest { private final ReflectionUtilsTestClass testClass = new ReflectionUtilsTestClass(); - /** - *testSimpleVariableAccess.
- * - * @throws java.lang.IllegalAccessException if any. - */ @Test - void simpleVariableAccess() throws IllegalAccessException { + void simpleVariableAccess() throws Exception { assertEquals("woohoo", ReflectionUtils.getValueIncludingSuperclasses("myString", testClass)); } - /** - *testComplexVariableAccess.
- * - * @throws java.lang.IllegalAccessException if any. - */ @Test - void complexVariableAccess() throws IllegalAccessException { + void complexVariableAccess() throws Exception { MaptestSuperClassVariableAccess.
- * - * @throws java.lang.IllegalAccessException if any. - */ @Test - void superClassVariableAccess() throws IllegalAccessException { + void superClassVariableAccess() throws Exception { assertEquals("super-duper", ReflectionUtils.getValueIncludingSuperclasses("mySuperString", testClass)); } - /** - *testSettingVariableValue.
- * - * @throws java.lang.IllegalAccessException if any. - */ @Test - void settingVariableValue() throws IllegalAccessException { + void settingVariableValue() throws Exception { ReflectionUtils.setVariableValueInObject(testClass, "mySettableString", "mySetString"); assertEquals("mySetString", ReflectionUtils.getValueIncludingSuperclasses("mySettableString", testClass)); @@ -87,12 +66,14 @@ void settingVariableValue() throws IllegalAccessException { ReflectionUtils.getValueIncludingSuperclasses("myParentsSettableString", testClass)); } - private class ReflectionUtilsTestClass extends AbstractReflectionUtilsTestClass { + @SuppressWarnings({"FieldMayBeFinal", "FieldCanBeLocal"}) + private static class ReflectionUtilsTestClass extends AbstractReflectionUtilsTestClass { private String myString = "woohoo"; private String mySettableString; + @SuppressWarnings("CanBeFinal") private MaptestExtractPattern.
- */ + @Test void extractPattern() { assertEquals("[A-Z].*", SelectorUtils.extractPattern("%regex[[A-Z].*]", "/")); @@ -44,9 +42,6 @@ void extractPattern() { assertEquals("some\\ABC*", SelectorUtils.extractPattern("%ant[some/ABC*]", "\\")); } - /** - *testIsAntPrefixedPattern.
- */ @Test void isAntPrefixedPattern() { assertTrue(SelectorUtils.isAntPrefixedPattern("%ant[A]")); // single char not allowed @@ -55,9 +50,6 @@ void isAntPrefixedPattern() { assertFalse(SelectorUtils.isAntPrefixedPattern("*")); } - /** - *testIsRegexPrefixedPattern.
- */ @Test void isRegexPrefixedPattern() { assertTrue(SelectorUtils.isRegexPrefixedPattern("%regex[A]")); // single char not allowed @@ -66,9 +58,6 @@ void isRegexPrefixedPattern() { assertFalse(SelectorUtils.isRegexPrefixedPattern("*")); } - /** - *testMatchPath_DefaultFileSeparator.
- */ @Test void matchPathDefaultFileSeparator() { String separator = File.separator; @@ -84,9 +73,6 @@ void matchPathDefaultFileSeparator() { assertTrue(SelectorUtils.matchPath("*" + separator + "a.txt", "b" + separator + "a.txt")); } - /** - *testMatchPath_UnixFileSeparator.
- */ @Test void matchPathUnixFileSeparator() { String separator = "/"; @@ -104,9 +90,6 @@ void matchPathUnixFileSeparator() { assertTrue(SelectorUtils.matchPath("*" + separator + "a.txt", "b" + separator + "a.txt", separator, false)); } - /** - *testMatchPath_WindowsFileSeparator.
- */ @Test void matchPathWindowsFileSeparator() { String separator = "\\"; diff --git a/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java b/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java index 8640fa45..32b5b907 100644 --- a/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java @@ -28,14 +28,11 @@ * Test string utils. * * @author Brett Porter - * @version $Id: $Id * @since 3.4.0 */ class StringUtilsTest { - /** - *testIsEmpty.
- */ + @SuppressWarnings("ConstantValue") @Test void isEmpty() { assertTrue(StringUtils.isEmpty(null)); @@ -45,9 +42,7 @@ void isEmpty() { assertFalse(StringUtils.isEmpty(" foo ")); } - /** - *testIsNotEmpty.
- */ + @SuppressWarnings("ConstantValue") @Test void isNotEmpty() { assertFalse(StringUtils.isNotEmpty(null)); @@ -59,6 +54,7 @@ void isNotEmpty() { @Test void isNotEmptyNegatesIsEmpty() { + //noinspection ConstantValue assertEquals(!StringUtils.isEmpty(null), StringUtils.isNotEmpty(null)); assertEquals(!StringUtils.isEmpty(""), StringUtils.isNotEmpty("")); assertEquals(!StringUtils.isEmpty(" "), StringUtils.isNotEmpty(" ")); @@ -66,9 +62,6 @@ void isNotEmptyNegatesIsEmpty() { assertEquals(!StringUtils.isEmpty(" foo "), StringUtils.isNotEmpty(" foo ")); } - /** - *testIsBlank.
- */ @Test void isBlank() { assertTrue(StringUtils.isBlank(null)); @@ -78,9 +71,6 @@ void isBlank() { assertFalse(StringUtils.isBlank(" foo ")); } - /** - *testIsNotBlank.
- */ @Test void isNotBlank() { assertFalse(StringUtils.isNotBlank(null)); @@ -90,18 +80,12 @@ void isNotBlank() { assertTrue(StringUtils.isNotBlank(" foo ")); } - /** - *testCapitalizeFirstLetter.
- */ @Test void capitalizeFirstLetter() { assertEquals("Id", StringUtils.capitalizeFirstLetter("id")); assertEquals("Id", StringUtils.capitalizeFirstLetter("Id")); } - /** - *testCapitalizeFirstLetterTurkish.
- */ @Test void capitalizeFirstLetterTurkish() { Locale l = Locale.getDefault(); @@ -111,18 +95,12 @@ void capitalizeFirstLetterTurkish() { Locale.setDefault(l); } - /** - *testLowerCaseFirstLetter.
- */ @Test void lowerCaseFirstLetter() { assertEquals("id", StringUtils.lowercaseFirstLetter("id")); assertEquals("id", StringUtils.lowercaseFirstLetter("Id")); } - /** - *testLowerCaseFirstLetterTurkish.
- */ @Test void lowerCaseFirstLetterTurkish() { Locale l = Locale.getDefault(); @@ -132,18 +110,12 @@ void lowerCaseFirstLetterTurkish() { Locale.setDefault(l); } - /** - *testRemoveAndHump.
- */ @Test void removeAndHump() { assertEquals("Id", StringUtils.removeAndHump("id", "-")); assertEquals("SomeId", StringUtils.removeAndHump("some-id", "-")); } - /** - *testRemoveAndHumpTurkish.
- */ @Test void removeAndHumpTurkish() { Locale l = Locale.getDefault(); @@ -153,9 +125,6 @@ void removeAndHumpTurkish() { Locale.setDefault(l); } - /** - *testQuote_EscapeEmbeddedSingleQuotes.
- */ @Test void quoteEscapeEmbeddedSingleQuotes() { String src = "This 'is a' test"; @@ -167,9 +136,6 @@ void quoteEscapeEmbeddedSingleQuotes() { assertEquals(check, result); } - /** - *testQuote_EscapeEmbeddedSingleQuotesWithPattern.
- */ @Test void quoteEscapeEmbeddedSingleQuotesWithPattern() { String src = "This 'is a' test"; @@ -181,9 +147,6 @@ void quoteEscapeEmbeddedSingleQuotesWithPattern() { assertEquals(check, result); } - /** - *testQuote_EscapeEmbeddedDoubleQuotesAndSpaces.
- */ @Test void quoteEscapeEmbeddedDoubleQuotesAndSpaces() { String src = "This \"is a\" test"; @@ -195,9 +158,6 @@ void quoteEscapeEmbeddedDoubleQuotesAndSpaces() { assertEquals(check, result); } - /** - *testQuote_DontQuoteIfUnneeded.
- */ @Test void quoteDontQuoteIfUnneeded() { String src = "ThisIsATest"; @@ -208,9 +168,6 @@ void quoteDontQuoteIfUnneeded() { assertEquals(src, result); } - /** - *testQuote_WrapWithSingleQuotes.
- */ @Test void quoteWrapWithSingleQuotes() { String src = "This is a test"; @@ -222,9 +179,6 @@ void quoteWrapWithSingleQuotes() { assertEquals(check, result); } - /** - *testQuote_PreserveExistingQuotes.
- */ @Test void quotePreserveExistingQuotes() { String src = "'This is a test'"; @@ -235,9 +189,6 @@ void quotePreserveExistingQuotes() { assertEquals(src, result); } - /** - *testQuote_WrapExistingQuotesWhenForceIsTrue.
- */ @Test void quoteWrapExistingQuotesWhenForceIsTrue() { String src = "'This is a test'"; @@ -249,9 +200,6 @@ void quoteWrapExistingQuotesWhenForceIsTrue() { assertEquals(check, result); } - /** - *testQuote_ShortVersion_SingleQuotesPreserved.
- */ @Test void quoteShortVersionSingleQuotesPreserved() { String src = "'This is a test'"; @@ -261,9 +209,6 @@ void quoteShortVersionSingleQuotesPreserved() { assertEquals(src, result); } - /** - *testSplit.
- */ @Test void split() { String[] tokens; @@ -293,13 +238,8 @@ void split() { assertEquals(Arrays.asList("this", "is", "a", "test", "really"), Arrays.asList(tokens)); } - /** - *testRemoveDuplicateWhitespace.
- * - * @throws java.lang.Exception if any. - */ @Test - void removeDuplicateWhitespace() throws Exception { + void removeDuplicateWhitespace() { String s = "this is test "; assertEquals("this is test ", StringUtils.removeDuplicateWhitespace(s)); s = "this \r\n is \n \r test "; @@ -310,21 +250,11 @@ void removeDuplicateWhitespace() throws Exception { assertEquals("this is test ", StringUtils.removeDuplicateWhitespace(s)); } - /** - *testUnifyLineSeparators.
- * - * @throws java.lang.Exception if any. - */ @Test - void unifyLineSeparators() throws Exception { + void unifyLineSeparators() { String s = "this\r\nis\na\r\ntest"; - try { - StringUtils.unifyLineSeparators(s, "abs"); - fail("Exception NOT catched"); - } catch (IllegalArgumentException e) { - assertTrue(true, "Exception catched"); - } + assertThrows(IllegalArgumentException.class, () -> StringUtils.unifyLineSeparators(s, "abs")); assertEquals("this\nis\na\ntest", StringUtils.unifyLineSeparators(s, "\n")); assertEquals("this\r\nis\r\na\r\ntest", StringUtils.unifyLineSeparators(s, "\r\n")); diff --git a/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java b/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java index 3c3bb778..95214cc3 100644 --- a/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java +++ b/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java @@ -33,7 +33,6 @@ * Created on 21/06/2003 * * @author Bert van Brakel - * @version $Id: $Id * @since 3.4.0 */ class SweeperPoolTest { @@ -87,9 +86,6 @@ void maxSize() { assertNotSame(tmp, tmp2, "Expected returned objects to be different"); } - /** - *testSweepAndTrim1.
- */ @Test void sweepAndTrim1() { // test trigger @@ -116,13 +112,8 @@ void sweepAndTrim1() { assertEquals(3, pool.testGetDisposedObjects().size(), "Expected 3 disposed objects"); } - /** - *setUp.
- * - * @throws java.lang.Exception if any. - */ @BeforeEach - void setUp() throws Exception { + void setUp() { o1 = new Object(); o2 = new Object(); o3 = new Object(); @@ -131,19 +122,14 @@ void setUp() throws Exception { o6 = new Object(); } - /** - *tearDown.
- * - * @throws java.lang.Exception if any. - */ @AfterEach - void tearDown() throws Exception { + void tearDown() { pool.dispose(); assertTrue(pool.isDisposed()); pool = null; } - class TestObjectPool extends SweeperPool { + static class TestObjectPool extends SweeperPool { private final Vector