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; - /** Constant DEBUG=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.

- * - * @return a {@link java.lang.Throwable} object. - */ public Throwable getError() { return error; } @@ -98,8 +87,7 @@ public void reset() { while (isRunning) { try { wait(); - } catch (InterruptedException e) { - + } catch (InterruptedException ignored) { } } errorMsg = null; @@ -115,7 +103,7 @@ public void reset() { public final void start() { // shouldn't have multiple threads running this test at the same time synchronized (this) { - if (isRunning == false) { + if (!isRunning) { isRunning = true; Thread t = new Thread(this); t.start(); @@ -123,29 +111,14 @@ public final void start() { } } - /** - *

Getter for the field errorMsg.

- * - * @return a {@link java.lang.String} object. - */ public String getErrorMsg() { return 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.

- * - * @param throwable a {@link java.lang.Throwable} object. - */ public void setError(Throwable throwable) { error = throwable; } - /** - *

Setter for the field errorMsg.

- * - * @param string a {@link java.lang.String} object. - */ public void setErrorMsg(String string) { errorMsg = string; } - /** - *

Setter for the field passed.

- * - * @param b a boolean. - */ public void setPassed(boolean b) { passed = b; } - /** - *

Getter for the field name.

- * - * @return a {@link java.lang.String} object. - */ public String getName() { return name; } - /** - *

Setter for the field name.

- * - * @param string a {@link java.lang.String} object. - */ public void setName(String string) { name = string; } - private final void debug(String msg) { + private void debug(String msg) { if (DEBUG) { System.out.println(this + ":" + msg); } diff --git a/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java b/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java index 953576ef..19e800c1 100644 --- a/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java @@ -32,13 +32,10 @@ *

CollectionUtilsTest class.

* * @author herve - * @version $Id: $Id * @since 3.4.0 */ class CollectionUtilsTest { - /** - *

testMergeMaps.

- */ + @Test void mergeMaps() { Map dominantMap = new HashMap<>(); @@ -74,9 +71,6 @@ void mergeMaps() { assertEquals("z", result.get("z")); } - /** - *

testMergeMapArray.

- */ @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() { List original = new ArrayList<>(); @@ -211,9 +199,6 @@ void iteratorToListWithAPopulatedList() { assertEquals("tre", copy.get(2)); } - /** - *

testIteratorToListWithAEmptyList.

- */ @Test void iteratorToListWithAEmptyList() { List original = new ArrayList<>(); diff --git a/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java b/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java index 5d12b620..fa5ed661 100644 --- a/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java +++ b/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java @@ -42,15 +42,11 @@ * Base class for testcases doing tests with files. * * @author Dan T. Tran - * @version $Id: $Id * @since 3.4.0 */ class DirectoryScannerTest extends FileBasedTestCase { private static final String testDir = getTestDirectory().getPath(); - /** - *

setUp.

- */ @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(List included) { assertTrue(included.contains("symLinkToFileOnTheOutside")); } - /** - *

testFollowSymlinks.

- */ @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 { Map m = new HashMap<>(); @@ -54,11 +48,6 @@ void shouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Excep /* * kenneyw@14-04-2005 Added test to check above fix. */ - /** - *

testShouldNotInterpolateExpressionWithMissingEndToken.

- * - * @throws java.lang.Exception if any. - */ @Test void shouldNotInterpolateExpressionWithMissingEndToken() throws Exception { Map m = new HashMap<>(); @@ -69,11 +58,6 @@ void shouldNotInterpolateExpressionWithMissingEndToken() throws Exception { assertEquals("This is a ${test, really", interpolate(testStr, m)); } - /** - *

testShouldNotInterpolateWithMalformedStartToken.

- * - * @throws java.lang.Exception if any. - */ @Test void shouldNotInterpolateWithMalformedStartToken() throws Exception { Map m = new HashMap<>(); @@ -84,11 +68,6 @@ void shouldNotInterpolateWithMalformedStartToken() throws Exception { assertEquals("This is a $!test} again", interpolate(foo, m)); } - /** - *

testShouldNotInterpolateWithMalformedEndToken.

- * - * @throws java.lang.Exception if any. - */ @Test void shouldNotInterpolateWithMalformedEndToken() throws Exception { Map m = new HashMap<>(); @@ -99,11 +78,6 @@ void shouldNotInterpolateWithMalformedEndToken() throws Exception { assertEquals("This is a ${test!} again", interpolate(foo, m, "${", "$}")); } - /** - *

testInterpolationWithMulticharDelimiters.

- * - * @throws java.lang.Exception if any. - */ @Test void interpolationWithMulticharDelimiters() throws Exception { Map m = new HashMap<>(); @@ -114,11 +88,6 @@ void interpolationWithMulticharDelimiters() throws Exception { assertEquals("This is a testValue again", interpolate(foo, m, "${", "$}")); } - /** - *

testDefaultInterpolationWithNonInterpolatedValueAtEnd.

- * - * @throws java.lang.Exception if any. - */ @Test void defaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { Map m = new HashMap<>(); @@ -130,11 +99,6 @@ void defaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { assertEquals("jason is an asshole. ${not.interpolated}", interpolate(foo, m)); } - /** - *

testDefaultInterpolationWithInterpolatedValueAtEnd.

- * - * @throws java.lang.Exception if any. - */ @Test void defaultInterpolationWithInterpolatedValueAtEnd() throws Exception { Map m = new HashMap<>(); @@ -146,11 +110,6 @@ void defaultInterpolationWithInterpolatedValueAtEnd() throws Exception { assertEquals("jason is an asshole", interpolate(foo, m)); } - /** - *

testInterpolationWithSpecifiedBoundaryTokens.

- * - * @throws java.lang.Exception if any. - */ @Test void interpolationWithSpecifiedBoundaryTokens() throws Exception { Map m = new HashMap<>(); @@ -162,11 +121,6 @@ void interpolationWithSpecifiedBoundaryTokens() throws Exception { assertEquals("jason is an asshole. @not.interpolated@ baby @foo@. @bar@", interpolate(foo, m, "@", "@")); } - /** - *

testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd.

- * - * @throws java.lang.Exception if any. - */ @Test void interpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd() throws Exception { Map m = new HashMap<>(); @@ -178,11 +132,6 @@ void interpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd() thr assertEquals("jason is an @foobarred@", interpolate(foo, m, "@", "@")); } - /** - *

testInterpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd.

- * - * @throws java.lang.Exception if any. - */ @Test void interpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd() throws Exception { Map m = new HashMap<>(); @@ -194,11 +143,6 @@ void interpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd() throws assertEquals("jason is an asshole", interpolate(foo, m, "@", "@")); } - /** - *

testInterpolationWithSpecifiedBoundaryTokensAndAdditionalTokenCharacter.

- * - * @throws java.lang.Exception if any. - */ @Test void interpolationWithSpecifiedBoundaryTokensAndAdditionalTokenCharacter() throws Exception { Map m = new HashMap<>(); @@ -210,10 +154,6 @@ void interpolationWithSpecifiedBoundaryTokensAndAdditionalTokenCharacter() throw assertEquals("jason (known as jason@somewhere) is an asshole", interpolate(foo, m, "@", "@")); } - // ---------------------------------------------------------------------- - // - // ---------------------------------------------------------------------- - private String interpolate(String input, Map context) throws Exception { return IOUtil.toString(new InterpolationFilterReader(new StringReader(input), context)); } diff --git a/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java b/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java index 612d41a8..e5338bbb 100644 --- a/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java +++ b/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java @@ -17,7 +17,6 @@ */ import java.io.BufferedReader; -import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; import java.util.Collections; @@ -33,20 +32,12 @@ * and www.objectfab.de for informations about the tool, the licence and the authors. * * @author herve - * @version $Id: $Id * @since 3.4.0 */ class LineOrientedInterpolatingReaderTest { - /* - * Added and commented by jdcasey@03-Feb-2005 because it is a bug in the InterpolationFilterReader. - */ - /** - *

testShouldInterpolateExpressionAtEndOfDataWithInvalidEndToken.

- * - * @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 { Map m = getStandardMap(); @@ -84,11 +70,6 @@ private Map getStandardMap() { return m; } - /** - *

testDefaultInterpolationWithEscapedExpression.

- * - * @throws java.lang.Exception if any. - */ @Test void defaultInterpolationWithEscapedExpression() throws Exception { Map m = getStandardMap(); @@ -104,11 +85,6 @@ void defaultInterpolationWithEscapedExpression() throws Exception { assertEquals("jason is an asshole. ${noun} value", bar); } - /** - *

testDefaultInterpolationWithInterpolatedValueAtEnd.

- * - * @throws java.lang.Exception if any. - */ @Test void defaultInterpolationWithInterpolatedValueAtEnd() throws Exception { Map m = getStandardMap(); @@ -124,11 +100,6 @@ void defaultInterpolationWithInterpolatedValueAtEnd() throws Exception { assertEquals("jason is an asshole", bar); } - /** - *

testInterpolationWithSpecifiedBoundaryTokens.

- * - * @throws java.lang.Exception if any. - */ @Test void interpolationWithSpecifiedBoundaryTokens() throws Exception { Map m = getStandardMap(); @@ -145,11 +116,6 @@ void interpolationWithSpecifiedBoundaryTokens() throws Exception { assertEquals("jason is an asshole. @not.interpolated@ baby @foo@. @bar@", bar); } - /** - *

testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd.

- * - * @throws java.lang.Exception if any. - */ @Test void interpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd() throws Exception { Map m = getStandardMap(); @@ -166,11 +132,6 @@ void interpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd() thr assertEquals("jason is an @foobarred@", bar); } - /** - *

testInterpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd.

- * - * @throws java.lang.Exception if any. - */ @Test void interpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd() throws Exception { Map m = getStandardMap(); diff --git a/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java b/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java index 2d67e0bf..09b34f04 100644 --- a/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java +++ b/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java @@ -27,14 +27,10 @@ *

MatchPatternTest 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() { List expected = Arrays.asList("ABC**", "some/ABC*", "[ABC].*"); @@ -44,13 +41,8 @@ void getSources() { assertEquals(expected, actual); } - /** - *

testMatches.

- * - * @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() { Iterator iter = Os.getValidFamilies().iterator(); @@ -82,9 +76,6 @@ void os() { assertFalse(Os.isOs(currentFamily, Os.OS_NAME, Os.OS_ARCH, "myversion")); } - /** - *

testValidList.

- */ @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 { Map map = ReflectionUtils.getVariablesAndValuesIncludingSuperclasses(testClass); Map myMap = (Map) map.get("myMap"); @@ -59,23 +48,13 @@ void complexVariableAccess() throws IllegalAccessException { assertEquals("myOtherValue", myMap.get("myOtherKey")); } - /** - *

testSuperClassVariableAccess.

- * - * @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 Map myMap = new HashMap<>(); public ReflectionUtilsTestClass() { @@ -101,7 +82,8 @@ public ReflectionUtilsTestClass() { } } - private class AbstractReflectionUtilsTestClass { + @SuppressWarnings("FieldMayBeFinal") + private static class AbstractReflectionUtilsTestClass { private String mySuperString = "super-duper"; private String myParentsSettableString; diff --git a/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java b/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java index 1185d60d..db07559e 100644 --- a/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java @@ -31,9 +31,7 @@ * @since 3.4.0 */ class SelectorUtilsTest { - /** - *

testExtractPattern.

- */ + @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 disposedObjects = new Vector<>(); public TestObjectPool(int maxSize, int minSize, int intialCapacity, int sweepInterval, int triggerSize) { @@ -154,9 +140,6 @@ public void reset() { disposedObjects.clear(); } - /** - * @see nz.co.bonzo.beans.castor.pool.ObjectPool#objectDisposed(java.lang.Object) - */ public void objectDisposed(Object obj) { disposedObjects.add(obj); } diff --git a/src/test/java/org/codehaus/plexus/util/TestThreadManager.java b/src/test/java/org/codehaus/plexus/util/TestThreadManager.java index b9ee75b8..9b957884 100644 --- a/src/test/java/org/codehaus/plexus/util/TestThreadManager.java +++ b/src/test/java/org/codehaus/plexus/util/TestThreadManager.java @@ -18,7 +18,6 @@ import java.util.Collection; import java.util.Vector; -import java.util.logging.Logger; /** * Manages a number of test threads, which notify this manager when they have completed. Allows TestCases to easily @@ -28,11 +27,9 @@ *

* * @author Bert van Brakel - * @version $Id: $Id * @since 3.4.0 */ public class TestThreadManager { - // ~ Instance fields ---------------------------------------------------------------------------- /** Test threads which have completed running */ private Collection runThreads = new Vector(); @@ -40,8 +37,6 @@ public class TestThreadManager { /** Test threads still needing to be run, or are currently running */ private Collection toRunThreads = new Vector(); - private Logger logger = null; - /** Any test threads which failed */ private Vector failedThreads = new Vector(); @@ -51,32 +46,15 @@ public class TestThreadManager { */ private Object notify = null; - // ~ Constructors ------------------------------------------------------------------------------- - - /** - *

Constructor for TestThreadManager.

- * - * @param notify a {@link java.lang.Object} object. - */ public TestThreadManager(Object notify) { super(); this.notify = notify; } - // ~ Methods ------------------------------------------------------------------------------------ - - /** - *

Getter for the field runThreads.

- * - * @return a {@link java.util.Collection} object. - */ public Collection getRunThreads() { return runThreads; } - /** - *

runTestThreads.

- */ public void runTestThreads() { failedThreads.clear(); // use an array as the tests may run very quickly @@ -88,11 +66,6 @@ public void runTestThreads() { } } - /** - *

getFailedTests.

- * - * @return a {@link java.util.Collection} object. - */ public Collection getFailedTests() { return failedThreads; } @@ -106,51 +79,24 @@ public Object getNotifyObject() { return notify; } - /** - *

hasFailedThreads.

- * - * @return a boolean. - */ public boolean hasFailedThreads() { return !failedThreads.isEmpty(); } - /** - * Determine if any threads are still running! - * - * @return DOCUMENT ME! - */ public boolean isStillRunningThreads() { return !toRunThreads.isEmpty(); } - /** - *

Getter for the field toRunThreads.

- * - * @return a {@link java.util.Collection} object. - */ public Collection getToRunThreads() { return toRunThreads; } - /** - * DOCUMENT ME! - */ public void clear() { toRunThreads.clear(); runThreads.clear(); failedThreads.clear(); } - /* - * (non-Javadoc) - * @see java.util.Collection#remove(java.lang.Object) - */ - /** - *

completed.

- * - * @param thread a {@link org.codehaus.plexus.util.AbstractTestThread} object. - */ public synchronized void completed(AbstractTestThread thread) { toRunThreads.remove(thread); runThreads.add(thread); @@ -173,11 +119,6 @@ public synchronized void completed(AbstractTestThread thread) { */ public void doRegisterThread(AbstractTestThread thread) {} - /** - *

registerThread.

- * - * @param thread a {@link org.codehaus.plexus.util.AbstractTestThread} object. - */ public final void registerThread(AbstractTestThread thread) { thread.setThreadRegistry(this); if (toRunThreads.contains(thread) == false) { diff --git a/src/test/java/org/codehaus/plexus/util/Tracer.java b/src/test/java/org/codehaus/plexus/util/Tracer.java index d5ff964d..a7b5dcc0 100644 --- a/src/test/java/org/codehaus/plexus/util/Tracer.java +++ b/src/test/java/org/codehaus/plexus/util/Tracer.java @@ -26,7 +26,6 @@ *

* * @author Bert van Brakel - * @version $Id: $Id * @since 3.4.0 */ public class Tracer { diff --git a/src/test/java/org/codehaus/plexus/util/WalkCollector.java b/src/test/java/org/codehaus/plexus/util/WalkCollector.java index 183e7f94..81c6ad20 100644 --- a/src/test/java/org/codehaus/plexus/util/WalkCollector.java +++ b/src/test/java/org/codehaus/plexus/util/WalkCollector.java @@ -33,25 +33,20 @@ class WalkCollector implements DirectoryWalkListener { public int percentageHigh; - /** - *

Constructor for WalkCollector.

- */ public WalkCollector() { - steps = new ArrayList(); + steps = new ArrayList<>(); startCount = 0; finishCount = 0; percentageLow = 0; percentageHigh = 0; } - /** {@inheritDoc} */ public void directoryWalkStarting(File basedir) { debug("Walk Starting: " + basedir); startCount++; startingDir = basedir; } - /** {@inheritDoc} */ public void directoryWalkStep(int percentage, File file) { percentageLow = Math.min(percentageLow, percentage); percentageHigh = Math.max(percentageHigh, percentage); @@ -59,15 +54,11 @@ public void directoryWalkStep(int percentage, File file) { steps.add(file); } - /** - *

directoryWalkFinished.

- */ public void directoryWalkFinished() { debug("Walk Finished."); finishCount++; } - /** {@inheritDoc} */ public void debug(String message) { System.out.println(message); } 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 a63adfab..77620d20 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java @@ -20,19 +20,16 @@ import java.util.Locale; import java.util.Properties; -import org.codehaus.plexus.util.Os; -import org.junit.jupiter.api.Assertions; 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.assertNotNull; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.*; /** *

CommandLineUtilsTest class.

* * @author herve - * @version $Id: $Id * @since 3.4.0 */ @SuppressWarnings({"deprecation"}) @@ -43,7 +40,7 @@ class CommandLineUtilsTest { */ @Test void quoteArguments() { - Assertions.assertDoesNotThrow(() -> { + assertDoesNotThrow(() -> { String result = CommandLineUtils.quote("Hello"); System.out.println(result); assertEquals("Hello", result); @@ -54,20 +51,15 @@ void quoteArguments() { System.out.println(result); assertEquals("'\"Hello World\"'", result); }); - try { - CommandLineUtils.quote("\"Hello 'World''"); - fail(); - } catch (Exception ignored) { - } + + assertThrows(CommandLineException.class, () -> CommandLineUtils.quote("\"Hello 'World''")); } /** * Tests that case-insensitive environment variables are normalized to upper case. - * - * @throws java.lang.Exception if any. */ @Test - void getSystemEnvVarsCaseInsensitive() throws Exception { + void getSystemEnvVarsCaseInsensitive() { Properties vars = CommandLineUtils.getSystemEnvVars(false); for (Object o : vars.keySet()) { String variable = (String) o; @@ -77,14 +69,10 @@ void getSystemEnvVarsCaseInsensitive() throws Exception { /** * Tests that environment variables on Windows are normalized to upper case. Does nothing on Unix platforms. - * - * @throws java.lang.Exception if any. */ @Test - void getSystemEnvVarsWindows() throws Exception { - if (!Os.isFamily(Os.FAMILY_WINDOWS)) { - return; - } + @EnabledOnOs(OS.WINDOWS) + void getSystemEnvVarsWindows() { Properties vars = CommandLineUtils.getSystemEnvVars(); for (Object o : vars.keySet()) { String variable = (String) o; @@ -94,8 +82,6 @@ void getSystemEnvVarsWindows() throws Exception { /** * Tests the splitting of a command line into distinct arguments. - * - * @throws java.lang.Exception if any. */ @Test void translateCommandline() throws Exception { 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 ac2ef781..95862478 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java @@ -29,6 +29,8 @@ import org.codehaus.plexus.util.cli.shell.Shell; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.OS; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -38,17 +40,11 @@ *

CommandlineTest class.

* * @author herve - * @version $Id: $Id * @since 3.4.0 */ class CommandlineTest { private String baseDir; - /** - *

setUp.

- * - * @throws java.lang.Exception if any. - */ @BeforeEach void setUp() throws Exception { baseDir = System.getProperty("basedir"); @@ -58,9 +54,7 @@ void setUp() throws Exception { } } - /** - *

testCommandlineWithoutCommandInConstructor.

- */ + @SuppressWarnings("deprecation") @Test void commandlineWithoutCommandInConstructor() { Commandline cmd = new Commandline(new Shell()); @@ -72,9 +66,6 @@ void commandlineWithoutCommandInConstructor() { assertEquals("cd .", cmd.toString()); } - /** - *

testCommandlineWithCommandInConstructor.

- */ @Test void commandlineWithCommandInConstructor() { Commandline cmd = new Commandline("cd .", new Shell()); @@ -84,11 +75,6 @@ void commandlineWithCommandInConstructor() { assertEquals("cd .", cmd.toString()); } - /** - *

testExecuteBinaryOnPath.

- * - * @throws java.lang.Exception if any. - */ @Test void executeBinaryOnPath() throws Exception { // Maven startup script on PATH is required for this test @@ -104,11 +90,7 @@ void executeBinaryOnPath() throws Exception { assertTrue(out.contains("Java version:")); } - /** - *

testExecute.

- * - * @throws java.lang.Exception if any. - */ + @SuppressWarnings("deprecation") @Test void execute() throws Exception { // allow it to detect the proper shell here. @@ -122,9 +104,7 @@ void execute() throws Exception { assertEquals("Hello", IOUtil.toString(process.getInputStream()).trim()); } - /** - *

testSetLine.

- */ + @SuppressWarnings("deprecation") @Test void setLine() { Commandline cmd = new Commandline(new Shell()); @@ -137,9 +117,7 @@ void setLine() { assertEquals("echo Hello", cmd.toString()); } - /** - *

testCreateCommandInReverseOrder.

- */ + @SuppressWarnings("deprecation") @Test void createCommandInReverseOrder() { Commandline cmd = new Commandline(new Shell()); @@ -151,9 +129,7 @@ void createCommandInReverseOrder() { assertEquals("cd .", cmd.toString()); } - /** - *

testSetFile.

- */ + @SuppressWarnings("deprecation") @Test void setFile() { Commandline cmd = new Commandline(new Shell()); @@ -170,13 +146,8 @@ void setFile() { assertEquals("more " + fileName, cmd.toString()); } - /** - *

testGetShellCommandLineWindows.

- * - * @throws java.lang.Exception if any. - */ @Test - void getShellCommandLineWindows() throws Exception { + void getShellCommandLineWindows() { Commandline cmd = new Commandline(new CmdShell()); cmd.setExecutable("c:\\Program Files\\xxx"); cmd.addArguments(new String[] {"a", "b"}); @@ -193,13 +164,8 @@ void getShellCommandLineWindows() throws Exception { assertEquals(expectedShellCmd, shellCommandline[4]); } - /** - *

testGetShellCommandLineWindowsWithSeveralQuotes.

- * - * @throws java.lang.Exception if any. - */ @Test - void getShellCommandLineWindowsWithSeveralQuotes() throws Exception { + void getShellCommandLineWindowsWithSeveralQuotes() { Commandline cmd = new Commandline(new CmdShell()); cmd.setExecutable("c:\\Program Files\\xxx"); cmd.addArguments(new String[] {"c:\\Documents and Settings\\whatever", "b"}); @@ -219,11 +185,9 @@ void getShellCommandLineWindowsWithSeveralQuotes() throws Exception { /** * Test the command line generated for the bash shell - * - * @throws java.lang.Exception */ @Test - void getShellCommandLineBash() throws Exception { + void getShellCommandLineBash() { Commandline cmd = new Commandline(new BourneShell()); cmd.setExecutable("/bin/echo"); cmd.addArguments(new String[] {"hello world"}); @@ -243,11 +207,9 @@ void getShellCommandLineBash() throws Exception { /** * Test the command line generated for the bash shell - * - * @throws java.lang.Exception */ @Test - void getShellCommandLineBashWithWorkingDirectory() throws Exception { + void getShellCommandLineBashWithWorkingDirectory() { Commandline cmd = new Commandline(new BourneShell()); cmd.setExecutable("/bin/echo"); cmd.addArguments(new String[] {"hello world"}); @@ -270,11 +232,9 @@ void getShellCommandLineBashWithWorkingDirectory() throws Exception { /** * Test the command line generated for the bash shell - * - * @throws java.lang.Exception */ @Test - void getShellCommandLineBashWithSingleQuotedArg() throws Exception { + void getShellCommandLineBashWithSingleQuotedArg() { Commandline cmd = new Commandline(new BourneShell()); cmd.setExecutable("/bin/echo"); cmd.addArguments(new String[] {"'hello world'"}); @@ -292,13 +252,8 @@ void getShellCommandLineBashWithSingleQuotedArg() throws Exception { assertEquals(expectedShellCmd, shellCommandline[2]); } - /** - *

testGetShellCommandLineNonWindows.

- * - * @throws java.lang.Exception if any. - */ @Test - void getShellCommandLineNonWindows() throws Exception { + void getShellCommandLineNonWindows() { Commandline cmd = new Commandline(new BourneShell()); cmd.setExecutable("/usr/bin"); cmd.addArguments(new String[] {"a", "b"}); @@ -316,11 +271,6 @@ void getShellCommandLineNonWindows() throws Exception { } } - /** - *

testEnvironment.

- * - * @throws java.lang.Exception if any. - */ @Test void environment() throws Exception { Commandline cmd = new Commandline(); @@ -328,11 +278,6 @@ void environment() throws Exception { assertEquals("name=value", cmd.getEnvironmentVariables()[0]); } - /** - *

testEnvironmentWitOverrideSystemEnvironment.

- * - * @throws java.lang.Exception if any. - */ @Test void environmentWitOverrideSystemEnvironment() throws Exception { Commandline cmd = new Commandline(); @@ -351,8 +296,6 @@ void environmentWitOverrideSystemEnvironment() throws Exception { /** * Test an executable with a single apostrophe ' in its path - * - * @throws java.lang.Exception */ @Test void quotedPathWithSingleApostrophe() throws Exception { @@ -365,8 +308,6 @@ void quotedPathWithSingleApostrophe() throws Exception { /** * Test an executable with shell-expandable content in its path. - * - * @throws java.lang.Exception */ @Test void pathWithShellExpansionStrings() throws Exception { @@ -376,16 +317,10 @@ void pathWithShellExpansionStrings() throws Exception { /** * Test an executable with a single quotation mark \" in its path only for non Windows box. - * - * @throws java.lang.Exception */ @Test + @DisabledOnOs(OS.WINDOWS) void quotedPathWithQuotationMark() throws Exception { - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - System.out.println("testQuotedPathWithQuotationMark() skipped on Windows"); - return; - } - File dir = new File(System.getProperty("basedir"), "target/test/quotedpath\"test"); createAndCallScript(dir, "echo Quoted"); @@ -396,16 +331,10 @@ void quotedPathWithQuotationMark() throws Exception { /** * Test an executable with a single quotation mark \" and ' in its path only for non * Windows box. - * - * @throws java.lang.Exception */ @Test + @DisabledOnOs(OS.WINDOWS) void quotedPathWithQuotationMarkAndApostrophe() throws Exception { - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - System.out.println("testQuotedPathWithQuotationMarkAndApostrophe() skipped on Windows"); - return; - } - File dir = new File(System.getProperty("basedir"), "target/test/quotedpath\"'test"); createAndCallScript(dir, "echo Quoted"); @@ -415,8 +344,6 @@ void quotedPathWithQuotationMarkAndApostrophe() throws Exception { /** * Test an executable with a quote in its path and no space - * - * @throws java.lang.Exception */ @Test void onlyQuotedPath() throws Exception { @@ -442,11 +369,6 @@ void onlyQuotedPath() throws Exception { createAndCallScript(dir, javaBinStr + " -version"); } - /** - *

testDollarSignInArgumentPath.

- * - * @throws java.lang.Exception if any. - */ @Test void dollarSignInArgumentPath() throws Exception { File dir = new File(System.getProperty("basedir"), "target/test"); @@ -454,12 +376,8 @@ void dollarSignInArgumentPath() throws Exception { assertTrue(dir.mkdirs(), "Can't create dir:" + dir.getAbsolutePath()); } - Writer writer = null; - try { - writer = Files.newBufferedWriter(dir.toPath().resolve("test$1.txt")); + try (Writer writer = Files.newBufferedWriter(dir.toPath().resolve("test$1.txt"))) { IOUtil.copy("Success", writer); - } finally { - IOUtil.close(writer); } Commandline cmd = new Commandline(); @@ -475,11 +393,6 @@ void dollarSignInArgumentPath() throws Exception { executeCommandLine(cmd); } - /** - *

testTimeOutException.

- * - * @throws java.lang.Exception if any. - */ @Test void timeOutException() throws Exception { File javaHome = new File(System.getProperty("java.home")); @@ -555,11 +468,8 @@ private static void createAndCallScript(File dir, String content) throws Excepti bat = new File(dir, "echo"); } - Writer w = Files.newBufferedWriter(bat.toPath()); - try { + try (Writer w = Files.newBufferedWriter(bat.toPath())) { IOUtil.copy(content, w); - } finally { - IOUtil.close(w); } // Change permission 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 fae942ef..558aeb32 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/DefaultConsumerTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/DefaultConsumerTest.java @@ -22,15 +22,10 @@ *

DefaultConsumerTest class.

* * @author herve - * @version $Id: $Id * @since 3.4.0 */ class DefaultConsumerTest { - /** - *

testConsumeLine.

- * - * @throws java.lang.Exception if any. - */ + @Test void consumeLine() throws Exception { DefaultConsumer cons = new DefaultConsumer(); 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 4f7b6ddd..da592b2d 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizerTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizerTest.java @@ -16,23 +16,20 @@ * limitations under the License. */ +import java.util.NoSuchElementException; + import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.*; /** *

EnhancedStringTokenizerTest class.

* * @author herve - * @version $Id: $Id * @since 3.4.0 */ class EnhancedStringTokenizerTest { - /** - *

test1.

- */ + @Test void test1() { EnhancedStringTokenizer est = new EnhancedStringTokenizer("this is a test string"); @@ -44,9 +41,6 @@ void test1() { assertEquals("this is a test string ", sb.toString()); } - /** - *

test2.

- */ @Test void test2() { EnhancedStringTokenizer est = new EnhancedStringTokenizer("1,,,3,,4", ","); @@ -58,9 +52,6 @@ void test2() { assertEquals("4", est.nextToken(), "Token 6"); } - /** - *

test3.

- */ @Test void test3() { EnhancedStringTokenizer est = new EnhancedStringTokenizer("1,,,3,,4", ",", true); @@ -77,9 +68,6 @@ void test3() { assertEquals("4", est.nextToken(), "Token 11"); } - /** - *

testMultipleDelim.

- */ @Test void multipleDelim() { EnhancedStringTokenizer est = new EnhancedStringTokenizer("1 2|3|4", " |", true); @@ -93,23 +81,13 @@ void multipleDelim() { assertFalse(est.hasMoreTokens(), "est.hasMoreTokens()"); } - /** - *

testEmptyString.

- */ @Test void emptyString() { EnhancedStringTokenizer est = new EnhancedStringTokenizer(""); assertFalse(est.hasMoreTokens(), "est.hasMoreTokens()"); - try { - est.nextToken(); - fail(); - } catch (Exception ignored) { - } + assertThrows(NoSuchElementException.class, est::nextToken); } - /** - *

testSimpleString.

- */ @Test void simpleString() { EnhancedStringTokenizer est = new EnhancedStringTokenizer("a "); 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 7cbba879..51f54b87 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java @@ -4,24 +4,24 @@ * 651 W Washington Ave. Suite 500 * Chicago, IL 60661 USA * All rights reserved. - * + *

* Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + *

* + Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * + *

* + Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. - * + *

* + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the * names of its contributors may be used to endorse or promote * products derived from this software without specific prior * written permission. - * + *

* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -53,7 +53,6 @@ */ import java.io.ByteArrayInputStream; -import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.StringWriter; @@ -70,15 +69,11 @@ *

StreamPumperTest class.

* * @author Paul Julius - * @version $Id: $Id * @since 3.4.0 */ class StreamPumperTest { private final String lineSeparator = System.lineSeparator(); - /** - *

testPumping.

- */ @Test void pumping() { String line1 = "line1"; @@ -95,9 +90,6 @@ void pumping() { assertTrue(consumer.wasLineConsumed(line2, 1000)); } - /** - *

testPumpingWithPrintWriter.

- */ @Test void pumpingWithPrintWriter() { String inputString = "This a test string"; @@ -112,9 +104,6 @@ void pumpingWithPrintWriter() { pumper.close(); } - /** - *

testPumperReadsInputStreamUntilEndEvenIfConsumerFails.

- */ @Test void pumperReadsInputStreamUntilEndEvenIfConsumerFails() { // the number of bytes generated should surely exceed the read buffer used by the pumper @@ -138,7 +127,7 @@ public GeneratorInputStream(int size) { this.size = size; } - public int read() throws IOException { + public int read() { if (read < size) { read++; return '\n'; @@ -147,7 +136,7 @@ public int read() throws IOException { } } - public void close() throws IOException { + public void close() { closed = true; } } 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 6c2e3a8e..34fd80dc 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 @@ -30,23 +30,14 @@ *

BourneShellTest class.

* * @author herve - * @version $Id: $Id * @since 3.4.0 */ class BourneShellTest { - /** - *

newShell.

- * - * @return a {@link org.codehaus.plexus.util.cli.shell.Shell} object. - */ protected Shell newShell() { return new BourneShell(); } - /** - *

testQuoteWorkingDirectoryAndExecutable.

- */ @Test void quoteWorkingDirectoryAndExecutable() { Shell sh = newShell(); @@ -60,9 +51,6 @@ void quoteWorkingDirectoryAndExecutable() { assertEquals("/bin/sh -c cd '/usr/local/bin' && 'chmod'", executable); } - /** - *

testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes.

- */ @Test void quoteWorkingDirectoryAndExecutableWDPathWithSingleQuotes() { Shell sh = newShell(); @@ -76,9 +64,6 @@ void quoteWorkingDirectoryAndExecutableWDPathWithSingleQuotes() { assertEquals("/bin/sh -c cd '/usr/local/'\"'\"'something else'\"'\"'' && 'chmod'", executable); } - /** - *

testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes_BackslashFileSep.

- */ @Test void quoteWorkingDirectoryAndExecutableWDPathWithSingleQuotesBackslashFileSep() { Shell sh = newShell(); @@ -92,9 +77,6 @@ void quoteWorkingDirectoryAndExecutableWDPathWithSingleQuotesBackslashFileSep() assertEquals("/bin/sh -c cd '\\usr\\local\\'\"'\"'something else'\"'\"'' && 'chmod'", executable); } - /** - *

testPreserveSingleQuotesOnArgument.

- */ @Test void preserveSingleQuotesOnArgument() { Shell sh = newShell(); @@ -111,9 +93,6 @@ void preserveSingleQuotesOnArgument() { assertTrue(cli.endsWith("''\"'\"'some arg with spaces'\"'\"''")); } - /** - *

testAddSingleQuotesOnArgumentWithSpaces.

- */ @Test void addSingleQuotesOnArgumentWithSpaces() { Shell sh = newShell(); @@ -130,9 +109,6 @@ void addSingleQuotesOnArgumentWithSpaces() { assertTrue(cli.endsWith("'" + args[0] + "'")); } - /** - *

testEscapeSingleQuotesOnArgument.

- */ @Test void escapeSingleQuotesOnArgument() { Shell sh = newShell(); @@ -150,9 +126,6 @@ void escapeSingleQuotesOnArgument() { "cd '/usr/bin' && 'chmod' 'arg'\"'\"'withquote'", shellCommandLine.get(shellCommandLine.size() - 1)); } - /** - *

testArgumentsWithsemicolon.

- */ @Test void argumentsWithsemicolon() { @@ -210,11 +183,6 @@ void argumentsWithsemicolon() { assertEquals("\"--password ;password\"", lines[4]); } - /** - *

testBourneShellQuotingCharacters.

- * - * @throws java.lang.Exception if any. - */ @Test void bourneShellQuotingCharacters() throws Exception { // { ' ', '$', ';', '&', '|', '<', '>', '*', '?', '(', ')' }; 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 97ddfcec..85245d06 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java @@ -27,13 +27,10 @@ *

CycleDetectedExceptionTest class.

* * @author Jason van Zyl - * @version $Id: $Id * @since 3.4.0 */ class CycleDetectedExceptionTest { - /** - *

testException.

- */ + @Test void exception() { final List cycle = new ArrayList<>(); 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 e900ca83..57c8e484 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java @@ -18,9 +18,9 @@ import java.util.List; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -31,21 +31,17 @@ *

CycleDetectorTest class.

* * @author Michal Maczka - * @version $Id: $Id * @since 3.4.0 */ class CycleDetectorTest { - /** - *

testCycyleDetection.

- */ @Test void cycyleDetection() { // No cycle // // a --> b --->c // - Assertions.assertDoesNotThrow( + assertDoesNotThrow( () -> { final DAG dag1 = new DAG(); @@ -89,7 +85,7 @@ void cycyleDetection() { // a --> b // | | --> d // ---------> - Assertions.assertDoesNotThrow( + assertDoesNotThrow( () -> { final DAG dag3 = new DAG(); 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 7f0cf922..ed7573d1 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java @@ -30,17 +30,12 @@ *

DAGTest class.

* * @author Michal Maczka - * @version $Id: $Id * @since 3.4.0 */ class DAGTest { - /** - *

testDAG.

- * - * @throws org.codehaus.plexus.util.dag.CycleDetectedException if any. - */ + @Test - void dag() throws CycleDetectedException { + void dag() throws Exception { final DAG dag = new DAG(); dag.addVertex("a"); @@ -140,13 +135,8 @@ void dag() throws CycleDetectedException { assertTrue(d.getParentLabels().contains("c")); } - /** - *

testGetPredecessors.

- * - * @throws org.codehaus.plexus.util.dag.CycleDetectedException if any. - */ @Test - void getPredecessors() throws CycleDetectedException { + void getPredecessors() throws Exception { 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 02bd14cd..bb8aee29 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java @@ -27,17 +27,12 @@ *

TopologicalSorterTest class.

* * @author Michal Maczka - * @version $Id: $Id * @since 3.4.0 */ class TopologicalSorterTest { - /** - *

testDfs.

- * - * @throws org.codehaus.plexus.util.dag.CycleDetectedException if any. - */ + @Test - void dfs() throws CycleDetectedException { + void dfs() throws Exception { // a --> b --->c // // result a,b,c 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 9263d46e..ef626086 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/VertexTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/VertexTest.java @@ -24,13 +24,10 @@ *

VertexTest class.

* * @author Michal Maczka - * @version $Id: $Id * @since 3.4.0 */ class VertexTest { - /** - *

testVertex.

- */ + @Test void vertex() { 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 69aa1d5c..be6cd610 100644 --- a/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java +++ b/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java @@ -24,27 +24,19 @@ import org.junit.jupiter.api.BeforeEach; 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.assertNull; +import static org.junit.jupiter.api.Assertions.*; /** *

ReflectionValueExtractorTest class.

* * @author Jason van Zyl - * @version $Id: $Id * @since 3.4.0 */ class ReflectionValueExtractorTest { private Project project; - /** - *

setUp.

- * - * @throws java.lang.Exception if any. - */ @BeforeEach - void setUp() throws Exception { + void setUp() { Dependency dependency1 = new Dependency(); dependency1.setArtifactId("dep1"); Dependency dependency2 = new Dependency(); @@ -68,11 +60,6 @@ void setUp() throws Exception { project.addArtifact(new Artifact("g2", "a2", "v2", "e2", "c2")); } - /** - *

testValueExtraction.

- * - * @throws java.lang.Exception if any. - */ @Test void valueExtraction() throws Exception { // ---------------------------------------------------------------------- @@ -153,11 +140,6 @@ void valueExtraction() throws Exception { assertNotNull(build); } - /** - *

testValueExtractorWithAInvalidExpression.

- * - * @throws java.lang.Exception if any. - */ @Test void valueExtractorWithAInvalidExpression() throws Exception { assertNull(ReflectionValueExtractor.evaluate("project.foo", project)); @@ -165,11 +147,6 @@ void valueExtractorWithAInvalidExpression() throws Exception { assertNull(ReflectionValueExtractor.evaluate("project.dependencies[0].foo", project)); } - /** - *

testMappedDottedKey.

- * - * @throws java.lang.Exception if any. - */ @Test void mappedDottedKey() throws Exception { Map map = new HashMap<>(); @@ -178,11 +155,6 @@ void mappedDottedKey() throws Exception { assertEquals("a.b-value", ReflectionValueExtractor.evaluate("h.value(a.b)", new ValueHolder(map))); } - /** - *

testIndexedMapped.

- * - * @throws java.lang.Exception if any. - */ @Test void indexedMapped() throws Exception { Map map = new HashMap<>(); @@ -193,11 +165,6 @@ void indexedMapped() throws Exception { assertEquals("a-value", ReflectionValueExtractor.evaluate("h.value[0](a)", new ValueHolder(list))); } - /** - *

testMappedIndexed.

- * - * @throws java.lang.Exception if any. - */ @Test void mappedIndexed() throws Exception { List list = new ArrayList<>(); @@ -207,11 +174,6 @@ void mappedIndexed() throws Exception { assertEquals("a-value", ReflectionValueExtractor.evaluate("h.value(a)[0]", new ValueHolder(map))); } - /** - *

testMappedMissingDot.

- * - * @throws java.lang.Exception if any. - */ @Test void mappedMissingDot() throws Exception { Map map = new HashMap<>(); @@ -219,11 +181,6 @@ void mappedMissingDot() throws Exception { assertNull(ReflectionValueExtractor.evaluate("h.value(a)value", new ValueHolder(map))); } - /** - *

testIndexedMissingDot.

- * - * @throws java.lang.Exception if any. - */ @Test void indexedMissingDot() throws Exception { List list = new ArrayList<>(); @@ -231,21 +188,11 @@ void indexedMissingDot() throws Exception { assertNull(ReflectionValueExtractor.evaluate("h.value[0]value", new ValueHolder(list))); } - /** - *

testDotDot.

- * - * @throws java.lang.Exception if any. - */ @Test void dotDot() throws Exception { assertNull(ReflectionValueExtractor.evaluate("h..value", new ValueHolder("value"))); } - /** - *

testBadIndexedSyntax.

- * - * @throws java.lang.Exception if any. - */ @Test void badIndexedSyntax() throws Exception { List list = new ArrayList<>(); @@ -260,11 +207,6 @@ void badIndexedSyntax() throws Exception { assertNull(ReflectionValueExtractor.evaluate("h.value[-1]", value)); } - /** - *

testBadMappedSyntax.

- * - * @throws java.lang.Exception if any. - */ @Test void badMappedSyntax() throws Exception { Map map = new HashMap<>(); @@ -277,49 +219,24 @@ void badMappedSyntax() throws Exception { assertNull(ReflectionValueExtractor.evaluate("h.value(a]", value)); } - /** - *

testIllegalIndexedType.

- * - * @throws java.lang.Exception if any. - */ @Test - void illegalIndexedType() throws Exception { - try { - ReflectionValueExtractor.evaluate("h.value[1]", new ValueHolder("string")); - } catch (Exception e) { - // TODO assert exception message - } + void illegalIndexedType() { + // TODO assert exception message + assertThrows(Exception.class, () -> ReflectionValueExtractor.evaluate("h.value[1]", new ValueHolder("string"))); } - /** - *

testIllegalMappedType.

- * - * @throws java.lang.Exception if any. - */ @Test - void illegalMappedType() throws Exception { - try { - ReflectionValueExtractor.evaluate("h.value(key)", new ValueHolder("string")); - } catch (Exception e) { - // TODO assert exception message - } + void illegalMappedType() { + // TODO assert exception message + assertThrows( + Exception.class, () -> ReflectionValueExtractor.evaluate("h.value(key)", new ValueHolder("string"))); } - /** - *

testTrimRootToken.

- * - * @throws java.lang.Exception if any. - */ @Test void trimRootToken() throws Exception { assertNull(ReflectionValueExtractor.evaluate("project", project, true)); } - /** - *

testArtifactMap.

- * - * @throws java.lang.Exception if any. - */ @Test void artifactMap() throws Exception { assertEquals( @@ -547,11 +464,6 @@ public Object getValue() { } } - /** - *

testRootPropertyRegression.

- * - * @throws java.lang.Exception if any. - */ @Test void rootPropertyRegression() throws Exception { Project project = new 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 11da4e05..4bfda2cc 100644 --- a/src/test/java/org/codehaus/plexus/util/io/CachingOutputStreamTest.java +++ b/src/test/java/org/codehaus/plexus/util/io/CachingOutputStreamTest.java @@ -60,7 +60,7 @@ private void waitLastModified() throws IOException, InterruptedException { } @Test - void writeNoExistingFile() throws IOException, InterruptedException { + void writeNoExistingFile() throws Exception { 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 5172547b..ab52ca10 100644 --- a/src/test/java/org/codehaus/plexus/util/io/CachingWriterTest.java +++ b/src/test/java/org/codehaus/plexus/util/io/CachingWriterTest.java @@ -60,7 +60,7 @@ private void waitLastModified() throws IOException, InterruptedException { } @Test - void noOverwriteWithFlush() throws IOException, InterruptedException { + void noOverwriteWithFlush() throws Exception { String data = "Hello world!"; Path path = tempDir.resolve("file-bigger.txt"); assertFalse(Files.exists(path)); @@ -85,7 +85,7 @@ void noOverwriteWithFlush() throws IOException, InterruptedException { } @Test - void writeNoExistingFile() throws IOException, InterruptedException { + void writeNoExistingFile() throws Exception { 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 932254f6..8e8f88b2 100644 --- a/src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java +++ b/src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java @@ -25,7 +25,6 @@ *

ReflectorTest class.

* * @author Jörg Schaible - * @version $Id: $Id * @since 3.4.0 */ class ReflectorTest { @@ -33,13 +32,8 @@ class ReflectorTest { private Reflector reflector; - /** - *

setUp.

- * - * @throws java.lang.Exception if any. - */ @BeforeEach - void setUp() throws Exception { + void setUp() { project = new Project(); project.setModelVersion("1.0.0"); project.setVersion("42"); @@ -47,31 +41,16 @@ void setUp() throws Exception { reflector = new Reflector(); } - /** - *

testObjectPropertyFromName.

- * - * @throws java.lang.Exception if any. - */ @Test void objectPropertyFromName() throws Exception { assertEquals("1.0.0", reflector.getObjectProperty(project, "modelVersion")); } - /** - *

testObjectPropertyFromBean.

- * - * @throws java.lang.Exception if any. - */ @Test void objectPropertyFromBean() throws Exception { assertEquals("Foo", reflector.getObjectProperty(project, "name")); } - /** - *

testObjectPropertyFromField.

- * - * @throws java.lang.Exception if any. - */ @Test void objectPropertyFromField() throws Exception { assertEquals("42", reflector.getObjectProperty(project, "version")); @@ -82,6 +61,7 @@ public static class Project { private String name; + @SuppressWarnings("FieldCanBeLocal") private String version; public void setModelVersion(String modelVersion) { @@ -96,6 +76,7 @@ public String modelVersion() { return model; } + @SuppressWarnings("SameReturnValue") public String getName() { return "Foo"; }