diff --git a/pom.xml b/pom.xml index 7fd5f185..88a8aaae 100644 --- a/pom.xml +++ b/pom.xml @@ -48,6 +48,7 @@ limitations under the License. + 1.36 2023-03-02T01:23:19Z @@ -55,19 +56,18 @@ limitations under the License. org.openjdk.jmh jmh-core - 1.36 + ${jmhVersion} test org.openjdk.jmh jmh-generator-annprocess - 1.36 + ${jmhVersion} test - junit - junit - 4.13.2 + org.junit.jupiter + junit-jupiter-api test @@ -97,8 +97,7 @@ limitations under the License. compile - 1.8 - 1.8 + 8 @@ -131,16 +130,6 @@ limitations under the License. org/codehaus/plexus/util/FileBasedTestCase.java **/Test*.java - - - JAVA_HOME - ${JAVA_HOME} - - - M2_HOME - ${M2_HOME} - - diff --git a/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java b/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java index 12a4e25d..953576ef 100644 --- a/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java @@ -22,11 +22,11 @@ import java.util.Map; import java.util.Properties; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; /** *

CollectionUtilsTest class.

@@ -35,13 +35,13 @@ * @version $Id: $Id * @since 3.4.0 */ -public class CollectionUtilsTest { +class CollectionUtilsTest { /** *

testMergeMaps.

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

testMavenPropertiesLoading.

*/ @Test - public void testMavenPropertiesLoading() { + void mavenPropertiesLoading() { // Mimic MavenSession properties loading. Properties listed // in dominant order. Properties systemProperties = new Properties(); @@ -175,26 +175,26 @@ public void testMavenPropertiesLoading() { }); // Values that should be taken from systemProperties. - assertEquals("/projects/maven", (String) result.get("maven.home")); + assertEquals("/projects/maven", result.get("maven.home")); // Values that should be taken from userBuildProperties. - assertEquals("/opt/maven/artifact", (String) result.get("maven.repo.local")); - assertEquals("false", (String) result.get("maven.repo.remote.enabled")); - assertEquals("jvanzyl", (String) result.get("maven.username")); + assertEquals("/opt/maven/artifact", result.get("maven.repo.local")); + assertEquals("false", result.get("maven.repo.remote.enabled")); + assertEquals("jvanzyl", result.get("maven.username")); // Values take from projectBuildProperties. - assertEquals("maven", (String) result.get("maven.final.name")); + assertEquals("maven", result.get("maven.final.name")); // Values take from projectProperties. - assertEquals(mavenRepoRemote, (String) result.get("maven.repo.remote")); + assertEquals(mavenRepoRemote, result.get("maven.repo.remote")); } /** *

testIteratorToListWithAPopulatedList.

*/ @Test - public void testIteratorToListWithAPopulatedList() { - List original = new ArrayList(); + void iteratorToListWithAPopulatedList() { + List original = new ArrayList<>(); original.add("en"); original.add("to"); @@ -215,8 +215,8 @@ public void testIteratorToListWithAPopulatedList() { *

testIteratorToListWithAEmptyList.

*/ @Test - public void testIteratorToListWithAEmptyList() { - List original = new ArrayList(); + void iteratorToListWithAEmptyList() { + List original = new ArrayList<>(); List copy = CollectionUtils.iteratorToList(original.iterator()); diff --git a/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java b/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java index afe9a877..340964f3 100644 --- a/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java +++ b/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java @@ -29,16 +29,15 @@ import java.util.List; import java.util.Set; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assumptions.assumeTrue; /** * Base class for testcases doing tests with files. @@ -48,16 +47,17 @@ * @since 3.4.0 */ public class DirectoryScannerTest extends FileBasedTestCase { - @Rule - public TestName name = new TestName(); - private static String testDir = getTestDirectory().getPath(); + public String name; + + private static final String testDir = getTestDirectory().getPath(); /** *

setUp.

*/ - @Before - public void setUp() { + @BeforeEach + void setUp(TestInfo testInfo) { + testInfo.getTestMethod().ifPresent(method -> this.name = method.getName()); try { FileUtils.deleteDirectory(testDir); } catch (IOException e) { @@ -72,7 +72,7 @@ public void setUp() { * @throws java.net.URISyntaxException if any. */ @Test - public void testCrossPlatformIncludesString() throws IOException, URISyntaxException { + void crossPlatformIncludesString() throws IOException, URISyntaxException { DirectoryScanner ds = new DirectoryScanner(); ds.setBasedir(new File(getTestResourcesDir() + File.separator + "directory-scanner").getCanonicalFile()); @@ -98,7 +98,7 @@ public void testCrossPlatformIncludesString() throws IOException, URISyntaxExcep * @throws java.net.URISyntaxException if any. */ @Test - public void testCrossPlatformExcludesString() throws IOException, URISyntaxException { + void crossPlatformExcludesString() throws IOException, URISyntaxException { DirectoryScanner ds = new DirectoryScanner(); ds.setBasedir(new File(getTestResourcesDir() + File.separator + "directory-scanner").getCanonicalFile()); ds.setIncludes(new String[] {"**"}); @@ -161,11 +161,10 @@ private boolean checkTestFilesSymlinks() { } return true; } catch (IOException e) { - System.err.println(String.format( - "The unit test '%s.%s' will be skipped, reason: %s", - this.getClass().getSimpleName(), name.getMethodName(), e.getMessage())); - System.out.println( - String.format("This test requires symlinks files in '%s' directory.", symlinksDirectory.getPath())); + System.err.printf( + "The unit test '%s.%s' will be skipped, reason: %s%n", + this.getClass().getSimpleName(), name, e.getMessage()); + System.out.printf("This test requires symlinks files in '%s' directory.%n", symlinksDirectory.getPath()); System.out.println("On some OS (like Windows 10), files are present only if the clone/checkout is done" + " in administrator mode, and correct (symlinks and not flat file/directory)" + " if symlinks option are used (for git: git clone -c core.symlinks=true [url])"); @@ -179,7 +178,7 @@ private boolean checkTestFilesSymlinks() { * @throws java.io.IOException if any. */ @Test - public void testGeneral() throws IOException { + void general() throws IOException { this.createTestFiles(); String includes = "scanner1.dat,scanner2.dat,scanner3.dat,scanner4.dat,scanner5.dat"; @@ -187,10 +186,10 @@ public void testGeneral() throws IOException { List fileNames = FileUtils.getFiles(new File(testDir), includes, excludes, false); - assertEquals("Wrong number of results.", 3, fileNames.size()); - assertTrue("3 not found.", fileNames.contains(new File("scanner3.dat"))); - assertTrue("4 not found.", fileNames.contains(new File("scanner4.dat"))); - assertTrue("5 not found.", fileNames.contains(new File("scanner5.dat"))); + assertEquals(3, fileNames.size(), "Wrong number of results."); + assertTrue(fileNames.contains(new File("scanner3.dat")), "3 not found."); + assertTrue(fileNames.contains(new File("scanner4.dat")), "4 not found."); + assertTrue(fileNames.contains(new File("scanner5.dat")), "5 not found."); } /** @@ -199,7 +198,7 @@ public void testGeneral() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testIncludesExcludesWithWhiteSpaces() throws IOException { + void includesExcludesWithWhiteSpaces() throws IOException { this.createTestFiles(); String includes = "scanner1.dat,\n \n,scanner2.dat \n\r, scanner3.dat\n, \tscanner4.dat,scanner5.dat\n,"; @@ -208,17 +207,17 @@ public void testIncludesExcludesWithWhiteSpaces() throws IOException { List fileNames = FileUtils.getFiles(new File(testDir), includes, excludes, false); - assertEquals("Wrong number of results.", 3, fileNames.size()); - assertTrue("3 not found.", fileNames.contains(new File("scanner3.dat"))); - assertTrue("4 not found.", fileNames.contains(new File("scanner4.dat"))); - assertTrue("5 not found.", fileNames.contains(new File("scanner5.dat"))); + assertEquals(3, fileNames.size(), "Wrong number of results."); + assertTrue(fileNames.contains(new File("scanner3.dat")), "3 not found."); + assertTrue(fileNames.contains(new File("scanner4.dat")), "4 not found."); + assertTrue(fileNames.contains(new File("scanner5.dat")), "5 not found."); } /** *

testFollowSymlinksFalse.

*/ @Test - public void testFollowSymlinksFalse() { + void followSymlinksFalse() { assumeTrue(checkTestFilesSymlinks()); DirectoryScanner ds = new DirectoryScanner(); @@ -253,7 +252,7 @@ private void assertAlwaysIncluded(List included) { *

testFollowSymlinks.

*/ @Test - public void testFollowSymlinks() { + void followSymlinks() { assumeTrue(checkTestFilesSymlinks()); DirectoryScanner ds = new DirectoryScanner(); @@ -300,7 +299,7 @@ private void createTestDirectories() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testDirectoriesWithHyphens() throws IOException { + void directoriesWithHyphens() throws IOException { this.createTestDirectories(); DirectoryScanner ds = new DirectoryScanner(); @@ -313,7 +312,7 @@ public void testDirectoriesWithHyphens() throws IOException { ds.scan(); String[] files = ds.getIncludedFiles(); - assertEquals("Wrong number of results.", 3, files.length); + assertEquals(3, files.length, "Wrong number of results."); } /** @@ -322,7 +321,7 @@ public void testDirectoriesWithHyphens() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testAntExcludesOverrideIncludes() throws IOException { + void antExcludesOverrideIncludes() throws IOException { printTestHeader(); File dir = new File(testDir, "regex-dir"); @@ -360,7 +359,7 @@ public void testAntExcludesOverrideIncludes() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testAntExcludesOverrideIncludesWithExplicitAntPrefix() throws IOException { + void antExcludesOverrideIncludesWithExplicitAntPrefix() throws IOException { printTestHeader(); File dir = new File(testDir, "regex-dir"); @@ -399,7 +398,7 @@ public void testAntExcludesOverrideIncludesWithExplicitAntPrefix() throws IOExce * @throws java.io.IOException if any. */ @Test - public void testRegexIncludeWithExcludedPrefixDirs() throws IOException { + void regexIncludeWithExcludedPrefixDirs() throws IOException { printTestHeader(); File dir = new File(testDir, "regex-dir"); @@ -433,7 +432,7 @@ public void testRegexIncludeWithExcludedPrefixDirs() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testRegexExcludeWithNegativeLookahead() throws IOException { + void regexExcludeWithNegativeLookahead() throws IOException { printTestHeader(); File dir = new File(testDir, "regex-dir"); @@ -472,7 +471,7 @@ public void testRegexExcludeWithNegativeLookahead() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testRegexWithSlashInsideCharacterClass() throws IOException { + void regexWithSlashInsideCharacterClass() throws IOException { printTestHeader(); File dir = new File(testDir, "regex-dir"); @@ -513,7 +512,7 @@ public void testRegexWithSlashInsideCharacterClass() throws IOException { * @throws java.io.IOException if occurs an I/O error. */ @Test - public void testDoNotScanUnnecesaryDirectories() throws IOException { + void doNotScanUnnecesaryDirectories() throws IOException { createTestDirectories(); // create additional directories 'anotherDir1', 'anotherDir2' and 'anotherDir3' with a 'file1.dat' file @@ -552,7 +551,7 @@ public void testDoNotScanUnnecesaryDirectories() throws IOException { "directoryTest" + File.separator + "test-dir-123" + File.separator + "file1.dat" }; - final Set scannedDirSet = new HashSet(); + final Set scannedDirSet = new HashSet<>(); DirectoryScanner ds = new DirectoryScanner() { @Override @@ -571,7 +570,7 @@ protected void scandir(File dir, String vpath, boolean fast) { assertInclusionsAndExclusions(ds.getIncludedFiles(), excludedPaths, includedPaths); Set expectedScannedDirSet = - new HashSet(Arrays.asList("io", "directoryTest", "testDir123", "test_dir_123", "test-dir-123")); + new HashSet<>(Arrays.asList("io", "directoryTest", "testDir123", "test_dir_123", "test-dir-123")); assertEquals(expectedScannedDirSet, scannedDirSet); } @@ -582,7 +581,7 @@ protected void scandir(File dir, String vpath, boolean fast) { * @throws java.io.IOException if any. */ @Test - public void testIsSymbolicLink() throws IOException { + void isSymbolicLink() throws IOException { assumeTrue(checkTestFilesSymlinks()); final File directory = new File("src/test/resources/symlinks/src"); @@ -599,7 +598,7 @@ public void testIsSymbolicLink() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testIsParentSymbolicLink() throws IOException { + void isParentSymbolicLink() throws IOException { assumeTrue(checkTestFilesSymlinks()); final File directory = new File("src/test/resources/symlinks/src"); @@ -627,7 +626,7 @@ private void assertInclusionsAndExclusions(String[] files, String[] excludedPath System.out.println(file); } - List failedToExclude = new ArrayList(); + List failedToExclude = new ArrayList<>(); for (String excludedPath : excludedPaths) { String alt = excludedPath.replace('/', '\\'); System.out.println("Searching for exclusion as: " + excludedPath + "\nor: " + alt); @@ -636,7 +635,7 @@ private void assertInclusionsAndExclusions(String[] files, String[] excludedPath } } - List failedToInclude = new ArrayList(); + List failedToInclude = new ArrayList<>(); for (String includedPath : includedPaths) { String alt = includedPath.replace('/', '\\'); System.out.println("Searching for inclusion as: " + includedPath + "\nor: " + alt); diff --git a/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java b/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java index 97786c51..f35062d7 100644 --- a/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java +++ b/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java @@ -18,11 +18,11 @@ import java.io.File; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** *

DirectoryWalkerTest class.

@@ -31,12 +31,12 @@ * @version $Id: $Id * @since 3.4.0 */ -public class DirectoryWalkerTest { +class DirectoryWalkerTest { /** *

testDirectoryWalk.

*/ @Test - public void testDirectoryWalk() { + void directoryWalk() { DirectoryWalker walker = new DirectoryWalker(); walker.addSCMExcludes(); @@ -48,11 +48,11 @@ public void testDirectoryWalk() { walker.scan(); - assertEquals("Walk Collector / Starting Count", 1, collector.startCount); - assertNotNull("Walk Collector / Starting Dir", collector.startingDir); - assertEquals("Walk Collector / Finish Count", 1, collector.finishCount); - assertEquals("Walk Collector / Steps Count", 4, collector.steps.size()); - assertTrue("Walk Collector / percentage low >= 0", collector.percentageLow >= 0); - assertTrue("Walk Collector / percentage high <= 100", collector.percentageHigh <= 100); + assertEquals(1, collector.startCount, "Walk Collector / Starting Count"); + assertNotNull(collector.startingDir, "Walk Collector / Starting Dir"); + assertEquals(1, collector.finishCount, "Walk Collector / Finish Count"); + assertEquals(4, collector.steps.size(), "Walk Collector / Steps Count"); + assertTrue(collector.percentageLow >= 0, "Walk Collector / percentage low >= 0"); + assertTrue(collector.percentageHigh <= 100, "Walk Collector / percentage high <= 100"); } } diff --git a/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java b/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java index 367eca64..988ed2c3 100644 --- a/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java +++ b/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java @@ -26,17 +26,15 @@ import java.io.PrintWriter; import java.io.Writer; import java.nio.file.Files; -import java.util.Arrays; -import junit.framework.AssertionFailedError; +import org.opentest4j.AssertionFailedError; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Base class for testcases doing tests with files. * * @author Jeremias Maerki - * @version $Id: $Id * @since 3.4.0 */ public abstract class FileBasedTestCase { @@ -69,37 +67,27 @@ protected byte[] createFile(final File file, final long size) throws IOException byte[] data = generateTestData(size); - final BufferedOutputStream output = new BufferedOutputStream(Files.newOutputStream(file.toPath())); - - try { + try (BufferedOutputStream output = new BufferedOutputStream(Files.newOutputStream(file.toPath()))) { output.write(data); - return data; - } finally { - output.close(); } } /** *

createSymlink.

* - * @param link a {@link java.io.File} object. + * @param link a {@link java.io.File} object. * @param target a {@link java.io.File} object. - * @return a boolean. */ - protected boolean createSymlink(final File link, final File target) { + protected void createSymlink(final File link, final File target) { try { String[] args = {"ln", "-s", target.getAbsolutePath(), link.getAbsolutePath()}; Process process = Runtime.getRuntime().exec(args); process.waitFor(); - if (0 != process.exitValue()) { - return false; - } + if (0 != process.exitValue()) {} } catch (Exception e) { // assume platform does not support "ln" command, tests should be skipped - return false; } - return true; } /** @@ -160,7 +148,7 @@ protected File newFile(String filename) throws IOException { * @throws java.lang.Exception if any. */ protected void checkFile(final File file, final File referenceFile) throws Exception { - assertTrue("Check existence of output file", file.exists()); + assertTrue(file.exists(), "Check existence of output file"); assertEqualContent(referenceFile, file); } @@ -168,9 +156,8 @@ protected void checkFile(final File file, final File referenceFile) throws Excep *

checkWrite.

* * @param output a {@link java.io.OutputStream} object. - * @throws java.lang.Exception if any. */ - protected void checkWrite(final OutputStream output) throws Exception { + protected void checkWrite(final OutputStream output) { try { new PrintStream(output).write(0); } catch (final Throwable t) { @@ -202,7 +189,7 @@ protected void checkWrite(final Writer output) throws Exception { */ protected void deleteFile(final File file) throws Exception { if (file.exists()) { - assertTrue("Couldn't delete file: " + file, file.delete()); + assertTrue(file.delete(), "Couldn't delete file: " + file); } } @@ -217,10 +204,8 @@ private void assertEqualContent(final File f0, final File f1) throws IOException * + " and " + f1 + " have differing file sizes (" + f0.length() + " vs " + f1.length() + ")", ( f0.length() == * f1.length() ) ); */ - final InputStream is0 = Files.newInputStream(f0.toPath()); - try { - final InputStream is1 = Files.newInputStream(f1.toPath()); - try { + try (InputStream is0 = Files.newInputStream(f0.toPath())) { + try (InputStream is1 = Files.newInputStream(f1.toPath())) { final byte[] buf0 = new byte[1024]; final byte[] buf1 = new byte[1024]; int n0 = 0; @@ -230,17 +215,13 @@ private void assertEqualContent(final File f0, final File f1) throws IOException n0 = is0.read(buf0); n1 = is1.read(buf1); assertTrue( + (n0 == n1), "The files " + f0 + " and " + f1 + " have differing number of bytes available (" + n0 - + " vs " + n1 + ")", - (n0 == n1)); + + " vs " + n1 + ")"); - assertTrue("The files " + f0 + " and " + f1 + " have different content", Arrays.equals(buf0, buf1)); + assertArrayEquals(buf0, buf1, "The files " + f0 + " and " + f1 + " have different content"); } - } finally { - is1.close(); } - } finally { - is0.close(); } } @@ -252,17 +233,14 @@ private void assertEqualContent(final File f0, final File f1) throws IOException * @throws java.io.IOException if any. */ protected void assertEqualContent(final byte[] b0, final File file) throws IOException { - final InputStream is = Files.newInputStream(file.toPath()); - try { + try (InputStream is = Files.newInputStream(file.toPath())) { byte[] b1 = new byte[b0.length]; int numRead = is.read(b1); - assertTrue("Different number of bytes", numRead == b0.length && is.available() == 0); + assertTrue(numRead == b0.length && is.available() == 0, "Different number of bytes"); for (int i = 0; i < numRead; - assertTrue("Byte " + i + " differs (" + b0[i] + " != " + b1[i] + ")", b0[i] == b1[i]), i++) + assertEquals(b0[i], b1[i], "Byte " + i + " differs (" + b0[i] + " != " + b1[i] + ")"), i++) ; - } finally { - is.close(); } } @@ -272,9 +250,9 @@ protected void assertEqualContent(final byte[] b0, final File file) throws IOExc * @param file a {@link java.io.File} object. */ protected void assertIsDirectory(File file) { - assertTrue("The File doesn't exists: " + file.getAbsolutePath(), file.exists()); + assertTrue(file.exists(), "The File doesn't exists: " + file.getAbsolutePath()); - assertTrue("The File isn't a directory: " + file.getAbsolutePath(), file.isDirectory()); + assertTrue(file.isDirectory(), "The File isn't a directory: " + file.getAbsolutePath()); } /** @@ -283,8 +261,8 @@ protected void assertIsDirectory(File file) { * @param file a {@link java.io.File} object. */ protected void assertIsFile(File file) { - assertTrue("The File doesn't exists: " + file.getAbsolutePath(), file.exists()); + assertTrue(file.exists(), "The File doesn't exists: " + file.getAbsolutePath()); - assertTrue("The File isn't a file: " + file.getAbsolutePath(), file.isFile()); + assertTrue(file.isFile(), "The File isn't a file: " + file.getAbsolutePath()); } } diff --git a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java index dcfe8e4d..839477c0 100644 --- a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java @@ -24,22 +24,25 @@ import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; +import java.lang.reflect.Method; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.Optional; import java.util.Properties; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * This is used to test FileUtils for correctness. @@ -51,8 +54,8 @@ * @since 3.4.0 */ public final class FileUtilsTest extends FileBasedTestCase { - @Rule - public TestName name = new TestName(); + + public String name; // Test data @@ -87,8 +90,12 @@ public FileUtilsTest() throws Exception { * * @throws java.lang.Exception if any. */ - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp(TestInfo testInfo) throws Exception { + Optional testMethod = testInfo.getTestMethod(); + if (testMethod.isPresent()) { + this.name = testMethod.get().getName(); + } getTestDirectory().mkdirs(); createFile(testFile1, testFile1Size); createFile(testFile2, testFile2Size); @@ -104,11 +111,11 @@ public void setUp() throws Exception { *

testByteCountToDisplaySize.

*/ @Test - public void testByteCountToDisplaySize() { - assertEquals(FileUtils.byteCountToDisplaySize(0), "0 bytes"); - assertEquals(FileUtils.byteCountToDisplaySize(1024), "1 KB"); - assertEquals(FileUtils.byteCountToDisplaySize(1024 * 1024), "1 MB"); - assertEquals(FileUtils.byteCountToDisplaySize(1024 * 1024 * 1024), "1 GB"); + void byteCountToDisplaySize() { + assertEquals("0 bytes", FileUtils.byteCountToDisplaySize(0)); + assertEquals("1 KB", FileUtils.byteCountToDisplaySize(1024)); + assertEquals("1 MB", FileUtils.byteCountToDisplaySize(1024 * 1024)); + assertEquals("1 GB", FileUtils.byteCountToDisplaySize(1024 * 1024 * 1024)); } // waitFor @@ -117,7 +124,7 @@ public void testByteCountToDisplaySize() { *

testWaitFor.

*/ @Test - public void testWaitFor() { + void waitFor() { FileUtils.waitFor("", -1); FileUtils.waitFor("", 2); @@ -129,7 +136,7 @@ public void testWaitFor() { * @throws java.lang.Exception if any. */ @Test - public void testToFile() throws Exception { + void toFile() throws Exception { URL url = getClass().getResource("/test.txt"); url = new URL(url.toString() + "/name%20%23%2520%3F%7B%7D%5B%5D%3C%3E.txt"); File file = FileUtils.toFile(url); @@ -142,7 +149,7 @@ public void testToFile() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testToFileBadProtocol() throws Exception { + void toFileBadProtocol() throws Exception { URL url = new URL("http://maven.apache.org/"); File file = FileUtils.toFile(url); assertNull(file); @@ -154,7 +161,7 @@ public void testToFileBadProtocol() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testToFileNull() throws Exception { + void toFileNull() throws Exception { File file = FileUtils.toFile(null); assertNull(file); } @@ -166,7 +173,7 @@ public void testToFileNull() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testToURLs() throws Exception { + void toURLs() throws Exception { File[] files = new File[] { new File("file1"), new File("file2"), }; @@ -174,10 +181,10 @@ public void testToURLs() throws Exception { URL[] urls = FileUtils.toURLs(files); assertEquals( - "The length of the generated URL's is not equals to the length of files. " + "Was " + files.length - + ", expected " + urls.length, files.length, - urls.length); + urls.length, + "The length of the generated URL's is not equals to the length of files. " + "Was " + files.length + + ", expected " + urls.length); for (int i = 0; i < urls.length; i++) { assertEquals(files[i].toURI().toURL(), urls[i]); @@ -188,14 +195,14 @@ public void testToURLs() throws Exception { *

testGetFilesFromExtension.

*/ @Test - public void testGetFilesFromExtension() { + void getFilesFromExtension() { // TODO I'm not sure what is supposed to happen here FileUtils.getFilesFromExtension("dir", null); // Non-existent files final String[] emptyFileNames = FileUtils.getFilesFromExtension(getTestDirectory().getAbsolutePath(), new String[] {"java"}); - assertTrue(emptyFileNames.length == 0); + assertEquals(0, emptyFileNames.length); // Existing files // TODO Figure out how to test this @@ -211,7 +218,7 @@ public void testGetFilesFromExtension() { *

testMkdir.

*/ @Test - public void testMkdir() { + void mkdir() { final File dir = new File(getTestDirectory(), "testdir"); FileUtils.mkdir(dir.getAbsolutePath()); dir.deleteOnExit(); @@ -221,7 +228,7 @@ public void testMkdir() { File winFile = new File(getTestDirectory(), "bla*bla"); winFile.deleteOnExit(); FileUtils.mkdir(winFile.getAbsolutePath()); - assertTrue(false); + fail(); } catch (IllegalArgumentException e) { assertTrue(true); } @@ -236,25 +243,25 @@ public void testMkdir() { * @throws java.lang.Exception if any. */ @Test - public void testContentEquals() throws Exception { + void contentEquals() throws Exception { // Non-existent files - final File file = new File(getTestDirectory(), name.getMethodName()); + final File file = new File(getTestDirectory(), name); assertTrue(FileUtils.contentEquals(file, file)); // TODO Should comparing 2 directories throw an Exception instead of returning false? // Directories - assertTrue(!FileUtils.contentEquals(getTestDirectory(), getTestDirectory())); + assertFalse(FileUtils.contentEquals(getTestDirectory(), getTestDirectory())); // Different files - final File objFile1 = new File(getTestDirectory(), name.getMethodName() + ".object"); + final File objFile1 = new File(getTestDirectory(), name + ".object"); objFile1.deleteOnExit(); FileUtils.copyURLToFile(getClass().getResource("/java/lang/Object.class"), objFile1); - final File objFile2 = new File(getTestDirectory(), name.getMethodName() + ".collection"); + final File objFile2 = new File(getTestDirectory(), name + ".collection"); objFile2.deleteOnExit(); FileUtils.copyURLToFile(getClass().getResource("/java/util/Collection.class"), objFile2); - assertTrue("Files should not be equal.", !FileUtils.contentEquals(objFile1, objFile2)); + assertFalse(FileUtils.contentEquals(objFile1, objFile2), "Files should not be equal."); // Equal files file.createNewFile(); @@ -267,10 +274,9 @@ public void testContentEquals() throws Exception { *

testRemovePath.

*/ @Test - public void testRemovePath() { - final String fileName = - FileUtils.removePath(new File(getTestDirectory(), name.getMethodName()).getAbsolutePath()); - assertEquals(name.getMethodName(), fileName); + void removePath() { + final String fileName = FileUtils.removePath(new File(getTestDirectory(), name).getAbsolutePath()); + assertEquals(name, fileName); } // getPath @@ -279,8 +285,8 @@ public void testRemovePath() { *

testGetPath.

*/ @Test - public void testGetPath() { - final String fileName = FileUtils.getPath(new File(getTestDirectory(), name.getMethodName()).getAbsolutePath()); + void getPath() { + final String fileName = FileUtils.getPath(new File(getTestDirectory(), name).getAbsolutePath()); assertEquals(getTestDirectory().getAbsolutePath(), fileName); } @@ -292,9 +298,9 @@ public void testGetPath() { * @throws java.lang.Exception if any. */ @Test - public void testCopyURLToFile() throws Exception { + void copyURLToFile() throws Exception { // Creates file - final File file = new File(getTestDirectory(), name.getMethodName()); + final File file = new File(getTestDirectory(), name); file.deleteOnExit(); // Loads resource @@ -302,12 +308,9 @@ public void testCopyURLToFile() throws Exception { FileUtils.copyURLToFile(getClass().getResource(resourceName), file); // Tests that resource was copied correctly - final InputStream fis = Files.newInputStream(file.toPath()); - try { + try (InputStream fis = Files.newInputStream(file.toPath())) { assertTrue( - "Content is not equal.", IOUtil.contentEquals(getClass().getResourceAsStream(resourceName), fis)); - } finally { - fis.close(); + IOUtil.contentEquals(getClass().getResourceAsStream(resourceName), fis), "Content is not equal."); } } @@ -317,7 +320,7 @@ public void testCopyURLToFile() throws Exception { *

testCatPath.

*/ @Test - public void testCatPath() { + void catPath() { // TODO StringIndexOutOfBoundsException thrown if file doesn't contain slash. // Is this acceptable? // assertEquals("", FileUtils.catPath("a", "b")); @@ -334,15 +337,15 @@ public void testCatPath() { * @throws java.lang.Exception if any. */ @Test - public void testForceMkdir() throws Exception { + void forceMkdir() throws Exception { // Tests with existing directory FileUtils.forceMkdir(getTestDirectory()); // Creates test file - final File testFile = new File(getTestDirectory(), name.getMethodName()); + final File testFile = new File(getTestDirectory(), name); testFile.deleteOnExit(); testFile.createNewFile(); - assertTrue("Test file does not exist.", testFile.exists()); + assertTrue(testFile.exists(), "Test file does not exist."); // Tests with existing file try { @@ -355,14 +358,14 @@ public void testForceMkdir() throws Exception { // Tests with non-existent directory FileUtils.forceMkdir(testFile); - assertTrue("Directory was not created.", testFile.exists()); + assertTrue(testFile.exists(), "Directory was not created."); if (Os.isFamily(Os.FAMILY_WINDOWS)) { try { File winFile = new File(getTestDirectory(), "bla*bla"); winFile.deleteOnExit(); FileUtils.forceMkdir(winFile); - assertTrue(false); + fail(); } catch (IllegalArgumentException e) { assertTrue(true); } @@ -377,8 +380,8 @@ public void testForceMkdir() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testSizeOfDirectory() throws Exception { - final File file = new File(getTestDirectory(), name.getMethodName()); + void sizeOfDirectory() throws Exception { + final File file = new File(getTestDirectory(), name); // Non-existent file try { @@ -402,7 +405,7 @@ public void testSizeOfDirectory() throws Exception { file.delete(); file.mkdir(); - assertEquals("Unexpected directory size", TEST_DIRECTORY_SIZE, FileUtils.sizeOfDirectory(file)); + assertEquals(TEST_DIRECTORY_SIZE, FileUtils.sizeOfDirectory(file), "Unexpected directory size"); } // isFileNewer @@ -421,11 +424,11 @@ public void XtestIsFileNewer() {} * @throws java.lang.Exception if any. */ @Test - public void testCopyFile1() throws Exception { + void copyFile1() throws Exception { final File destination = new File(getTestDirectory(), "copy1.txt"); FileUtils.copyFile(testFile1, destination); - assertTrue("Check Exist", destination.exists()); - assertTrue("Check Full copy", destination.length() == testFile1Size); + assertTrue(destination.exists(), "Check Exist"); + assertEquals(destination.length(), testFile1Size, "Check Full copy"); } /** @@ -434,11 +437,11 @@ public void testCopyFile1() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCopyFile2() throws Exception { + void copyFile2() throws Exception { final File destination = new File(getTestDirectory(), "copy2.txt"); FileUtils.copyFile(testFile1, destination); - assertTrue("Check Exist", destination.exists()); - assertTrue("Check Full copy", destination.length() == testFile2Size); + assertTrue(destination.exists(), "Check Exist"); + assertEquals(destination.length(), testFile2Size, "Check Full copy"); } /** @@ -447,15 +450,15 @@ public void testCopyFile2() throws Exception { * @throws java.lang.Exception */ @Test - public void testCopyFile3() throws Exception { + void copyFile3() throws Exception { File destDirectory = new File(getTestDirectory(), "foo/bar/testcopy"); if (destDirectory.exists()) { destDirectory.delete(); } final File destination = new File(destDirectory, "copy2.txt"); FileUtils.copyFile(testFile1, destination); - assertTrue("Check Exist", destination.exists()); - assertTrue("Check Full copy", destination.length() == testFile2Size); + assertTrue(destination.exists(), "Check Exist"); + assertEquals(destination.length(), testFile2Size, "Check Full copy"); } // linkFile @@ -465,12 +468,12 @@ public void testCopyFile3() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testLinkFile1() throws Exception { + void linkFile1() throws Exception { final File destination = new File(getTestDirectory(), "link1.txt"); FileUtils.linkFile(testFile1, destination); - assertTrue("Check Exist", destination.exists()); - assertTrue("Check File length", destination.length() == testFile1Size); - assertTrue("Check is link", Files.isSymbolicLink(destination.toPath())); + assertTrue(destination.exists(), "Check Exist"); + assertEquals(destination.length(), testFile1Size, "Check File length"); + assertTrue(Files.isSymbolicLink(destination.toPath()), "Check is link"); } /** @@ -479,12 +482,12 @@ public void testLinkFile1() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testLinkFile2() throws Exception { + void linkFile2() throws Exception { final File destination = new File(getTestDirectory(), "link2.txt"); FileUtils.linkFile(testFile1, destination); - assertTrue("Check Exist", destination.exists()); - assertTrue("Check File length", destination.length() == testFile2Size); - assertTrue("Check is link", Files.isSymbolicLink(destination.toPath())); + assertTrue(destination.exists(), "Check Exist"); + assertEquals(destination.length(), testFile2Size, "Check File length"); + assertTrue(Files.isSymbolicLink(destination.toPath()), "Check is link"); } /** @@ -493,16 +496,16 @@ public void testLinkFile2() throws Exception { * @throws java.lang.Exception */ @Test - public void testLinkFile3() throws Exception { + void linkFile3() throws Exception { File destDirectory = new File(getTestDirectory(), "foo/bar/testlink"); if (destDirectory.exists()) { destDirectory.delete(); } final File destination = new File(destDirectory, "link2.txt"); FileUtils.linkFile(testFile1, destination); - assertTrue("Check Exist", destination.exists()); - assertTrue("Check File length", destination.length() == testFile2Size); - assertTrue("Check is link", Files.isSymbolicLink(destination.toPath())); + assertTrue(destination.exists(), "Check Exist"); + assertEquals(destination.length(), testFile2Size, "Check File length"); + assertTrue(Files.isSymbolicLink(destination.toPath()), "Check is link"); } // copyFileIfModified @@ -513,7 +516,7 @@ public void testLinkFile3() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCopyIfModifiedWhenSourceIsNewer() throws Exception { + void copyIfModifiedWhenSourceIsNewer() throws Exception { FileUtils.forceMkdir(new File(getTestDirectory() + "/temp")); // Place destination @@ -530,8 +533,8 @@ public void testCopyIfModifiedWhenSourceIsNewer() throws Exception { // Copy will occur when source is newer assertTrue( - "Failed copy. Target file should have been updated.", - FileUtils.copyFileIfModified(source, destination)); + FileUtils.copyFileIfModified(source, destination), + "Failed copy. Target file should have been updated."); } /** @@ -540,7 +543,7 @@ public void testCopyIfModifiedWhenSourceIsNewer() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCopyIfModifiedWhenSourceIsOlder() throws Exception { + void copyIfModifiedWhenSourceIsOlder() throws Exception { FileUtils.forceMkdir(new File(getTestDirectory() + "/temp")); // Place source @@ -555,7 +558,7 @@ public void testCopyIfModifiedWhenSourceIsOlder() throws Exception { FileUtils.copyFile(testFile1, destination); // Copy will occur when destination is newer - assertFalse("Source file should not have been copied.", FileUtils.copyFileIfModified(source, destination)); + assertFalse(FileUtils.copyFileIfModified(source, destination), "Source file should not have been copied."); } /** @@ -564,7 +567,7 @@ public void testCopyIfModifiedWhenSourceIsOlder() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCopyIfModifiedWhenSourceHasZeroDate() throws Exception { + void copyIfModifiedWhenSourceHasZeroDate() throws Exception { FileUtils.forceMkdir(new File(getTestDirectory(), "temp")); // Source modified on 1970-01-01T00:00Z @@ -576,7 +579,7 @@ public void testCopyIfModifiedWhenSourceHasZeroDate() throws Exception { File destination = new File(getTestDirectory(), "temp/copy1.txt"); // Should copy the source to the non existing destination. - assertTrue("Source file should have been copied.", FileUtils.copyFileIfModified(source, destination)); + assertTrue(FileUtils.copyFileIfModified(source, destination), "Source file should have been copied."); } // forceDelete @@ -587,12 +590,12 @@ public void testCopyIfModifiedWhenSourceHasZeroDate() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testForceDeleteAFile1() throws Exception { + void forceDeleteAFile1() throws Exception { final File destination = new File(getTestDirectory(), "copy1.txt"); destination.createNewFile(); - assertTrue("Copy1.txt doesn't exist to delete", destination.exists()); + assertTrue(destination.exists(), "Copy1.txt doesn't exist to delete"); FileUtils.forceDelete(destination); - assertTrue("Check No Exist", !destination.exists()); + assertFalse(destination.exists(), "Check No Exist"); } /** @@ -601,12 +604,12 @@ public void testForceDeleteAFile1() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testForceDeleteAFile2() throws Exception { + void forceDeleteAFile2() throws Exception { final File destination = new File(getTestDirectory(), "copy2.txt"); destination.createNewFile(); - assertTrue("Copy2.txt doesn't exist to delete", destination.exists()); + assertTrue(destination.exists(), "Copy2.txt doesn't exist to delete"); FileUtils.forceDelete(destination); - assertTrue("Check No Exist", !destination.exists()); + assertFalse(destination.exists(), "Check No Exist"); } // copyFileToDirectory @@ -617,15 +620,15 @@ public void testForceDeleteAFile2() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCopyFile1ToDir() throws Exception { + void copyFile1ToDir() throws Exception { final File directory = new File(getTestDirectory(), "subdir"); if (!directory.exists()) { directory.mkdirs(); } final File destination = new File(directory, testFile1.getName()); FileUtils.copyFileToDirectory(testFile1, directory); - assertTrue("Check Exist", destination.exists()); - assertTrue("Check Full copy", destination.length() == testFile1Size); + assertTrue(destination.exists(), "Check Exist"); + assertEquals(destination.length(), testFile1Size, "Check Full copy"); } /** @@ -634,15 +637,15 @@ public void testCopyFile1ToDir() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCopyFile2ToDir() throws Exception { + void copyFile2ToDir() throws Exception { final File directory = new File(getTestDirectory(), "subdir"); if (!directory.exists()) { directory.mkdirs(); } final File destination = new File(directory, testFile1.getName()); FileUtils.copyFileToDirectory(testFile1, directory); - assertTrue("Check Exist", destination.exists()); - assertTrue("Check Full copy", destination.length() == testFile2Size); + assertTrue(destination.exists(), "Check Exist"); + assertEquals(destination.length(), testFile2Size, "Check Full copy"); } // copyFileToDirectoryIfModified @@ -653,7 +656,7 @@ public void testCopyFile2ToDir() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCopyFile1ToDirIfModified() throws Exception { + void copyFile1ToDirIfModified() throws Exception { final File directory = new File(getTestDirectory(), "subdir"); if (directory.exists()) { FileUtils.forceDelete(directory); @@ -667,12 +670,12 @@ public void testCopyFile1ToDirIfModified() throws Exception { final File target = new File(getTestDirectory() + "/subdir", testFile1.getName()); long timestamp = target.lastModified(); - assertTrue("Check Exist", destination.exists()); - assertTrue("Check Full copy", destination.length() == testFile1Size); + assertTrue(destination.exists(), "Check Exist"); + assertEquals(destination.length(), testFile1Size, "Check Full copy"); FileUtils.copyFileToDirectoryIfModified(testFile1, directory); - assertTrue("Timestamp was changed", timestamp == target.lastModified()); + assertEquals(timestamp, target.lastModified(), "Timestamp was changed"); } /** @@ -681,7 +684,7 @@ public void testCopyFile1ToDirIfModified() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCopyFile2ToDirIfModified() throws Exception { + void copyFile2ToDirIfModified() throws Exception { final File directory = new File(getTestDirectory(), "subdir"); if (directory.exists()) { FileUtils.forceDelete(directory); @@ -695,12 +698,12 @@ public void testCopyFile2ToDirIfModified() throws Exception { final File target = new File(getTestDirectory() + "/subdir", testFile2.getName()); long timestamp = target.lastModified(); - assertTrue("Check Exist", destination.exists()); - assertTrue("Check Full copy", destination.length() == testFile2Size); + assertTrue(destination.exists(), "Check Exist"); + assertEquals(destination.length(), testFile2Size, "Check Full copy"); FileUtils.copyFileToDirectoryIfModified(testFile2, directory); - assertTrue("Timestamp was changed", timestamp == target.lastModified()); + assertEquals(timestamp, target.lastModified(), "Timestamp was changed"); } // forceDelete @@ -711,9 +714,9 @@ public void testCopyFile2ToDirIfModified() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testForceDeleteDir() throws Exception { + void forceDeleteDir() throws Exception { FileUtils.forceDelete(getTestDirectory().getParentFile()); - assertTrue("Check No Exist", !getTestDirectory().getParentFile().exists()); + assertFalse(getTestDirectory().getParentFile().exists(), "Check No Exist"); } // resolveFile @@ -724,9 +727,9 @@ public void testForceDeleteDir() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testResolveFileDotDot() throws Exception { + void resolveFileDotDot() throws Exception { final File file = FileUtils.resolveFile(getTestDirectory(), ".."); - assertEquals("Check .. operator", file, getTestDirectory().getParentFile()); + assertEquals(file, getTestDirectory().getParentFile(), "Check .. operator"); } /** @@ -735,9 +738,9 @@ public void testResolveFileDotDot() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testResolveFileDot() throws Exception { + void resolveFileDot() throws Exception { final File file = FileUtils.resolveFile(getTestDirectory(), "."); - assertEquals("Check . operator", file, getTestDirectory()); + assertEquals(file, getTestDirectory(), "Check . operator"); } // normalize @@ -748,7 +751,7 @@ public void testResolveFileDot() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testNormalize() throws Exception { + void normalize() throws Exception { final String[] src = { "", "/", @@ -789,11 +792,11 @@ public void testNormalize() throws Exception { null }; - assertEquals("Oops, test writer goofed", src.length, dest.length); + assertEquals(src.length, dest.length, "Oops, test writer goofed"); for (int i = 0; i < src.length; i++) { assertEquals( - "Check if '" + src[i] + "' normalized to '" + dest[i] + "'", dest[i], FileUtils.normalize(src[i])); + dest[i], FileUtils.normalize(src[i]), "Check if '" + src[i] + "' normalized to '" + dest[i] + "'"); } } @@ -816,46 +819,42 @@ private String replaceAll(String text, String lookFor, String replaceWith) { */ // Used to exist as IOTestCase class @Test - public void testFileUtils() throws Exception { + void fileUtils() throws Exception { // Loads file from classpath final String path = "/test.txt"; final URL url = this.getClass().getResource(path); - assertNotNull(path + " was not found.", url); + assertNotNull(url, path + " was not found."); final String filename = Paths.get(url.toURI()).toString(); final String filename2 = "test2.txt"; - assertTrue( - "test.txt extension == \"txt\"", - FileUtils.getExtension(filename).equals("txt")); + assertEquals("txt", FileUtils.getExtension(filename), "test.txt extension == \"txt\""); - assertTrue("Test file does exist: " + filename, FileUtils.fileExists(filename)); + assertTrue(FileUtils.fileExists(filename), "Test file does exist: " + filename); - assertTrue("Second test file does not exist", !FileUtils.fileExists(filename2)); + assertFalse(FileUtils.fileExists(filename2), "Second test file does not exist"); FileUtils.fileWrite(filename2, filename); - assertTrue("Second file was written", FileUtils.fileExists(filename2)); + assertTrue(FileUtils.fileExists(filename2), "Second file was written"); final String file2contents = FileUtils.fileRead(filename2); - assertTrue( - "Second file's contents correct", FileUtils.fileRead(filename2).equals(file2contents)); + assertEquals(FileUtils.fileRead(filename2), file2contents, "Second file's contents correct"); FileUtils.fileAppend(filename2, filename); - assertTrue( - "Second file's contents correct", FileUtils.fileRead(filename2).equals(file2contents + file2contents)); + assertEquals(FileUtils.fileRead(filename2), file2contents + file2contents, "Second file's contents correct"); FileUtils.fileDelete(filename2); - assertTrue("Second test file does not exist", !FileUtils.fileExists(filename2)); + assertFalse(FileUtils.fileExists(filename2), "Second test file does not exist"); final String contents = FileUtils.fileRead(filename); - assertTrue("FileUtils.fileRead()", contents.equals("This is a test")); + assertEquals("This is a test", contents, "FileUtils.fileRead()"); } /** *

testGetExtension.

*/ @Test - public void testGetExtension() { + void getExtension() { final String[][] tests = { {"filename.ext", "ext"}, {"README", ""}, @@ -875,16 +874,16 @@ public void testGetExtension() { *

testGetExtensionWithPaths.

*/ @Test - public void testGetExtensionWithPaths() { + void getExtensionWithPaths() { // Since the utilities are based on the separator for the platform // running the test, ensure we are using the right separator final String sep = File.separator; final String[][] testsWithPaths = { {sep + "tmp" + sep + "foo" + sep + "filename.ext", "ext"}, {"C:" + sep + "temp" + sep + "foo" + sep + "filename.ext", "ext"}, - {"" + sep + "tmp" + sep + "foo.bar" + sep + "filename.ext", "ext"}, + {sep + "tmp" + sep + "foo.bar" + sep + "filename.ext", "ext"}, {"C:" + sep + "temp" + sep + "foo.bar" + sep + "filename.ext", "ext"}, - {"" + sep + "tmp" + sep + "foo.bar" + sep + "README", ""}, + {sep + "tmp" + sep + "foo.bar" + sep + "README", ""}, {"C:" + sep + "temp" + sep + "foo.bar" + sep + "README", ""}, {".." + sep + "filename.ext", "ext"}, {"blabla", ""} @@ -899,7 +898,7 @@ public void testGetExtensionWithPaths() { *

testRemoveExtension.

*/ @Test - public void testRemoveExtension() { + void removeExtension() { final String[][] tests = { {"filename.ext", "filename"}, {"first.second.third.ext", "first.second.third"}, @@ -919,7 +918,7 @@ public void testRemoveExtension() { *

testRemoveExtensionWithPaths.

*/ @Test - public void testRemoveExtensionWithPaths() { + void removeExtensionWithPaths() { // Since the utilities are based on the separator for the platform // running the test, ensure we are using the right separator final String sep = File.separator; @@ -954,7 +953,7 @@ public void testRemoveExtensionWithPaths() { * @throws java.lang.Exception if any. */ @Test - public void testCopyDirectoryStructureWithAEmptyDirectoryStructure() throws Exception { + void copyDirectoryStructureWithAEmptyDirectoryStructure() throws Exception { File from = new File(getTestDirectory(), "from"); FileUtils.deleteDirectory(from); @@ -974,7 +973,7 @@ public void testCopyDirectoryStructureWithAEmptyDirectoryStructure() throws Exce * @throws java.lang.Exception if any. */ @Test - public void testCopyDirectoryStructureWithAPopulatedStructure() throws Exception { + void copyDirectoryStructureWithAPopulatedStructure() throws Exception { // Make a structure to copy File from = new File(getTestDirectory(), "from"); @@ -1037,7 +1036,7 @@ public void testCopyDirectoryStructureWithAPopulatedStructure() throws Exception * @throws java.lang.Exception if any. */ @Test - public void testCopyDirectoryStructureIfModified() throws Exception { + void copyDirectoryStructureIfModified() throws Exception { // Make a structure to copy File from = new File(getTestDirectory(), "from"); @@ -1099,18 +1098,18 @@ public void testCopyDirectoryStructureIfModified() throws Exception { FileUtils.copyDirectoryStructureIfModified(from, to); - assertTrue("Unmodified file was overwritten", timestamps[0] == files[0].lastModified()); - assertTrue("Unmodified file was overwritten", timestamps[1] == files[1].lastModified()); - assertTrue("Unmodified file was overwritten", timestamps[2] == files[2].lastModified()); + assertEquals(timestamps[0], files[0].lastModified(), "Unmodified file was overwritten"); + assertEquals(timestamps[1], files[1].lastModified(), "Unmodified file was overwritten"); + assertEquals(timestamps[2], files[2].lastModified(), "Unmodified file was overwritten"); files[1].setLastModified(f2.lastModified() - 5000L); timestamps[1] = files[1].lastModified(); FileUtils.copyDirectoryStructureIfModified(from, to); - assertTrue("Unmodified file was overwritten", timestamps[0] == files[0].lastModified()); - assertTrue("Outdated file was not overwritten", timestamps[1] < files[1].lastModified()); - assertTrue("Unmodified file was overwritten", timestamps[2] == files[2].lastModified()); + assertEquals(timestamps[0], files[0].lastModified(), "Unmodified file was overwritten"); + assertTrue(timestamps[1] < files[1].lastModified(), "Outdated file was not overwritten"); + assertEquals(timestamps[2], files[2].lastModified(), "Unmodified file was overwritten"); } /** @@ -1119,7 +1118,7 @@ public void testCopyDirectoryStructureIfModified() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCopyDirectoryStructureToSelf() throws Exception { + void copyDirectoryStructureToSelf() throws Exception { // Make a structure to copy File toFrom = new File(getTestDirectory(), "tofrom"); @@ -1161,7 +1160,7 @@ public void testCopyDirectoryStructureToSelf() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testFilteredFileCopy() throws Exception { + void filteredFileCopy() throws Exception { File compareFile = new File(getTestDirectory(), "compare.txt"); FileUtils.fileWrite(compareFile.getAbsolutePath(), "UTF-8", "This is a test. Test sample text\n"); @@ -1183,7 +1182,7 @@ public Reader getReader(Reader reader) { FileUtils.fileWrite(srcFile.getAbsolutePath(), "UTF-8", "This is a test. Test ${s}\n"); FileUtils.copyFile(srcFile, destFile, "UTF-8", wrappers1); - assertTrue("Files should be equal.", FileUtils.contentEquals(compareFile, destFile)); + assertTrue(FileUtils.contentEquals(compareFile, destFile), "Files should be equal."); srcFile.delete(); destFile.delete(); @@ -1196,7 +1195,7 @@ public Reader getReader(Reader reader) { * @throws java.lang.Exception if any. */ @Test - public void testFilteredWithoutFilterAndOlderFile() throws Exception { + void filteredWithoutFilterAndOlderFile() throws Exception { String content = "This is a test."; File sourceFile = new File(getTestDirectory(), "source.txt"); FileUtils.fileWrite(sourceFile.getAbsolutePath(), "UTF-8", content); @@ -1227,7 +1226,7 @@ public void testFilteredWithoutFilterAndOlderFile() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testFilteredWithoutFilterAndOlderFileAndOverwrite() throws Exception { + void filteredWithoutFilterAndOlderFileAndOverwrite() throws Exception { String content = "This is a test."; File sourceFile = new File(getTestDirectory(), "source.txt"); FileUtils.fileWrite(sourceFile.getAbsolutePath(), "UTF-8", content); @@ -1258,7 +1257,7 @@ public void testFilteredWithoutFilterAndOlderFileAndOverwrite() throws Exception * @throws java.io.IOException if any. */ @Test - public void testFileRead() throws IOException { + void fileRead() throws IOException { File testFile = new File(getTestDirectory(), "testFileRead.txt"); String testFileName = testFile.getAbsolutePath(); /* @@ -1276,8 +1275,8 @@ public void testFileRead() throws IOException { } finally { IOUtil.close(writer); } - assertEquals("testString should be equal", testString, FileUtils.fileRead(testFile)); - assertEquals("testString should be equal", testString, FileUtils.fileRead(testFileName)); + assertEquals(testString, FileUtils.fileRead(testFile), "testString should be equal"); + assertEquals(testString, FileUtils.fileRead(testFileName), "testString should be equal"); testFile.delete(); } @@ -1287,7 +1286,7 @@ public void testFileRead() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testFileReadWithEncoding() throws IOException { + void fileReadWithEncoding() throws IOException { String encoding = "UTF-8"; File testFile = new File(getTestDirectory(), "testFileRead.txt"); String testFileName = testFile.getAbsolutePath(); @@ -1301,8 +1300,8 @@ public void testFileReadWithEncoding() throws IOException { } finally { IOUtil.close(writer); } - assertEquals("testString should be equal", testString, FileUtils.fileRead(testFile, "UTF-8")); - assertEquals("testString should be equal", testString, FileUtils.fileRead(testFileName, "UTF-8")); + assertEquals(testString, FileUtils.fileRead(testFile, "UTF-8"), "testString should be equal"); + assertEquals(testString, FileUtils.fileRead(testFileName, "UTF-8"), "testString should be equal"); testFile.delete(); } @@ -1312,7 +1311,7 @@ public void testFileReadWithEncoding() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testFileAppend() throws IOException { + void fileAppend() throws IOException { String baseString = "abc"; File testFile = new File(getTestDirectory(), "testFileAppend.txt"); String testFileName = testFile.getAbsolutePath(); @@ -1337,7 +1336,7 @@ public void testFileAppend() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testFileAppendWithEncoding() throws IOException { + void fileAppendWithEncoding() throws IOException { String baseString = "abc"; String encoding = "UTF-8"; File testFile = new File(getTestDirectory(), "testFileAppend.txt"); @@ -1363,7 +1362,7 @@ public void testFileAppendWithEncoding() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testFileWrite() throws IOException { + void fileWrite() throws IOException { File testFile = new File(getTestDirectory(), "testFileWrite.txt"); String testFileName = testFile.getAbsolutePath(); // unicode escaped Japanese hiragana, "aiueo" + Umlaut a @@ -1379,7 +1378,7 @@ public void testFileWrite() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testFileWriteWithEncoding() throws IOException { + void fileWriteWithEncoding() throws IOException { String encoding = "UTF-8"; File testFile = new File(getTestDirectory(), "testFileWrite.txt"); String testFileName = testFile.getAbsolutePath(); @@ -1399,7 +1398,7 @@ public void testFileWriteWithEncoding() throws IOException { * @see Sun bug id=6481955 */ @Test - public void testDeleteLongPathOnWindows() throws Exception { + void deleteLongPathOnWindows() throws Exception { if (!Os.isFamily(Os.FAMILY_WINDOWS)) { return; } @@ -1409,14 +1408,14 @@ public void testDeleteLongPathOnWindows() throws Exception { File a1 = new File(a, "a"); a1.mkdir(); - StringBuilder path = new StringBuilder(""); + StringBuilder path = new StringBuilder(); for (int i = 0; i < 100; i++) { path.append("../a/"); } File f = new File(a1, path.toString() + "test.txt"); - InputStream is = new ByteArrayInputStream("Blabla".getBytes("UTF-8")); + InputStream is = new ByteArrayInputStream("Blabla".getBytes(StandardCharsets.UTF_8)); OutputStream os = Files.newOutputStream(f.getCanonicalFile().toPath()); IOUtil.copy(is, os); IOUtil.close(is); @@ -1437,7 +1436,7 @@ public void testDeleteLongPathOnWindows() throws Exception { * @throws java.io.IOException if any. */ @Test - public void testCopyFileOnSameFile() throws IOException { + void copyFileOnSameFile() throws IOException { String content = "ggrgreeeeeeeeeeeeeeeeeeeeeeeoierjgioejrgiojregioejrgufcdxivbsdibgfizgerfyaezgv!zeez"; final File theFile = File.createTempFile("test", ".txt"); theFile.deleteOnExit(); @@ -1457,7 +1456,7 @@ public void testCopyFileOnSameFile() throws IOException { * @throws java.lang.Exception if any. */ @Test - public void testExtensions() throws Exception { + void extensions() throws Exception { String[][] values = { {"fry.frozen", "frozen"}, @@ -1476,7 +1475,7 @@ public void testExtensions() throws Exception { String fileName = values[i][0].replace('/', File.separatorChar); String ext = values[i][1]; String computed = FileUtils.extension(fileName); - assertEquals("case [" + i + "]:" + fileName + " -> " + ext + ", computed : " + computed, ext, computed); + assertEquals(ext, computed, "case [" + i + "]:" + fileName + " -> " + ext + ", computed : " + computed); } } @@ -1486,7 +1485,7 @@ public void testExtensions() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testIsValidWindowsFileName() throws Exception { + void isValidWindowsFileName() throws Exception { File f = new File("c:\test"); assertTrue(FileUtils.isValidWindowsFileName(f)); @@ -1514,7 +1513,7 @@ public void testIsValidWindowsFileName() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testDeleteDirectoryWithValidFileSymlink() throws Exception { + void deleteDirectoryWithValidFileSymlink() throws Exception { File symlinkTarget = new File(getTestDirectory(), "fileSymlinkTarget"); createFile(symlinkTarget, 1); File symlink = new File(getTestDirectory(), "fileSymlink"); @@ -1527,7 +1526,7 @@ public void testDeleteDirectoryWithValidFileSymlink() throws Exception { */ symlink.delete(); } - assertTrue("Failed to delete test directory", !getTestDirectory().exists()); + assertFalse(getTestDirectory().exists(), "Failed to delete test directory"); } /** @@ -1536,7 +1535,7 @@ public void testDeleteDirectoryWithValidFileSymlink() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testDeleteDirectoryWithValidDirSymlink() throws Exception { + void deleteDirectoryWithValidDirSymlink() throws Exception { File symlinkTarget = new File(getTestDirectory(), "dirSymlinkTarget"); symlinkTarget.mkdir(); File symlink = new File(getTestDirectory(), "dirSymlink"); @@ -1549,7 +1548,7 @@ public void testDeleteDirectoryWithValidDirSymlink() throws Exception { */ symlink.delete(); } - assertTrue("Failed to delete test directory", !getTestDirectory().exists()); + assertFalse(getTestDirectory().exists(), "Failed to delete test directory"); } /** @@ -1558,7 +1557,7 @@ public void testDeleteDirectoryWithValidDirSymlink() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testDeleteDirectoryWithDanglingSymlink() throws Exception { + void deleteDirectoryWithDanglingSymlink() throws Exception { File symlinkTarget = new File(getTestDirectory(), "missingSymlinkTarget"); File symlink = new File(getTestDirectory(), "danglingSymlink"); createSymlink(symlink, symlinkTarget); @@ -1570,7 +1569,7 @@ public void testDeleteDirectoryWithDanglingSymlink() throws Exception { */ symlink.delete(); } - assertTrue("Failed to delete test directory", !getTestDirectory().exists()); + assertFalse(getTestDirectory().exists(), "Failed to delete test directory"); } /** @@ -1579,7 +1578,7 @@ public void testDeleteDirectoryWithDanglingSymlink() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testcopyDirectoryLayoutWithExcludesIncludes() throws Exception { + void testcopyDirectoryLayoutWithExcludesIncludes() throws Exception { File destination = new File("target", "copyDirectoryStructureWithExcludesIncludes"); if (!destination.exists()) { destination.mkdirs(); @@ -1613,12 +1612,11 @@ public void testcopyDirectoryLayoutWithExcludesIncludes() throws Exception { * @throws java.lang.Exception if any */ @Test - public void testCreateTempFile() throws Exception { + void createTempFile() throws Exception { File last = FileUtils.createTempFile("unique", ".tmp", null); for (int i = 0; i < 10; i++) { File current = FileUtils.createTempFile("unique", ".tmp", null); - assertTrue( - "No unique name: " + current.getName(), !current.getName().equals(last.getName())); + assertNotEquals(current.getName(), last.getName(), "No unique name: " + current.getName()); last = current; } } diff --git a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java index f235c495..a11c2020 100644 --- a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java @@ -26,14 +26,11 @@ import java.io.Reader; import java.io.Writer; import java.nio.file.Files; -import java.util.Arrays; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; /** * This is used to test IOUtil for correctness. The following checks are performed: @@ -66,8 +63,8 @@ public final class IOUtilTest { /** *

setUp.

*/ - @Before - public void setUp() { + @BeforeEach + void setUp() { try { testDirectory = (new File("target/test/io/")).getAbsoluteFile(); if (!testDirectory.exists()) { @@ -102,32 +99,28 @@ private void createFile(File file, long size) throws IOException { /** Assert that the contents of two byte arrays are the same. */ private void assertEqualContent(byte[] b0, byte[] b1) { - assertTrue("Content not equal according to java.util.Arrays#equals()", Arrays.equals(b0, b1)); + 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 { - InputStream is0 = Files.newInputStream(f0.toPath()); - InputStream is1 = Files.newInputStream(f1.toPath()); byte[] buf0 = new byte[FILE_SIZE]; byte[] buf1 = new byte[FILE_SIZE]; int n0 = 0; int n1 = 0; - try { + try (InputStream is0 = Files.newInputStream(f0.toPath()); + InputStream is1 = Files.newInputStream(f1.toPath())) { while (0 <= n0) { n0 = is0.read(buf0); n1 = is1.read(buf1); assertTrue( + (n0 == n1), "The files " + f0 + " and " + f1 + " have differing number of bytes available (" + n0 + " vs " - + n1 + ")", - (n0 == n1)); + + n1 + ")"); - assertTrue("The files " + f0 + " and " + f1 + " have different content", Arrays.equals(buf0, buf1)); + assertArrayEquals(buf0, buf1, "The files " + f0 + " and " + f1 + " have different content"); } - } finally { - is0.close(); - is1.close(); } } @@ -136,10 +129,10 @@ private void assertEqualContent(byte[] b0, File file) throws IOException { InputStream is = Files.newInputStream(file.toPath()); byte[] b1 = new byte[b0.length]; int numRead = is.read(b1); - assertTrue("Different number of bytes", numRead == b0.length && is.available() == 0); + assertTrue(numRead == b0.length && is.available() == 0, "Different number of bytes"); for (int i = 0; i < numRead; - assertTrue("Byte " + i + " differs (" + b0[i] + " != " + b1[i] + ")", b0[i] == b1[i]), i++) + assertEquals(b0[i], b1[i], "Byte " + i + " differs (" + b0[i] + " != " + b1[i] + ")"), i++) ; is.close(); } @@ -150,13 +143,13 @@ private void assertEqualContent(byte[] b0, File file) throws IOException { * @throws java.lang.Exception if any. */ @Test - public void testInputStreamToOutputStream() throws Exception { + void inputStreamToOutputStream() throws Exception { File destination = newFile("copy1.txt"); InputStream fin = Files.newInputStream(testFile.toPath()); OutputStream fout = Files.newOutputStream(destination.toPath()); IOUtil.copy(fin, fout); - assertTrue("Not all bytes were read", fin.available() == 0); + assertEquals(0, fin.available(), "Not all bytes were read"); fout.flush(); checkFile(destination); @@ -172,14 +165,14 @@ public void testInputStreamToOutputStream() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testInputStreamToWriter() throws Exception { + void inputStreamToWriter() throws Exception { File destination = newFile("copy2.txt"); InputStream fin = Files.newInputStream(testFile.toPath()); Writer fout = Files.newBufferedWriter(destination.toPath()); IOUtil.copy(fin, fout); - assertTrue("Not all bytes were read", fin.available() == 0); + assertEquals(0, fin.available(), "Not all bytes were read"); fout.flush(); checkFile(destination); @@ -195,12 +188,12 @@ public void testInputStreamToWriter() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testInputStreamToString() throws Exception { + void inputStreamToString() throws Exception { InputStream fin = Files.newInputStream(testFile.toPath()); String out = IOUtil.toString(fin); assertNotNull(out); - assertTrue("Not all bytes were read", fin.available() == 0); - assertTrue("Wrong output size: out.length()=" + out.length() + "!=" + FILE_SIZE, out.length() == FILE_SIZE); + assertEquals(0, fin.available(), "Not all bytes were read"); + assertEquals(out.length(), FILE_SIZE, "Wrong output size: out.length()=" + out.length() + "!=" + FILE_SIZE); fin.close(); } @@ -210,7 +203,7 @@ public void testInputStreamToString() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testReaderToOutputStream() throws Exception { + void readerToOutputStream() throws Exception { File destination = newFile("copy3.txt"); Reader fin = Files.newBufferedReader(testFile.toPath()); OutputStream fout = Files.newOutputStream(destination.toPath()); @@ -235,7 +228,7 @@ public void testReaderToOutputStream() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testReaderToWriter() throws Exception { + void readerToWriter() throws Exception { File destination = newFile("copy4.txt"); Reader fin = Files.newBufferedReader(testFile.toPath()); Writer fout = Files.newBufferedWriter(destination.toPath()); @@ -255,11 +248,11 @@ public void testReaderToWriter() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testReaderToString() throws Exception { + void readerToString() throws Exception { Reader fin = Files.newBufferedReader(testFile.toPath()); String out = IOUtil.toString(fin); assertNotNull(out); - assertTrue("Wrong output size: out.length()=" + out.length() + "!=" + FILE_SIZE, out.length() == FILE_SIZE); + assertEquals(out.length(), FILE_SIZE, "Wrong output size: out.length()=" + out.length() + "!=" + FILE_SIZE); fin.close(); } @@ -269,7 +262,7 @@ public void testReaderToString() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testStringToOutputStream() throws Exception { + void stringToOutputStream() throws Exception { File destination = newFile("copy5.txt"); Reader fin = Files.newBufferedReader(testFile.toPath()); // Create our String. Rely on testReaderToString() to make sure this is valid. @@ -296,7 +289,7 @@ public void testStringToOutputStream() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testStringToWriter() throws Exception { + void stringToWriter() throws Exception { File destination = newFile("copy6.txt"); Reader fin = Files.newBufferedReader(testFile.toPath()); // Create our String. Rely on testReaderToString() to make sure this is valid. @@ -319,12 +312,12 @@ public void testStringToWriter() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testInputStreamToByteArray() throws Exception { + void inputStreamToByteArray() throws Exception { InputStream fin = Files.newInputStream(testFile.toPath()); byte[] out = IOUtil.toByteArray(fin); assertNotNull(out); - assertTrue("Not all bytes were read", fin.available() == 0); - assertTrue("Wrong output size: out.length=" + out.length + "!=" + FILE_SIZE, out.length == FILE_SIZE); + assertEquals(0, fin.available(), "Not all bytes were read"); + assertEquals(out.length, FILE_SIZE, "Wrong output size: out.length=" + out.length + "!=" + FILE_SIZE); assertEqualContent(out, testFile); fin.close(); } @@ -335,7 +328,7 @@ public void testInputStreamToByteArray() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testStringToByteArray() throws Exception { + void stringToByteArray() throws Exception { Reader fin = Files.newBufferedReader(testFile.toPath()); // Create our String. Rely on testReaderToString() to make sure this is valid. @@ -352,7 +345,7 @@ public void testStringToByteArray() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testByteArrayToWriter() throws Exception { + void byteArrayToWriter() throws Exception { File destination = newFile("copy7.txt"); Writer fout = Files.newBufferedWriter(destination.toPath()); InputStream fin = Files.newInputStream(testFile.toPath()); @@ -374,7 +367,7 @@ public void testByteArrayToWriter() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testByteArrayToString() throws Exception { + void byteArrayToString() throws Exception { InputStream fin = Files.newInputStream(testFile.toPath()); byte[] in = IOUtil.toByteArray(fin); // Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid. @@ -389,7 +382,7 @@ public void testByteArrayToString() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testByteArrayToOutputStream() throws Exception { + void byteArrayToOutputStream() throws Exception { File destination = newFile("copy8.txt"); OutputStream fout = Files.newOutputStream(destination.toPath()); InputStream fin = Files.newInputStream(testFile.toPath()); @@ -418,7 +411,7 @@ public void testByteArrayToOutputStream() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCloseInputStream() throws Exception { + void closeInputStream() throws Exception { IOUtil.close((InputStream) null); TestInputStream inputStream = new TestInputStream(); @@ -434,7 +427,7 @@ public void testCloseInputStream() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCloseOutputStream() throws Exception { + void closeOutputStream() throws Exception { IOUtil.close((OutputStream) null); TestOutputStream outputStream = new TestOutputStream(); @@ -450,7 +443,7 @@ public void testCloseOutputStream() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCloseReader() throws Exception { + void closeReader() throws Exception { IOUtil.close((Reader) null); TestReader reader = new TestReader(); @@ -466,7 +459,7 @@ public void testCloseReader() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCloseWriter() throws Exception { + void closeWriter() throws Exception { IOUtil.close((Writer) null); TestWriter writer = new TestWriter(); @@ -538,13 +531,13 @@ public void flush() { private File newFile(String filename) throws Exception { File destination = new File(testDirectory, filename); - assertTrue(filename + "Test output data file shouldn't previously exist", !destination.exists()); + assertFalse(destination.exists(), filename + "Test output data file shouldn't previously exist"); return destination; } private void checkFile(File file) throws Exception { - assertTrue("Check existence of output file", file.exists()); + assertTrue(file.exists(), "Check existence of output file"); assertEqualContent(testFile, file); } @@ -565,10 +558,11 @@ private void checkWrite(Writer output) throws Exception { } private void deleteFile(File file) throws Exception { - assertTrue( - "Wrong output size: file.length()=" + file.length() + "!=" + FILE_SIZE + 1, - file.length() == FILE_SIZE + 1); + assertEquals( + file.length(), + FILE_SIZE + 1, + "Wrong output size: file.length()=" + file.length() + "!=" + FILE_SIZE + 1); - assertTrue("File would not delete", (file.delete() || (!file.exists()))); + assertTrue((file.delete() || (!file.exists())), "File would not delete"); } } diff --git a/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java b/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java index 66cec400..a8f86410 100644 --- a/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java +++ b/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java @@ -20,9 +20,9 @@ import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** *

InterpolationFilterReaderTest class.

@@ -31,7 +31,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class InterpolationFilterReaderTest { +class InterpolationFilterReaderTest { /* * Added and commented by jdcasey@03-Feb-2005 because it is a bug in the InterpolationFilterReader. * kenneyw@15-04-2005 fixed the bug. @@ -42,8 +42,8 @@ public class InterpolationFilterReaderTest { * @throws java.lang.Exception if any. */ @Test - public void testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Exception { - Map m = new HashMap(); + void shouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Exception { + Map m = new HashMap<>(); m.put("test", "TestValue"); String testStr = "This is a ${test"; @@ -60,8 +60,8 @@ public void testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() t * @throws java.lang.Exception if any. */ @Test - public void testShouldNotInterpolateExpressionWithMissingEndToken() throws Exception { - Map m = new HashMap(); + void shouldNotInterpolateExpressionWithMissingEndToken() throws Exception { + Map m = new HashMap<>(); m.put("test", "TestValue"); String testStr = "This is a ${test, really"; @@ -75,8 +75,8 @@ public void testShouldNotInterpolateExpressionWithMissingEndToken() throws Excep * @throws java.lang.Exception if any. */ @Test - public void testShouldNotInterpolateWithMalformedStartToken() throws Exception { - Map m = new HashMap(); + void shouldNotInterpolateWithMalformedStartToken() throws Exception { + Map m = new HashMap<>(); m.put("test", "testValue"); String foo = "This is a $!test} again"; @@ -90,8 +90,8 @@ public void testShouldNotInterpolateWithMalformedStartToken() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testShouldNotInterpolateWithMalformedEndToken() throws Exception { - Map m = new HashMap(); + void shouldNotInterpolateWithMalformedEndToken() throws Exception { + Map m = new HashMap<>(); m.put("test", "testValue"); String foo = "This is a ${test!} again"; @@ -105,8 +105,8 @@ public void testShouldNotInterpolateWithMalformedEndToken() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testInterpolationWithMulticharDelimiters() throws Exception { - Map m = new HashMap(); + void interpolationWithMulticharDelimiters() throws Exception { + Map m = new HashMap<>(); m.put("test", "testValue"); String foo = "This is a ${test$} again"; @@ -120,8 +120,8 @@ public void testInterpolationWithMulticharDelimiters() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { - Map m = new HashMap(); + void defaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -136,8 +136,8 @@ public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Excep * @throws java.lang.Exception if any. */ @Test - public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exception { - Map m = new HashMap(); + void defaultInterpolationWithInterpolatedValueAtEnd() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -152,8 +152,8 @@ public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exceptio * @throws java.lang.Exception if any. */ @Test - public void testInterpolationWithSpecifiedBoundaryTokens() throws Exception { - Map m = new HashMap(); + void interpolationWithSpecifiedBoundaryTokens() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -168,8 +168,8 @@ public void testInterpolationWithSpecifiedBoundaryTokens() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd() throws Exception { - Map m = new HashMap(); + void interpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -184,8 +184,8 @@ public void testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValue * @throws java.lang.Exception if any. */ @Test - public void testInterpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd() throws Exception { - Map m = new HashMap(); + void interpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -200,8 +200,8 @@ public void testInterpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtE * @throws java.lang.Exception if any. */ @Test - public void testInterpolationWithSpecifiedBoundaryTokensAndAdditionalTokenCharacter() throws Exception { - Map m = new HashMap(); + void interpolationWithSpecifiedBoundaryTokensAndAdditionalTokenCharacter() throws Exception { + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); diff --git a/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java b/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java index 77f82fcc..612d41a8 100644 --- a/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java +++ b/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java @@ -24,9 +24,9 @@ import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Generated by JUnitDoclet, a tool provided by ObjectFab GmbH under LGPL. Please see www.junitdoclet.org, www.gnu.org @@ -36,7 +36,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class LineOrientedInterpolatingReaderTest { +class LineOrientedInterpolatingReaderTest { /* * Added and commented by jdcasey@03-Feb-2005 because it is a bug in the InterpolationFilterReader. */ @@ -46,7 +46,7 @@ public class LineOrientedInterpolatingReaderTest { * @throws java.io.IOException if any. */ @Test - public void testShouldInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws IOException { + void shouldInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws IOException { String testStr = "This is a ${test"; LineOrientedInterpolatingReader iReader = new LineOrientedInterpolatingReader( new StringReader(testStr), Collections.singletonMap("test", "TestValue")); @@ -63,7 +63,7 @@ public void testShouldInterpolateExpressionAtEndOfDataWithInvalidEndToken() thro * @throws java.lang.Exception if any. */ @Test - public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { + void defaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { Map m = getStandardMap(); String foo = "${name} is an ${noun}. ${not.interpolated}"; @@ -78,7 +78,7 @@ public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Excep } private Map getStandardMap() { - Map m = new HashMap(); + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); return m; @@ -90,7 +90,7 @@ private Map getStandardMap() { * @throws java.lang.Exception if any. */ @Test - public void testDefaultInterpolationWithEscapedExpression() throws Exception { + void defaultInterpolationWithEscapedExpression() throws Exception { Map m = getStandardMap(); String foo = "${name} is an ${noun}. \\${noun} value"; @@ -110,7 +110,7 @@ public void testDefaultInterpolationWithEscapedExpression() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exception { + void defaultInterpolationWithInterpolatedValueAtEnd() throws Exception { Map m = getStandardMap(); String foo = "${name} is an ${noun}"; @@ -130,7 +130,7 @@ public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exceptio * @throws java.lang.Exception if any. */ @Test - public void testInterpolationWithSpecifiedBoundaryTokens() throws Exception { + void interpolationWithSpecifiedBoundaryTokens() throws Exception { Map m = getStandardMap(); String foo = "@name@ is an @noun@. @not.interpolated@ baby @foo@. @bar@"; @@ -151,7 +151,7 @@ public void testInterpolationWithSpecifiedBoundaryTokens() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd() throws Exception { + void interpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd() throws Exception { Map m = getStandardMap(); String foo = "@name@ is an @foobarred@"; @@ -172,7 +172,7 @@ public void testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValue * @throws java.lang.Exception if any. */ @Test - public void testInterpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd() throws Exception { + void interpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd() throws Exception { Map m = getStandardMap(); String foo = "@name@ is an @noun@"; diff --git a/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java b/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java index 1a73f8d3..2d8a8495 100644 --- a/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java +++ b/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java @@ -1,27 +1,11 @@ package org.codehaus.plexus.util; -/* - * Copyright The Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** *

MatchPatternTest class.

@@ -30,12 +14,12 @@ * @version $Id: $Id * @since 3.4.0 */ -public class MatchPatternTest { +class MatchPatternTest { /** *

testGetSource

*/ @Test - public void testGetSource() { + void getSource() { MatchPattern mp = MatchPattern.fromString("ABC*"); assertEquals("ABC*", mp.getSource()); mp = MatchPattern.fromString("%ant[some/ABC*]"); @@ -50,7 +34,7 @@ public void testGetSource() { * @throws java.lang.Exception if any. */ @Test - public void testMatchPath() throws Exception { + void matchPath() throws Exception { MatchPattern mp = MatchPattern.fromString("ABC*"); assertTrue(mp.matchPath("ABCD", true)); } @@ -61,7 +45,7 @@ public void testMatchPath() throws Exception { * @see Issue #63 */ @Test - public void testMatchPatternStart() { + void matchPatternStart() { MatchPattern mp = MatchPattern.fromString("ABC*"); assertTrue(mp.matchPatternStart("ABCD", true)); @@ -78,7 +62,7 @@ public void testMatchPatternStart() { *

testTokenizePathToString.

*/ @Test - public void testTokenizePathToString() { + void tokenizePathToString() { String[] expected = {"hello", "world"}; String[] actual = MatchPattern.tokenizePathToString("hello/world", "/"); assertArrayEquals(expected, actual); diff --git a/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java b/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java index 58cdcc19..12caa631 100644 --- a/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java +++ b/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java @@ -19,11 +19,11 @@ import java.util.Arrays; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** *

MatchPatternsTest class.

@@ -32,12 +32,12 @@ * @version $Id: $Id * @since 3.4.0 */ -public class MatchPatternsTest { +class MatchPatternsTest { /** *

testGetSource

*/ @Test - public void testGetSources() { + void getSources() { List expected = Arrays.asList("ABC**", "some/ABC*", "[ABC].*"); MatchPatterns from = MatchPatterns.from("ABC**", "%ant[some/ABC*]", "%regex[[ABC].*]"); List actual = from.getSources(); @@ -50,7 +50,7 @@ public void testGetSources() { * @throws java.lang.Exception if any. */ @Test - public void testMatches() throws Exception { + void matches() throws Exception { MatchPatterns from = MatchPatterns.from("ABC**", "CDE**"); assertTrue(from.matches("ABCDE", true)); assertTrue(from.matches("CDEF", true)); diff --git a/src/test/java/org/codehaus/plexus/util/OsTest.java b/src/test/java/org/codehaus/plexus/util/OsTest.java index ae049d3d..41bd5f53 100644 --- a/src/test/java/org/codehaus/plexus/util/OsTest.java +++ b/src/test/java/org/codehaus/plexus/util/OsTest.java @@ -18,11 +18,11 @@ import java.util.Iterator; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test Case for Os @@ -31,12 +31,12 @@ * @version $Id: $Id * @since 3.4.0 */ -public class OsTest { +class OsTest { /** *

testUndefinedFamily.

*/ @Test - public void testUndefinedFamily() { + void undefinedFamily() { assertFalse(Os.isFamily("bogus family")); } @@ -44,7 +44,7 @@ public void testUndefinedFamily() { *

testOs.

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

testValidList.

*/ @Test - public void testValidList() { + void validList() { assertTrue(Os.isValidFamily("dos")); assertFalse(Os.isValidFamily("")); diff --git a/src/test/java/org/codehaus/plexus/util/PathToolTest.java b/src/test/java/org/codehaus/plexus/util/PathToolTest.java index c8f41080..09c4bd6b 100644 --- a/src/test/java/org/codehaus/plexus/util/PathToolTest.java +++ b/src/test/java/org/codehaus/plexus/util/PathToolTest.java @@ -1,24 +1,8 @@ package org.codehaus.plexus.util; -/* - * Copyright The Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** *

PathToolTest class.

@@ -27,20 +11,20 @@ * @version $Id: $Id * @since 3.4.0 */ -public class PathToolTest { +class PathToolTest { /** *

testGetRelativePath.

* * @throws java.lang.Exception */ @Test - public void testGetRelativePath() throws Exception { - assertEquals(PathTool.getRelativePath(null, null), ""); - assertEquals(PathTool.getRelativePath(null, "/usr/local/java/bin"), ""); - assertEquals(PathTool.getRelativePath("/usr/local/", null), ""); - assertEquals(PathTool.getRelativePath("/usr/local/", "/usr/local/java/bin"), ".."); - assertEquals(PathTool.getRelativePath("/usr/local/", "/usr/local/java/bin/java.sh"), "../.."); - assertEquals(PathTool.getRelativePath("/usr/local/java/bin/java.sh", "/usr/local/"), ""); + void getRelativePath() throws Exception { + assertEquals("", PathTool.getRelativePath(null, null)); + assertEquals("", PathTool.getRelativePath(null, "/usr/local/java/bin")); + assertEquals("", PathTool.getRelativePath("/usr/local/", null)); + assertEquals("..", PathTool.getRelativePath("/usr/local/", "/usr/local/java/bin")); + assertEquals("../..", PathTool.getRelativePath("/usr/local/", "/usr/local/java/bin/java.sh")); + assertEquals("", PathTool.getRelativePath("/usr/local/java/bin/java.sh", "/usr/local/")); } /** @@ -49,11 +33,11 @@ public void testGetRelativePath() throws Exception { * @throws java.lang.Exception */ @Test - public void testGetDirectoryComponent() throws Exception { - assertEquals(PathTool.getDirectoryComponent(null), ""); - assertEquals(PathTool.getDirectoryComponent("/usr/local/java/bin"), "/usr/local/java"); - assertEquals(PathTool.getDirectoryComponent("/usr/local/java/bin/"), "/usr/local/java/bin"); - assertEquals(PathTool.getDirectoryComponent("/usr/local/java/bin/java.sh"), "/usr/local/java/bin"); + void getDirectoryComponent() throws Exception { + assertEquals("", PathTool.getDirectoryComponent(null)); + assertEquals("/usr/local/java", PathTool.getDirectoryComponent("/usr/local/java/bin")); + assertEquals("/usr/local/java/bin", PathTool.getDirectoryComponent("/usr/local/java/bin/")); + assertEquals("/usr/local/java/bin", PathTool.getDirectoryComponent("/usr/local/java/bin/java.sh")); } /** @@ -62,18 +46,18 @@ public void testGetDirectoryComponent() throws Exception { * @throws java.lang.Exception */ @Test - public void testCalculateLink() throws Exception { - assertEquals(PathTool.calculateLink("/index.html", "../.."), "../../index.html"); + void calculateLink() throws Exception { + assertEquals("../../index.html", PathTool.calculateLink("/index.html", "../..")); assertEquals( - PathTool.calculateLink("http://plexus.codehaus.org/plexus-utils/index.html", "../.."), - "http://plexus.codehaus.org/plexus-utils/index.html"); + "http://plexus.codehaus.org/plexus-utils/index.html", + PathTool.calculateLink("http://plexus.codehaus.org/plexus-utils/index.html", "../..")); assertEquals( - PathTool.calculateLink("/usr/local/java/bin/java.sh", "../.."), "../../usr/local/java/bin/java.sh"); + "../../usr/local/java/bin/java.sh", PathTool.calculateLink("/usr/local/java/bin/java.sh", "../..")); assertEquals( - PathTool.calculateLink("../index.html", "/usr/local/java/bin"), "/usr/local/java/bin/../index.html"); + "/usr/local/java/bin/../index.html", PathTool.calculateLink("../index.html", "/usr/local/java/bin")); assertEquals( - PathTool.calculateLink("../index.html", "http://plexus.codehaus.org/plexus-utils"), - "http://plexus.codehaus.org/plexus-utils/../index.html"); + "http://plexus.codehaus.org/plexus-utils/../index.html", + PathTool.calculateLink("../index.html", "http://plexus.codehaus.org/plexus-utils")); } /** @@ -82,18 +66,18 @@ public void testCalculateLink() throws Exception { * @throws java.lang.Exception */ @Test - public void testGetRelativeWebPath() throws Exception { - assertEquals(PathTool.getRelativeWebPath(null, null), ""); - assertEquals(PathTool.getRelativeWebPath(null, "http://plexus.codehaus.org/"), ""); - assertEquals(PathTool.getRelativeWebPath("http://plexus.codehaus.org/", null), ""); + void getRelativeWebPath() throws Exception { + assertEquals("", PathTool.getRelativeWebPath(null, null)); + assertEquals("", PathTool.getRelativeWebPath(null, "http://plexus.codehaus.org/")); + assertEquals("", PathTool.getRelativeWebPath("http://plexus.codehaus.org/", null)); assertEquals( + "plexus-utils/index.html", PathTool.getRelativeWebPath( - "http://plexus.codehaus.org/", "http://plexus.codehaus.org/plexus-utils/index.html"), - "plexus-utils/index.html"); + "http://plexus.codehaus.org/", "http://plexus.codehaus.org/plexus-utils/index.html")); assertEquals( + "../../", PathTool.getRelativeWebPath( - "http://plexus.codehaus.org/plexus-utils/index.html", "http://plexus.codehaus.org/"), - "../../"); + "http://plexus.codehaus.org/plexus-utils/index.html", "http://plexus.codehaus.org/")); } /** @@ -102,34 +86,34 @@ public void testGetRelativeWebPath() throws Exception { * @throws java.lang.Exception */ @Test - public void testGetRelativeFilePath() throws Exception { + void getRelativeFilePath() throws Exception { if (Os.isFamily(Os.FAMILY_WINDOWS)) { - assertEquals(PathTool.getRelativeFilePath(null, null), ""); - assertEquals(PathTool.getRelativeFilePath(null, "c:\\tools\\java\\bin"), ""); - assertEquals(PathTool.getRelativeFilePath("c:\\tools\\java", null), ""); - assertEquals(PathTool.getRelativeFilePath("c:\\tools", "c:\\tools\\java\\bin"), "java\\bin"); - assertEquals(PathTool.getRelativeFilePath("c:\\tools", "c:\\tools\\java\\bin\\"), "java\\bin\\"); - assertEquals(PathTool.getRelativeFilePath("c:\\tools\\java\\bin", "c:\\tools"), "..\\.."); + assertEquals("", PathTool.getRelativeFilePath(null, null)); + assertEquals("", PathTool.getRelativeFilePath(null, "c:\\tools\\java\\bin")); + assertEquals("", PathTool.getRelativeFilePath("c:\\tools\\java", null)); + assertEquals("java\\bin", PathTool.getRelativeFilePath("c:\\tools", "c:\\tools\\java\\bin")); + assertEquals("java\\bin\\", PathTool.getRelativeFilePath("c:\\tools", "c:\\tools\\java\\bin\\")); + assertEquals("..\\..", PathTool.getRelativeFilePath("c:\\tools\\java\\bin", "c:\\tools")); assertEquals( - PathTool.getRelativeFilePath("c:\\tools\\", "c:\\tools\\java\\bin\\java.exe"), - "java\\bin\\java.exe"); - assertEquals(PathTool.getRelativeFilePath("c:\\tools\\java\\bin\\java.sh", "c:\\tools"), "..\\..\\.."); - assertEquals(PathTool.getRelativeFilePath("c:\\tools", "c:\\bin"), "..\\bin"); - assertEquals(PathTool.getRelativeFilePath("c:\\bin", "c:\\tools"), "..\\tools"); - assertEquals(PathTool.getRelativeFilePath("c:\\bin", "c:\\bin"), ""); + "java\\bin\\java.exe", + PathTool.getRelativeFilePath("c:\\tools\\", "c:\\tools\\java\\bin\\java.exe")); + assertEquals("..\\..\\..", PathTool.getRelativeFilePath("c:\\tools\\java\\bin\\java.sh", "c:\\tools")); + assertEquals("..\\bin", PathTool.getRelativeFilePath("c:\\tools", "c:\\bin")); + assertEquals("..\\tools", PathTool.getRelativeFilePath("c:\\bin", "c:\\tools")); + assertEquals("", PathTool.getRelativeFilePath("c:\\bin", "c:\\bin")); } else { - assertEquals(PathTool.getRelativeFilePath(null, null), ""); - assertEquals(PathTool.getRelativeFilePath(null, "/usr/local/java/bin"), ""); - assertEquals(PathTool.getRelativeFilePath("/usr/local", null), ""); - assertEquals(PathTool.getRelativeFilePath("/usr/local", "/usr/local/java/bin"), "java/bin"); - assertEquals(PathTool.getRelativeFilePath("/usr/local", "/usr/local/java/bin/"), "java/bin/"); - assertEquals(PathTool.getRelativeFilePath("/usr/local/java/bin", "/usr/local/"), "../../"); + assertEquals("", PathTool.getRelativeFilePath(null, null)); + assertEquals("", PathTool.getRelativeFilePath(null, "/usr/local/java/bin")); + assertEquals("", PathTool.getRelativeFilePath("/usr/local", null)); + assertEquals("java/bin", PathTool.getRelativeFilePath("/usr/local", "/usr/local/java/bin")); + assertEquals("java/bin/", PathTool.getRelativeFilePath("/usr/local", "/usr/local/java/bin/")); + assertEquals("../../", PathTool.getRelativeFilePath("/usr/local/java/bin", "/usr/local/")); assertEquals( - PathTool.getRelativeFilePath("/usr/local/", "/usr/local/java/bin/java.sh"), "java/bin/java.sh"); - assertEquals(PathTool.getRelativeFilePath("/usr/local/java/bin/java.sh", "/usr/local/"), "../../../"); - assertEquals(PathTool.getRelativeFilePath("/usr/local/", "/bin"), "../../bin"); - assertEquals(PathTool.getRelativeFilePath("/bin", "/usr/local"), "../usr/local"); - assertEquals(PathTool.getRelativeFilePath("/bin", "/bin"), ""); + "java/bin/java.sh", PathTool.getRelativeFilePath("/usr/local/", "/usr/local/java/bin/java.sh")); + assertEquals("../../../", PathTool.getRelativeFilePath("/usr/local/java/bin/java.sh", "/usr/local/")); + assertEquals("../../bin", PathTool.getRelativeFilePath("/usr/local/", "/bin")); + assertEquals("../usr/local", PathTool.getRelativeFilePath("/bin", "/usr/local")); + assertEquals("", PathTool.getRelativeFilePath("/bin", "/bin")); } } } diff --git a/src/test/java/org/codehaus/plexus/util/PerfTest.java b/src/test/java/org/codehaus/plexus/util/PerfTest.java index e7542e1d..b59c34ef 100644 --- a/src/test/java/org/codehaus/plexus/util/PerfTest.java +++ b/src/test/java/org/codehaus/plexus/util/PerfTest.java @@ -1,22 +1,6 @@ package org.codehaus.plexus.util; -/* - * Copyright 2011 The Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.junit.Test; +import org.junit.jupiter.api.Test; /** *

PerfTest class.

@@ -25,7 +9,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class PerfTest { +class PerfTest { String src = "012345578901234556789012345678901234456789012345678901234567890"; private final int oops = 100; @@ -34,12 +18,12 @@ public class PerfTest { *

testSubString.

*/ @Test - public void testSubString() { + void subString() { StringBuilder res = new StringBuilder(); int len = src.length(); for (int cnt = 0; cnt < oops; cnt++) { for (int i = 0; i < len - 5; i++) { - res.append(src.substring(i, i + 4)); + res.append(src, i, i + 4); } } int i = res.length(); @@ -50,7 +34,7 @@ public void testSubString() { *

testResDir.

*/ @Test - public void testResDir() { + void resDir() { StringBuilder res = new StringBuilder(); int len = src.length(); for (int cnt = 0; cnt < oops; cnt++) { diff --git a/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java b/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java index c9e982a1..527f7d1a 100644 --- a/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java @@ -19,9 +19,9 @@ import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * This is used to test ReflectionUtils for correctness. @@ -32,7 +32,7 @@ * @since 3.4.0 */ public final class ReflectionUtilsTest { - public ReflectionUtilsTestClass testClass = new ReflectionUtilsTestClass(); + private final ReflectionUtilsTestClass testClass = new ReflectionUtilsTestClass(); /** *

testSimpleVariableAccess.

@@ -40,8 +40,8 @@ public final class ReflectionUtilsTest { * @throws java.lang.IllegalAccessException if any. */ @Test - public void testSimpleVariableAccess() throws IllegalAccessException { - assertEquals("woohoo", (String) ReflectionUtils.getValueIncludingSuperclasses("myString", testClass)); + void simpleVariableAccess() throws IllegalAccessException { + assertEquals("woohoo", ReflectionUtils.getValueIncludingSuperclasses("myString", testClass)); } /** @@ -50,13 +50,13 @@ public void testSimpleVariableAccess() throws IllegalAccessException { * @throws java.lang.IllegalAccessException if any. */ @Test - public void testComplexVariableAccess() throws IllegalAccessException { + void complexVariableAccess() throws IllegalAccessException { Map map = ReflectionUtils.getVariablesAndValuesIncludingSuperclasses(testClass); Map myMap = (Map) map.get("myMap"); - assertEquals("myValue", (String) myMap.get("myKey")); - assertEquals("myOtherValue", (String) myMap.get("myOtherKey")); + assertEquals("myValue", myMap.get("myKey")); + assertEquals("myOtherValue", myMap.get("myOtherKey")); } /** @@ -65,8 +65,8 @@ public void testComplexVariableAccess() throws IllegalAccessException { * @throws java.lang.IllegalAccessException if any. */ @Test - public void testSuperClassVariableAccess() throws IllegalAccessException { - assertEquals("super-duper", (String) ReflectionUtils.getValueIncludingSuperclasses("mySuperString", testClass)); + void superClassVariableAccess() throws IllegalAccessException { + assertEquals("super-duper", ReflectionUtils.getValueIncludingSuperclasses("mySuperString", testClass)); } /** @@ -75,15 +75,15 @@ public void testSuperClassVariableAccess() throws IllegalAccessException { * @throws java.lang.IllegalAccessException if any. */ @Test - public void testSettingVariableValue() throws IllegalAccessException { + void settingVariableValue() throws IllegalAccessException { ReflectionUtils.setVariableValueInObject(testClass, "mySettableString", "mySetString"); - assertEquals( - "mySetString", (String) ReflectionUtils.getValueIncludingSuperclasses("mySettableString", testClass)); + assertEquals("mySetString", ReflectionUtils.getValueIncludingSuperclasses("mySettableString", testClass)); ReflectionUtils.setVariableValueInObject(testClass, "myParentsSettableString", "myParentsSetString"); - assertEquals("myParentsSetString", (String) + assertEquals( + "myParentsSetString", ReflectionUtils.getValueIncludingSuperclasses("myParentsSettableString", testClass)); } @@ -93,7 +93,7 @@ private class ReflectionUtilsTestClass extends AbstractReflectionUtilsTestClass private String mySettableString; - private Map myMap = new HashMap(); + private Map myMap = new HashMap<>(); public ReflectionUtilsTestClass() { myMap.put("myKey", "myValue"); diff --git a/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java b/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java index 3e7cc488..1185d60d 100644 --- a/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java @@ -18,11 +18,11 @@ import java.io.File; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** *

SelectorUtilsTest class.

@@ -30,12 +30,12 @@ * @author herve * @since 3.4.0 */ -public class SelectorUtilsTest { +class SelectorUtilsTest { /** *

testExtractPattern.

*/ @Test - public void testExtractPattern() { + void extractPattern() { assertEquals("[A-Z].*", SelectorUtils.extractPattern("%regex[[A-Z].*]", "/")); assertEquals("ABC*", SelectorUtils.extractPattern("%ant[ABC*]", "/")); assertEquals("some/ABC*", SelectorUtils.extractPattern("%ant[some/ABC*]", "/")); @@ -48,7 +48,7 @@ public void testExtractPattern() { *

testIsAntPrefixedPattern.

*/ @Test - public void testIsAntPrefixedPattern() { + void isAntPrefixedPattern() { assertTrue(SelectorUtils.isAntPrefixedPattern("%ant[A]")); // single char not allowed assertTrue(SelectorUtils.isAntPrefixedPattern("%ant[AB]")); assertFalse(SelectorUtils.isAntPrefixedPattern("%ant[]")); @@ -59,7 +59,7 @@ public void testIsAntPrefixedPattern() { *

testIsRegexPrefixedPattern.

*/ @Test - public void testIsRegexPrefixedPattern() { + void isRegexPrefixedPattern() { assertTrue(SelectorUtils.isRegexPrefixedPattern("%regex[A]")); // single char not allowed assertTrue(SelectorUtils.isRegexPrefixedPattern("%regex[.*]")); assertFalse(SelectorUtils.isRegexPrefixedPattern("%regex[]")); @@ -70,7 +70,7 @@ public void testIsRegexPrefixedPattern() { *

testMatchPath_DefaultFileSeparator.

*/ @Test - public void testMatchPath_DefaultFileSeparator() { + void matchPathDefaultFileSeparator() { String separator = File.separator; // Pattern and target start with file separator @@ -88,7 +88,7 @@ public void testMatchPath_DefaultFileSeparator() { *

testMatchPath_UnixFileSeparator.

*/ @Test - public void testMatchPath_UnixFileSeparator() { + void matchPathUnixFileSeparator() { String separator = "/"; // Pattern and target start with file separator @@ -108,7 +108,7 @@ public void testMatchPath_UnixFileSeparator() { *

testMatchPath_WindowsFileSeparator.

*/ @Test - public void testMatchPath_WindowsFileSeparator() { + void matchPathWindowsFileSeparator() { String separator = "\\"; // Pattern and target start with file separator @@ -125,29 +125,29 @@ public void testMatchPath_WindowsFileSeparator() { } @Test - public void testPatternMatchSingleWildcardPosix() { + void patternMatchSingleWildcardPosix() { assertFalse(SelectorUtils.matchPath("/com/test/*", "/com/test/test/hallo")); } @Test - public void testPatternMatchDoubleWildcardCaseInsensitivePosix() { + void patternMatchDoubleWildcardCaseInsensitivePosix() { assertTrue(SelectorUtils.matchPath("/com/test/**", "/com/test/test/hallo")); } @Test - public void testPatternMatchDoubleWildcardPosix() { + void patternMatchDoubleWildcardPosix() { assertTrue(SelectorUtils.matchPath("/com/test/**", "/com/test/test/hallo")); } @Test - public void testPatternMatchSingleWildcardWindows() { + void patternMatchSingleWildcardWindows() { assertFalse(SelectorUtils.matchPath("D:\\com\\test\\*", "D:\\com\\test\\test\\hallo")); assertFalse(SelectorUtils.matchPath("D:/com/test/*", "D:/com/test/test/hallo")); } @Test - public void testPatternMatchDoubleWildcardWindows() { + void patternMatchDoubleWildcardWindows() { assertTrue(SelectorUtils.matchPath("D:\\com\\test\\**", "D:\\com\\test\\test\\hallo")); assertTrue(SelectorUtils.matchPath("D:\\com\\test\\**", "D:/com/test/test/hallo")); diff --git a/src/test/java/org/codehaus/plexus/util/StringInputStreamTest.java b/src/test/java/org/codehaus/plexus/util/StringInputStreamTest.java index 0a76f8c8..a9e1ada7 100644 --- a/src/test/java/org/codehaus/plexus/util/StringInputStreamTest.java +++ b/src/test/java/org/codehaus/plexus/util/StringInputStreamTest.java @@ -1,22 +1,6 @@ package org.codehaus.plexus.util; -/* - * Copyright The Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; /** *

StringInputStreamTest class.

@@ -25,9 +9,10 @@ * @version $Id: $Id * @since 3.4.0 */ -public class StringInputStreamTest extends TestCase { +class StringInputStreamTest { /** *

testFoo.

*/ - public void testFoo() {} + @Test + void foo() {} } diff --git a/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java b/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java index d4ad8856..8640fa45 100644 --- a/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java @@ -17,13 +17,12 @@ */ import java.util.Arrays; +import java.util.Collections; import java.util.Locale; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Test string utils. @@ -32,34 +31,34 @@ * @version $Id: $Id * @since 3.4.0 */ -public class StringUtilsTest { +class StringUtilsTest { /** *

testIsEmpty.

*/ @Test - public void testIsEmpty() { - assertEquals(true, StringUtils.isEmpty(null)); - assertEquals(true, StringUtils.isEmpty("")); - assertEquals(false, StringUtils.isEmpty(" ")); - assertEquals(false, StringUtils.isEmpty("foo")); - assertEquals(false, StringUtils.isEmpty(" foo ")); + void isEmpty() { + assertTrue(StringUtils.isEmpty(null)); + assertTrue(StringUtils.isEmpty("")); + assertFalse(StringUtils.isEmpty(" ")); + assertFalse(StringUtils.isEmpty("foo")); + assertFalse(StringUtils.isEmpty(" foo ")); } /** *

testIsNotEmpty.

*/ @Test - public void testIsNotEmpty() { - assertEquals(false, StringUtils.isNotEmpty(null)); - assertEquals(false, StringUtils.isNotEmpty("")); - assertEquals(true, StringUtils.isNotEmpty(" ")); - assertEquals(true, StringUtils.isNotEmpty("foo")); - assertEquals(true, StringUtils.isNotEmpty(" foo ")); + void isNotEmpty() { + assertFalse(StringUtils.isNotEmpty(null)); + assertFalse(StringUtils.isNotEmpty("")); + assertTrue(StringUtils.isNotEmpty(" ")); + assertTrue(StringUtils.isNotEmpty("foo")); + assertTrue(StringUtils.isNotEmpty(" foo ")); } @Test - public void testIsNotEmptyNegatesIsEmpty() { + void isNotEmptyNegatesIsEmpty() { assertEquals(!StringUtils.isEmpty(null), StringUtils.isNotEmpty(null)); assertEquals(!StringUtils.isEmpty(""), StringUtils.isNotEmpty("")); assertEquals(!StringUtils.isEmpty(" "), StringUtils.isNotEmpty(" ")); @@ -71,31 +70,31 @@ public void testIsNotEmptyNegatesIsEmpty() { *

testIsBlank.

*/ @Test - public void testIsBlank() { - assertEquals(true, StringUtils.isBlank(null)); - assertEquals(true, StringUtils.isBlank("")); - assertEquals(true, StringUtils.isBlank(" \t\r\n")); - assertEquals(false, StringUtils.isBlank("foo")); - assertEquals(false, StringUtils.isBlank(" foo ")); + void isBlank() { + assertTrue(StringUtils.isBlank(null)); + assertTrue(StringUtils.isBlank("")); + assertTrue(StringUtils.isBlank(" \t\r\n")); + assertFalse(StringUtils.isBlank("foo")); + assertFalse(StringUtils.isBlank(" foo ")); } /** *

testIsNotBlank.

*/ @Test - public void testIsNotBlank() { - assertEquals(false, StringUtils.isNotBlank(null)); - assertEquals(false, StringUtils.isNotBlank("")); - assertEquals(false, StringUtils.isNotBlank(" \t\r\n")); - assertEquals(true, StringUtils.isNotBlank("foo")); - assertEquals(true, StringUtils.isNotBlank(" foo ")); + void isNotBlank() { + assertFalse(StringUtils.isNotBlank(null)); + assertFalse(StringUtils.isNotBlank("")); + assertFalse(StringUtils.isNotBlank(" \t\r\n")); + assertTrue(StringUtils.isNotBlank("foo")); + assertTrue(StringUtils.isNotBlank(" foo ")); } /** *

testCapitalizeFirstLetter.

*/ @Test - public void testCapitalizeFirstLetter() { + void capitalizeFirstLetter() { assertEquals("Id", StringUtils.capitalizeFirstLetter("id")); assertEquals("Id", StringUtils.capitalizeFirstLetter("Id")); } @@ -104,7 +103,7 @@ public void testCapitalizeFirstLetter() { *

testCapitalizeFirstLetterTurkish.

*/ @Test - public void testCapitalizeFirstLetterTurkish() { + void capitalizeFirstLetterTurkish() { Locale l = Locale.getDefault(); Locale.setDefault(new Locale("tr")); assertEquals("Id", StringUtils.capitalizeFirstLetter("id")); @@ -116,7 +115,7 @@ public void testCapitalizeFirstLetterTurkish() { *

testLowerCaseFirstLetter.

*/ @Test - public void testLowerCaseFirstLetter() { + void lowerCaseFirstLetter() { assertEquals("id", StringUtils.lowercaseFirstLetter("id")); assertEquals("id", StringUtils.lowercaseFirstLetter("Id")); } @@ -125,7 +124,7 @@ public void testLowerCaseFirstLetter() { *

testLowerCaseFirstLetterTurkish.

*/ @Test - public void testLowerCaseFirstLetterTurkish() { + void lowerCaseFirstLetterTurkish() { Locale l = Locale.getDefault(); Locale.setDefault(new Locale("tr")); assertEquals("id", StringUtils.lowercaseFirstLetter("id")); @@ -137,7 +136,7 @@ public void testLowerCaseFirstLetterTurkish() { *

testRemoveAndHump.

*/ @Test - public void testRemoveAndHump() { + void removeAndHump() { assertEquals("Id", StringUtils.removeAndHump("id", "-")); assertEquals("SomeId", StringUtils.removeAndHump("some-id", "-")); } @@ -146,7 +145,7 @@ public void testRemoveAndHump() { *

testRemoveAndHumpTurkish.

*/ @Test - public void testRemoveAndHumpTurkish() { + void removeAndHumpTurkish() { Locale l = Locale.getDefault(); Locale.setDefault(new Locale("tr")); assertEquals("Id", StringUtils.removeAndHump("id", "-")); @@ -158,9 +157,9 @@ public void testRemoveAndHumpTurkish() { *

testQuote_EscapeEmbeddedSingleQuotes.

*/ @Test - public void testQuote_EscapeEmbeddedSingleQuotes() { - String src = "This \'is a\' test"; - String check = "\'This \\\'is a\\\' test\'"; + void quoteEscapeEmbeddedSingleQuotes() { + String src = "This 'is a' test"; + String check = "'This \\'is a\\' test'"; char[] escaped = {'\'', '\"'}; String result = StringUtils.quoteAndEscape(src, '\'', escaped, '\\', false); @@ -172,9 +171,9 @@ public void testQuote_EscapeEmbeddedSingleQuotes() { *

testQuote_EscapeEmbeddedSingleQuotesWithPattern.

*/ @Test - public void testQuote_EscapeEmbeddedSingleQuotesWithPattern() { - String src = "This \'is a\' test"; - String check = "\'This pre'postis apre'post test\'"; + void quoteEscapeEmbeddedSingleQuotesWithPattern() { + String src = "This 'is a' test"; + String check = "'This pre'postis apre'post test'"; char[] escaped = {'\'', '\"'}; String result = StringUtils.quoteAndEscape(src, '\'', escaped, new char[] {' '}, "pre%spost", false); @@ -186,9 +185,9 @@ public void testQuote_EscapeEmbeddedSingleQuotesWithPattern() { *

testQuote_EscapeEmbeddedDoubleQuotesAndSpaces.

*/ @Test - public void testQuote_EscapeEmbeddedDoubleQuotesAndSpaces() { + void quoteEscapeEmbeddedDoubleQuotesAndSpaces() { String src = "This \"is a\" test"; - String check = "\'This\\ \\\"is\\ a\\\"\\ test\'"; + String check = "'This\\ \\\"is\\ a\\\"\\ test'"; char[] escaped = {'\'', '\"', ' '}; String result = StringUtils.quoteAndEscape(src, '\'', escaped, '\\', false); @@ -200,7 +199,7 @@ public void testQuote_EscapeEmbeddedDoubleQuotesAndSpaces() { *

testQuote_DontQuoteIfUnneeded.

*/ @Test - public void testQuote_DontQuoteIfUnneeded() { + void quoteDontQuoteIfUnneeded() { String src = "ThisIsATest"; char[] escaped = {'\'', '\"'}; @@ -213,9 +212,9 @@ public void testQuote_DontQuoteIfUnneeded() { *

testQuote_WrapWithSingleQuotes.

*/ @Test - public void testQuote_WrapWithSingleQuotes() { + void quoteWrapWithSingleQuotes() { String src = "This is a test"; - String check = "\'This is a test\'"; + String check = "'This is a test'"; char[] escaped = {'\'', '\"'}; String result = StringUtils.quoteAndEscape(src, '\'', escaped, '\\', false); @@ -227,8 +226,8 @@ public void testQuote_WrapWithSingleQuotes() { *

testQuote_PreserveExistingQuotes.

*/ @Test - public void testQuote_PreserveExistingQuotes() { - String src = "\'This is a test\'"; + void quotePreserveExistingQuotes() { + String src = "'This is a test'"; char[] escaped = {'\'', '\"'}; String result = StringUtils.quoteAndEscape(src, '\'', escaped, '\\', false); @@ -240,9 +239,9 @@ public void testQuote_PreserveExistingQuotes() { *

testQuote_WrapExistingQuotesWhenForceIsTrue.

*/ @Test - public void testQuote_WrapExistingQuotesWhenForceIsTrue() { - String src = "\'This is a test\'"; - String check = "\'\\\'This is a test\\\'\'"; + void quoteWrapExistingQuotesWhenForceIsTrue() { + String src = "'This is a test'"; + String check = "'\\'This is a test\\''"; char[] escaped = {'\'', '\"'}; String result = StringUtils.quoteAndEscape(src, '\'', escaped, '\\', true); @@ -254,8 +253,8 @@ public void testQuote_WrapExistingQuotesWhenForceIsTrue() { *

testQuote_ShortVersion_SingleQuotesPreserved.

*/ @Test - public void testQuote_ShortVersion_SingleQuotesPreserved() { - String src = "\'This is a test\'"; + void quoteShortVersionSingleQuotesPreserved() { + String src = "'This is a test'"; String result = StringUtils.quoteAndEscape(src, '\''); @@ -266,32 +265,32 @@ public void testQuote_ShortVersion_SingleQuotesPreserved() { *

testSplit.

*/ @Test - public void testSplit() { + void split() { String[] tokens; tokens = StringUtils.split("", ", "); assertNotNull(tokens); - assertEquals(Arrays.asList(new String[0]), Arrays.asList(tokens)); + assertEquals(Collections.emptyList(), Arrays.asList(tokens)); tokens = StringUtils.split(", ,,, ,", ", "); assertNotNull(tokens); - assertEquals(Arrays.asList(new String[0]), Arrays.asList(tokens)); + assertEquals(Collections.emptyList(), Arrays.asList(tokens)); tokens = StringUtils.split("this", ", "); assertNotNull(tokens); - assertEquals(Arrays.asList(new String[] {"this"}), Arrays.asList(tokens)); + assertEquals(Collections.singletonList("this"), Arrays.asList(tokens)); tokens = StringUtils.split("this is a test", ", "); assertNotNull(tokens); - assertEquals(Arrays.asList(new String[] {"this", "is", "a", "test"}), Arrays.asList(tokens)); + assertEquals(Arrays.asList("this", "is", "a", "test"), Arrays.asList(tokens)); tokens = StringUtils.split(" this is a test ", ", "); assertNotNull(tokens); - assertEquals(Arrays.asList(new String[] {"this", "is", "a", "test"}), Arrays.asList(tokens)); + assertEquals(Arrays.asList("this", "is", "a", "test"), Arrays.asList(tokens)); tokens = StringUtils.split("this is a test, really", ", "); assertNotNull(tokens); - assertEquals(Arrays.asList(new String[] {"this", "is", "a", "test", "really"}), Arrays.asList(tokens)); + assertEquals(Arrays.asList("this", "is", "a", "test", "really"), Arrays.asList(tokens)); } /** @@ -300,7 +299,7 @@ public void testSplit() { * @throws java.lang.Exception if any. */ @Test - public void testRemoveDuplicateWhitespace() throws Exception { + void removeDuplicateWhitespace() throws Exception { String s = "this is test "; assertEquals("this is test ", StringUtils.removeDuplicateWhitespace(s)); s = "this \r\n is \n \r test "; @@ -317,14 +316,14 @@ public void testRemoveDuplicateWhitespace() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testUnifyLineSeparators() throws Exception { + void unifyLineSeparators() throws Exception { String s = "this\r\nis\na\r\ntest"; try { StringUtils.unifyLineSeparators(s, "abs"); - assertTrue("Exception NOT catched", false); + fail("Exception NOT catched"); } catch (IllegalArgumentException e) { - assertTrue("Exception catched", true); + assertTrue(true, "Exception catched"); } assertEquals("this\nis\na\ntest", StringUtils.unifyLineSeparators(s, "\n")); diff --git a/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java b/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java index 2ca71500..46267a46 100644 --- a/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java +++ b/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java @@ -18,16 +18,16 @@ import java.util.Vector; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Created on 21/06/2003 @@ -36,7 +36,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class SweeperPoolTest { +class SweeperPoolTest { /** The pool under test */ TestObjectPool pool; @@ -57,7 +57,7 @@ public class SweeperPoolTest { * Test the pool limits it's size, and disposes unneeded objects correctly */ @Test - public void testMaxSize() { + void maxSize() { int sweepInterval = 0; int initialCapacity = 5; int maxSize = 2; @@ -67,34 +67,31 @@ public void testMaxSize() { pool = new TestObjectPool(maxSize, minSize, initialCapacity, sweepInterval, triggerSize); Object tmp = pool.get(); - assertNull("Expected object from pool to be null", tmp); + assertNull(tmp, "Expected object from pool to be null"); pool.put(o1); - assertEquals("Expected pool to contain 1 object", 1, pool.getSize()); + assertEquals(1, pool.getSize(), "Expected pool to contain 1 object"); tmp = pool.get(); - assertSame("Expected returned pool object to be the same as the one put in", tmp, o1); + assertSame(tmp, o1, "Expected returned pool object to be the same as the one put in"); pool.put(o1); pool.put(o2); - assertEquals("Expected pool to contain 2 objects", 2, pool.getSize()); + assertEquals(2, pool.getSize(), "Expected pool to contain 2 objects"); pool.put(o3); - assertEquals("Expected pool to contain only a maximum of 2 objects.", 2, pool.getSize()); - assertEquals( - "Expected 1 disposed pool object", - 1, - pool.testGetDisposedObjects().size()); + assertEquals(2, pool.getSize(), "Expected pool to contain only a maximum of 2 objects."); + assertEquals(1, pool.testGetDisposedObjects().size(), "Expected 1 disposed pool object"); tmp = pool.testGetDisposedObjects().iterator().next(); tmp = pool.get(); - assertEquals("Expected pool size to be 1 after removing one object", 1, pool.getSize()); + assertEquals(1, pool.getSize(), "Expected pool size to be 1 after removing one object"); Object tmp2 = pool.get(); - assertEquals("Expected pool size to be 0 after removing 2 objects", 0, pool.getSize()); - assertNotSame("Expected returned objects to be different", tmp, tmp2); + assertEquals(0, pool.getSize(), "Expected pool size to be 0 after removing 2 objects"); + assertNotSame(tmp, tmp2, "Expected returned objects to be different"); } /** *

testSweepAndTrim1.

*/ @Test - public void testSweepAndTrim1() { + void sweepAndTrim1() { // test trigger int sweepInterval = 1; int initialCapacity = 5; @@ -115,9 +112,8 @@ public void testSweepAndTrim1() { fail("Unexpected exception thrown. e=" + Tracer.traceToString(e)); } } - assertEquals("Expected pool to only contain 1 object", 1, pool.getSize()); - assertEquals( - "Expected 3 disposed objects", 3, pool.testGetDisposedObjects().size()); + assertEquals(1, pool.getSize(), "Expected pool to only contain 1 object"); + assertEquals(3, pool.testGetDisposedObjects().size(), "Expected 3 disposed objects"); } /** @@ -125,8 +121,8 @@ public void testSweepAndTrim1() { * * @throws java.lang.Exception if any. */ - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { o1 = new Object(); o2 = new Object(); o3 = new Object(); @@ -140,15 +136,15 @@ public void setUp() throws Exception { * * @throws java.lang.Exception if any. */ - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() throws Exception { pool.dispose(); assertTrue(pool.isDisposed()); pool = null; } class TestObjectPool extends SweeperPool { - private Vector disposedObjects = new Vector(); + private Vector disposedObjects = new Vector<>(); public TestObjectPool(int maxSize, int minSize, int intialCapacity, int sweepInterval, int triggerSize) { super(maxSize, minSize, intialCapacity, sweepInterval, triggerSize); diff --git a/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java b/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java index 976551c7..41514a1c 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java @@ -21,11 +21,12 @@ import java.util.Properties; import org.codehaus.plexus.util.Os; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; /** *

CommandLineUtilsTest class.

@@ -35,14 +36,14 @@ * @since 3.4.0 */ @SuppressWarnings({"JavaDoc", "deprecation"}) -public class CommandLineUtilsTest { +class CommandLineUtilsTest { /** *

testQuoteArguments.

*/ @Test - public void testQuoteArguments() { - try { + void quoteArguments() { + Assertions.assertDoesNotThrow(() -> { String result = CommandLineUtils.quote("Hello"); System.out.println(result); assertEquals("Hello", result); @@ -51,12 +52,10 @@ public void testQuoteArguments() { assertEquals("\"Hello World\"", result); result = CommandLineUtils.quote("\"Hello World\""); System.out.println(result); - assertEquals("\'\"Hello World\"\'", result); - } catch (Exception e) { - fail(e.getMessage()); - } + assertEquals("'\"Hello World\"'", result); + }); try { - CommandLineUtils.quote("\"Hello \'World\'\'"); + CommandLineUtils.quote("\"Hello 'World''"); fail(); } catch (Exception e) { } @@ -68,7 +67,7 @@ public void testQuoteArguments() { * @throws java.lang.Exception if any. */ @Test - public void testGetSystemEnvVarsCaseInsensitive() throws Exception { + void getSystemEnvVarsCaseInsensitive() throws Exception { Properties vars = CommandLineUtils.getSystemEnvVars(false); for (Object o : vars.keySet()) { String variable = (String) o; @@ -82,7 +81,7 @@ public void testGetSystemEnvVarsCaseInsensitive() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testGetSystemEnvVarsWindows() throws Exception { + void getSystemEnvVarsWindows() throws Exception { if (!Os.isFamily(Os.FAMILY_WINDOWS)) { return; } @@ -99,7 +98,7 @@ public void testGetSystemEnvVarsWindows() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testTranslateCommandline() throws Exception { + void translateCommandline() throws Exception { assertCmdLineArgs(new String[] {}, null); assertCmdLineArgs(new String[] {}, ""); diff --git a/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java b/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java index bdcf5556..3d39ed01 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java @@ -27,12 +27,12 @@ import org.codehaus.plexus.util.cli.shell.BourneShell; import org.codehaus.plexus.util.cli.shell.CmdShell; import org.codehaus.plexus.util.cli.shell.Shell; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** *

CommandlineTest class.

@@ -41,7 +41,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class CommandlineTest { +class CommandlineTest { private String baseDir; /** @@ -49,8 +49,8 @@ public class CommandlineTest { * * @throws java.lang.Exception if any. */ - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { baseDir = System.getProperty("basedir"); if (baseDir == null) { @@ -62,7 +62,7 @@ public void setUp() throws Exception { *

testCommandlineWithoutCommandInConstructor.

*/ @Test - public void testCommandlineWithoutCommandInConstructor() { + void commandlineWithoutCommandInConstructor() { Commandline cmd = new Commandline(new Shell()); cmd.setWorkingDirectory(baseDir); cmd.createArgument().setValue("cd"); @@ -76,7 +76,7 @@ public void testCommandlineWithoutCommandInConstructor() { *

testCommandlineWithCommandInConstructor.

*/ @Test - public void testCommandlineWithCommandInConstructor() { + void commandlineWithCommandInConstructor() { Commandline cmd = new Commandline("cd .", new Shell()); cmd.setWorkingDirectory(baseDir); @@ -90,7 +90,7 @@ public void testCommandlineWithCommandInConstructor() { * @throws java.lang.Exception if any. */ @Test - public void testExecuteBinaryOnPath() throws Exception { + void executeBinaryOnPath() throws Exception { // Maven startup script on PATH is required for this test Commandline cmd = new Commandline(); cmd.setWorkingDirectory(baseDir); @@ -110,7 +110,7 @@ public void testExecuteBinaryOnPath() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testExecute() throws Exception { + void execute() throws Exception { // allow it to detect the proper shell here. Commandline cmd = new Commandline(); cmd.setWorkingDirectory(baseDir); @@ -126,7 +126,7 @@ public void testExecute() throws Exception { *

testSetLine.

*/ @Test - public void testSetLine() { + void setLine() { Commandline cmd = new Commandline(new Shell()); cmd.setWorkingDirectory(baseDir); cmd.setExecutable("echo"); @@ -141,7 +141,7 @@ public void testSetLine() { *

testCreateCommandInReverseOrder.

*/ @Test - public void testCreateCommandInReverseOrder() { + void createCommandInReverseOrder() { Commandline cmd = new Commandline(new Shell()); cmd.setWorkingDirectory(baseDir); cmd.createArgument().setValue("."); @@ -155,7 +155,7 @@ public void testCreateCommandInReverseOrder() { *

testSetFile.

*/ @Test - public void testSetFile() { + void setFile() { Commandline cmd = new Commandline(new Shell()); cmd.setWorkingDirectory(baseDir); cmd.createArgument().setValue("more"); @@ -176,13 +176,13 @@ public void testSetFile() { * @throws java.lang.Exception if any. */ @Test - public void testGetShellCommandLineWindows() throws Exception { + void getShellCommandLineWindows() throws Exception { Commandline cmd = new Commandline(new CmdShell()); cmd.setExecutable("c:\\Program Files\\xxx"); cmd.addArguments(new String[] {"a", "b"}); String[] shellCommandline = cmd.getShellCommandline(); - assertEquals("Command line size", 4, shellCommandline.length); + assertEquals(4, shellCommandline.length, "Command line size"); assertEquals("cmd.exe", shellCommandline[0]); assertEquals("/X", shellCommandline[1]); @@ -198,13 +198,13 @@ public void testGetShellCommandLineWindows() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testGetShellCommandLineWindowsWithSeveralQuotes() throws Exception { + void getShellCommandLineWindowsWithSeveralQuotes() throws Exception { Commandline cmd = new Commandline(new CmdShell()); cmd.setExecutable("c:\\Program Files\\xxx"); cmd.addArguments(new String[] {"c:\\Documents and Settings\\whatever", "b"}); String[] shellCommandline = cmd.getShellCommandline(); - assertEquals("Command line size", 4, shellCommandline.length); + assertEquals(4, shellCommandline.length, "Command line size"); assertEquals("cmd.exe", shellCommandline[0]); assertEquals("/X", shellCommandline[1]); @@ -221,20 +221,20 @@ public void testGetShellCommandLineWindowsWithSeveralQuotes() throws Exception { * @throws java.lang.Exception */ @Test - public void testGetShellCommandLineBash() throws Exception { + void getShellCommandLineBash() throws Exception { Commandline cmd = new Commandline(new BourneShell()); cmd.setExecutable("/bin/echo"); cmd.addArguments(new String[] {"hello world"}); String[] shellCommandline = cmd.getShellCommandline(); - assertEquals("Command line size", 3, shellCommandline.length); + assertEquals(3, shellCommandline.length, "Command line size"); assertEquals("/bin/sh", shellCommandline[0]); assertEquals("-c", shellCommandline[1]); String expectedShellCmd = "'/bin/echo' 'hello world'"; if (Os.isFamily(Os.FAMILY_WINDOWS)) { - expectedShellCmd = "'\\bin\\echo' \'hello world\'"; + expectedShellCmd = "'\\bin\\echo' 'hello world'"; } assertEquals(expectedShellCmd, shellCommandline[2]); } @@ -245,7 +245,7 @@ public void testGetShellCommandLineBash() throws Exception { * @throws java.lang.Exception */ @Test - public void testGetShellCommandLineBash_WithWorkingDirectory() throws Exception { + void getShellCommandLineBashWithWorkingDirectory() throws Exception { Commandline cmd = new Commandline(new BourneShell()); cmd.setExecutable("/bin/echo"); cmd.addArguments(new String[] {"hello world"}); @@ -255,7 +255,7 @@ public void testGetShellCommandLineBash_WithWorkingDirectory() throws Exception String[] shellCommandline = cmd.getShellCommandline(); - assertEquals("Command line size", 3, shellCommandline.length); + assertEquals(3, shellCommandline.length, "Command line size"); assertEquals("/bin/sh", shellCommandline[0]); assertEquals("-c", shellCommandline[1]); @@ -272,14 +272,14 @@ public void testGetShellCommandLineBash_WithWorkingDirectory() throws Exception * @throws java.lang.Exception */ @Test - public void testGetShellCommandLineBash_WithSingleQuotedArg() throws Exception { + void getShellCommandLineBashWithSingleQuotedArg() throws Exception { Commandline cmd = new Commandline(new BourneShell()); cmd.setExecutable("/bin/echo"); - cmd.addArguments(new String[] {"\'hello world\'"}); + cmd.addArguments(new String[] {"'hello world'"}); String[] shellCommandline = cmd.getShellCommandline(); - assertEquals("Command line size", 3, shellCommandline.length); + assertEquals(3, shellCommandline.length, "Command line size"); assertEquals("/bin/sh", shellCommandline[0]); assertEquals("-c", shellCommandline[1]); @@ -296,13 +296,13 @@ public void testGetShellCommandLineBash_WithSingleQuotedArg() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testGetShellCommandLineNonWindows() throws Exception { + void getShellCommandLineNonWindows() throws Exception { Commandline cmd = new Commandline(new BourneShell()); cmd.setExecutable("/usr/bin"); cmd.addArguments(new String[] {"a", "b"}); String[] shellCommandline = cmd.getShellCommandline(); - assertEquals("Command line size", 3, shellCommandline.length); + assertEquals(3, shellCommandline.length, "Command line size"); assertEquals("/bin/sh", shellCommandline[0]); assertEquals("-c", shellCommandline[1]); @@ -320,7 +320,7 @@ public void testGetShellCommandLineNonWindows() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testEnvironment() throws Exception { + void environment() throws Exception { Commandline cmd = new Commandline(); cmd.addEnvironment("name", "value"); assertEquals("name=value", cmd.getEnvironmentVariables()[0]); @@ -332,7 +332,7 @@ public void testEnvironment() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testEnvironmentWitOverrideSystemEnvironment() throws Exception { + void environmentWitOverrideSystemEnvironment() throws Exception { Commandline cmd = new Commandline(); cmd.addSystemEnvironment(); cmd.addEnvironment("JAVA_HOME", "/usr/jdk1.5"); @@ -353,7 +353,7 @@ public void testEnvironmentWitOverrideSystemEnvironment() throws Exception { * @throws java.lang.Exception */ @Test - public void testQuotedPathWithSingleApostrophe() throws Exception { + void quotedPathWithSingleApostrophe() throws Exception { File dir = new File(System.getProperty("basedir"), "target/test/quotedpath'test"); createAndCallScript(dir, "echo Quoted"); @@ -367,7 +367,7 @@ public void testQuotedPathWithSingleApostrophe() throws Exception { * @throws java.lang.Exception */ @Test - public void testPathWithShellExpansionStrings() throws Exception { + void pathWithShellExpansionStrings() throws Exception { File dir = new File(System.getProperty("basedir"), "target/test/dollar$test"); createAndCallScript(dir, "echo Quoted"); } @@ -378,7 +378,7 @@ public void testPathWithShellExpansionStrings() throws Exception { * @throws java.lang.Exception */ @Test - public void testQuotedPathWithQuotationMark() throws Exception { + void quotedPathWithQuotationMark() throws Exception { if (Os.isFamily(Os.FAMILY_WINDOWS)) { System.out.println("testQuotedPathWithQuotationMark() skipped on Windows"); return; @@ -398,7 +398,7 @@ public void testQuotedPathWithQuotationMark() throws Exception { * @throws java.lang.Exception */ @Test - public void testQuotedPathWithQuotationMarkAndApostrophe() throws Exception { + void quotedPathWithQuotationMarkAndApostrophe() throws Exception { if (Os.isFamily(Os.FAMILY_WINDOWS)) { System.out.println("testQuotedPathWithQuotationMarkAndApostrophe() skipped on Windows"); return; @@ -417,8 +417,8 @@ public void testQuotedPathWithQuotationMarkAndApostrophe() throws Exception { * @throws java.lang.Exception */ @Test - public void testOnlyQuotedPath() throws Exception { - File dir = new File(System.getProperty("basedir"), "target/test/quotedpath\'test"); + void onlyQuotedPath() throws Exception { + File dir = new File(System.getProperty("basedir"), "target/test/quotedpath'test"); File javaHome = new File(System.getProperty("java.home")); File java; @@ -446,10 +446,10 @@ public void testOnlyQuotedPath() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testDollarSignInArgumentPath() throws Exception { + void dollarSignInArgumentPath() throws Exception { File dir = new File(System.getProperty("basedir"), "target/test"); if (!dir.exists()) { - assertTrue("Can't create dir:" + dir.getAbsolutePath(), dir.mkdirs()); + assertTrue(dir.mkdirs(), "Can't create dir:" + dir.getAbsolutePath()); } Writer writer = null; @@ -479,7 +479,7 @@ public void testDollarSignInArgumentPath() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testTimeOutException() throws Exception { + void timeOutException() throws Exception { File javaHome = new File(System.getProperty("java.home")); File java; if (Os.isFamily(Os.FAMILY_WINDOWS)) { @@ -542,7 +542,7 @@ private static void makeExecutable(File path) throws IOException { */ private static void createAndCallScript(File dir, String content) throws Exception { if (!dir.exists()) { - assertTrue("Can't create dir:" + dir.getAbsolutePath(), dir.mkdirs()); + assertTrue(dir.mkdirs(), "Can't create dir:" + dir.getAbsolutePath()); } // Create a script file @@ -586,8 +586,7 @@ private static void executeCommandLine(Commandline cmd) throws Exception { int exitCode = CommandLineUtils.executeCommandLine(cmd, new DefaultConsumer(), err); if (exitCode != 0) { - String msg = "Exit code: " + exitCode + " - " + err.getOutput(); - throw new Exception(msg.toString()); + throw new Exception("Exit code: " + exitCode + " - " + err.getOutput()); } } catch (CommandLineException e) { throw new Exception("Unable to execute command: " + e.getMessage(), e); diff --git a/src/test/java/org/codehaus/plexus/util/cli/DefaultConsumerTest.java b/src/test/java/org/codehaus/plexus/util/cli/DefaultConsumerTest.java index 92dd21db..6f201346 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/DefaultConsumerTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/DefaultConsumerTest.java @@ -1,22 +1,6 @@ package org.codehaus.plexus.util.cli; -/* - * Copyright The Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.junit.Test; +import org.junit.jupiter.api.Test; /** *

DefaultConsumerTest class.

@@ -25,14 +9,14 @@ * @version $Id: $Id * @since 3.4.0 */ -public class DefaultConsumerTest { +class DefaultConsumerTest { /** *

testConsumeLine.

* * @throws java.lang.Exception if any. */ @Test - public void testConsumeLine() throws Exception { + void consumeLine() throws Exception { DefaultConsumer cons = new DefaultConsumer(); cons.consumeLine("Test DefaultConsumer consumeLine"); } diff --git a/src/test/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizerTest.java b/src/test/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizerTest.java index 8376a2c0..98d19c95 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizerTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizerTest.java @@ -1,25 +1,10 @@ package org.codehaus.plexus.util.cli; -/* - * Copyright The Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.fail; /** *

EnhancedStringTokenizerTest class.

@@ -28,12 +13,12 @@ * @version $Id: $Id * @since 3.4.0 */ -public class EnhancedStringTokenizerTest { +class EnhancedStringTokenizerTest { /** *

test1.

*/ @Test - public void test1() { + void test1() { EnhancedStringTokenizer est = new EnhancedStringTokenizer("this is a test string"); StringBuilder sb = new StringBuilder(); while (est.hasMoreTokens()) { @@ -47,58 +32,58 @@ public void test1() { *

test2.

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

test3.

*/ @Test - public void test3() { + void test3() { EnhancedStringTokenizer est = new EnhancedStringTokenizer("1,,,3,,4", ",", true); - assertEquals("Token 1", "1", est.nextToken()); - assertEquals("Token 2", ",", est.nextToken()); - assertEquals("Token 3", "", est.nextToken()); - assertEquals("Token 4", ",", est.nextToken()); - assertEquals("Token 5", "", est.nextToken()); - assertEquals("Token 6", ",", est.nextToken()); - assertEquals("Token 7", "3", est.nextToken()); - assertEquals("Token 8", ",", est.nextToken()); - assertEquals("Token 9", "", est.nextToken()); - assertEquals("Token 10", ",", est.nextToken()); - assertEquals("Token 11", "4", est.nextToken()); + assertEquals("1", est.nextToken(), "Token 1"); + assertEquals(",", est.nextToken(), "Token 2"); + assertEquals("", est.nextToken(), "Token 3"); + assertEquals(",", est.nextToken(), "Token 4"); + assertEquals("", est.nextToken(), "Token 5"); + assertEquals(",", est.nextToken(), "Token 6"); + assertEquals("3", est.nextToken(), "Token 7"); + assertEquals(",", est.nextToken(), "Token 8"); + assertEquals("", est.nextToken(), "Token 9"); + assertEquals(",", est.nextToken(), "Token 10"); + assertEquals("4", est.nextToken(), "Token 11"); } /** *

testMultipleDelim.

*/ @Test - public void testMultipleDelim() { + void multipleDelim() { EnhancedStringTokenizer est = new EnhancedStringTokenizer("1 2|3|4", " |", true); - assertEquals("Token 1", "1", est.nextToken()); - assertEquals("Token 2", " ", est.nextToken()); - assertEquals("Token 3", "2", est.nextToken()); - assertEquals("Token 4", "|", est.nextToken()); - assertEquals("Token 5", "3", est.nextToken()); - assertEquals("Token 6", "|", est.nextToken()); - assertEquals("Token 7", "4", est.nextToken()); - assertEquals("est.hasMoreTokens()", false, est.hasMoreTokens()); + assertEquals("1", est.nextToken(), "Token 1"); + assertEquals(" ", est.nextToken(), "Token 2"); + assertEquals("2", est.nextToken(), "Token 3"); + assertEquals("|", est.nextToken(), "Token 4"); + assertEquals("3", est.nextToken(), "Token 5"); + assertEquals("|", est.nextToken(), "Token 6"); + assertEquals("4", est.nextToken(), "Token 7"); + assertFalse(est.hasMoreTokens(), "est.hasMoreTokens()"); } /** *

testEmptyString.

*/ @Test - public void testEmptyString() { + void emptyString() { EnhancedStringTokenizer est = new EnhancedStringTokenizer(""); - assertEquals("est.hasMoreTokens()", false, est.hasMoreTokens()); + assertFalse(est.hasMoreTokens(), "est.hasMoreTokens()"); try { est.nextToken(); fail(); @@ -110,10 +95,10 @@ public void testEmptyString() { *

testSimpleString.

*/ @Test - public void testSimpleString() { + void simpleString() { EnhancedStringTokenizer est = new EnhancedStringTokenizer("a "); - assertEquals("Token 1", "a", est.nextToken()); - assertEquals("Token 2", "", est.nextToken()); - assertEquals("est.hasMoreTokens()", false, est.hasMoreTokens()); + assertEquals("a", est.nextToken(), "Token 1"); + assertEquals("", est.nextToken(), "Token 2"); + assertFalse(est.hasMoreTokens(), "est.hasMoreTokens()"); } } diff --git a/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java b/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java index 2a327933..f3887a0c 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java @@ -60,11 +60,11 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** *

StreamPumperTest class.

@@ -73,14 +73,14 @@ * @version $Id: $Id * @since 3.4.0 */ -public class StreamPumperTest { +class StreamPumperTest { private String lineSeparator = System.lineSeparator(); /** *

testPumping.

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

testPumpingWithPrintWriter.

*/ @Test - public void testPumpingWithPrintWriter() { + void pumpingWithPrintWriter() { String inputString = "This a test string"; ByteArrayInputStream bais = new ByteArrayInputStream(inputString.getBytes()); StringWriter sw = new StringWriter(); @@ -116,12 +116,12 @@ public void testPumpingWithPrintWriter() { *

testPumperReadsInputStreamUntilEndEvenIfConsumerFails.

*/ @Test - public void testPumperReadsInputStreamUntilEndEvenIfConsumerFails() { + void pumperReadsInputStreamUntilEndEvenIfConsumerFails() { // the number of bytes generated should surely exceed the read buffer used by the pumper GeneratorInputStream gis = new GeneratorInputStream(1024 * 1024 * 4); StreamPumper pumper = new StreamPumper(gis, new FailingConsumer()); pumper.run(); - assertEquals("input stream was not fully consumed, producer deadlocks", gis.size, gis.read); + assertEquals(gis.size, gis.read, "input stream was not fully consumed, producer deadlocks"); assertTrue(gis.closed); assertNotNull(pumper.getException()); } @@ -164,7 +164,7 @@ public void consumeLine(String line) { */ static class TestConsumer implements StreamConsumer { - private List lines = new ArrayList(); + private List lines = new ArrayList<>(); /** * Checks to see if this consumer consumed a particular line. This method will wait up to timeout number of @@ -209,7 +209,7 @@ public void consumeLine(String line) { *

testEnabled.

*/ @Test - public void testEnabled() { + void enabled() { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream("AB\nCE\nEF".getBytes()); TestConsumer streamConsumer = new TestConsumer(); StreamPumper streamPumper = new StreamPumper(byteArrayInputStream, streamConsumer); @@ -221,7 +221,7 @@ public void testEnabled() { *

testDisabled.

*/ @Test - public void testDisabled() { + void disabled() { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream("AB\nCE\nEF".getBytes()); TestConsumer streamConsumer = new TestConsumer(); StreamPumper streamPumper = new StreamPumper(byteArrayInputStream, streamConsumer); diff --git a/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java b/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java index f20791c7..714bf733 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java @@ -21,10 +21,10 @@ import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.cli.Commandline; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** *

BourneShellTest class.

@@ -33,7 +33,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class BourneShellTest { +class BourneShellTest { /** *

newShell.

@@ -48,7 +48,7 @@ protected Shell newShell() { *

testQuoteWorkingDirectoryAndExecutable.

*/ @Test - public void testQuoteWorkingDirectoryAndExecutable() { + void quoteWorkingDirectoryAndExecutable() { Shell sh = newShell(); sh.setWorkingDirectory("/usr/local/bin"); @@ -64,7 +64,7 @@ public void testQuoteWorkingDirectoryAndExecutable() { *

testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes.

*/ @Test - public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes() { + void quoteWorkingDirectoryAndExecutableWDPathWithSingleQuotes() { Shell sh = newShell(); sh.setWorkingDirectory("/usr/local/'something else'"); @@ -80,7 +80,7 @@ public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes() { *

testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes_BackslashFileSep.

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

testPreserveSingleQuotesOnArgument.

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

testAddSingleQuotesOnArgumentWithSpaces.

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

testEscapeSingleQuotesOnArgument.

*/ @Test - public void testEscapeSingleQuotesOnArgument() { + void escapeSingleQuotesOnArgument() { Shell sh = newShell(); sh.setWorkingDirectory("/usr/bin"); @@ -154,7 +154,7 @@ public void testEscapeSingleQuotesOnArgument() { *

testArgumentsWithsemicolon.

*/ @Test - public void testArgumentsWithsemicolon() { + void argumentsWithsemicolon() { System.out.println("---- semi colon tests ----"); @@ -169,7 +169,7 @@ public void testArgumentsWithsemicolon() { String cli = StringUtils.join(shellCommandLine.iterator(), " "); System.out.println(cli); - assertTrue(cli.endsWith("\'" + args[0] + "\'")); + assertTrue(cli.endsWith("'" + args[0] + "'")); Commandline commandline = new Commandline(newShell()); commandline.setExecutable("chmod"); @@ -215,7 +215,7 @@ public void testArgumentsWithsemicolon() { * @throws java.lang.Exception if any. */ @Test - public void testBourneShellQuotingCharacters() throws Exception { + void bourneShellQuotingCharacters() throws Exception { // { ' ', '$', ';', '&', '|', '<', '>', '*', '?', '(', ')' }; // test with values http://steve-parker.org/sh/bourne.shtml Appendix B - Meta-characters and Reserved Words Commandline commandline = new Commandline(newShell()); diff --git a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java index 499fa555..97ddfcec 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java @@ -19,9 +19,9 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** *

CycleDetectedExceptionTest class.

@@ -30,13 +30,13 @@ * @version $Id: $Id * @since 3.4.0 */ -public class CycleDetectedExceptionTest { +class CycleDetectedExceptionTest { /** *

testException.

*/ @Test - public void testException() { - final List cycle = new ArrayList(); + void exception() { + final List cycle = new ArrayList<>(); cycle.add("a"); diff --git a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java index b0320182..e900ca83 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java @@ -18,13 +18,14 @@ import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** *

CycleDetectorTest class.

@@ -33,28 +34,26 @@ * @version $Id: $Id * @since 3.4.0 */ -public class CycleDetectorTest { +class CycleDetectorTest { /** *

testCycyleDetection.

*/ @Test - public void testCycyleDetection() { + void cycyleDetection() { // No cycle // // a --> b --->c // - try { - final DAG dag1 = new DAG(); - - dag1.addEdge("a", "b"); + Assertions.assertDoesNotThrow( + () -> { + final DAG dag1 = new DAG(); - dag1.addEdge("b", "c"); + dag1.addEdge("a", "b"); - } catch (CycleDetectedException e) { - - fail("Cycle should not be detected"); - } + dag1.addEdge("b", "c"); + }, + "Cycle should not be detected"); // // a --> b --->c @@ -77,33 +76,32 @@ public void testCycyleDetection() { final List cycle = e.getCycle(); - assertNotNull("Cycle should be not null", cycle); + assertNotNull(cycle, "Cycle should be not null"); - assertTrue("Cycle contains 'a'", cycle.contains("a")); + assertTrue(cycle.contains("a"), "Cycle contains 'a'"); - assertTrue("Cycle contains 'b'", cycle.contains("b")); + assertTrue(cycle.contains("b"), "Cycle contains 'b'"); - assertTrue("Cycle contains 'c'", cycle.contains("c")); + assertTrue(cycle.contains("c"), "Cycle contains 'c'"); } // | --> c // a --> b // | | --> d // ---------> - try { - final DAG dag3 = new DAG(); - - dag3.addEdge("a", "b"); + Assertions.assertDoesNotThrow( + () -> { + final DAG dag3 = new DAG(); - dag3.addEdge("b", "c"); + dag3.addEdge("a", "b"); - dag3.addEdge("b", "d"); + dag3.addEdge("b", "c"); - dag3.addEdge("a", "d"); + dag3.addEdge("b", "d"); - } catch (CycleDetectedException e) { - fail("Cycle should not be detected"); - } + dag3.addEdge("a", "d"); + }, + "Cycle should not be detected"); // ------------ // | | @@ -129,15 +127,15 @@ public void testCycyleDetection() { } catch (CycleDetectedException e) { final List cycle = e.getCycle(); - assertNotNull("Cycle should be not null", cycle); + assertNotNull(cycle, "Cycle should be not null"); - assertEquals("Cycle contains 'a'", "a", (String) cycle.get(0)); + assertEquals("a", cycle.get(0), "Cycle contains 'a'"); - assertEquals("Cycle contains 'b'", "b", cycle.get(1)); + assertEquals("b", cycle.get(1), "Cycle contains 'b'"); - assertEquals("Cycle contains 'c'", "c", cycle.get(2)); + assertEquals("c", cycle.get(2), "Cycle contains 'c'"); - assertEquals("Cycle contains 'a'", "a", (String) cycle.get(3)); + assertEquals("a", cycle.get(3), "Cycle contains 'a'"); } // f --> g --> h @@ -173,33 +171,33 @@ public void testCycyleDetection() { } catch (CycleDetectedException e) { final List cycle = e.getCycle(); - assertNotNull("Cycle should be not null", cycle); + assertNotNull(cycle, "Cycle should be not null"); - assertEquals("Cycle contains 5 elements", 5, cycle.size()); + assertEquals(5, cycle.size(), "Cycle contains 5 elements"); - assertEquals("Cycle contains 'b'", "b", (String) cycle.get(0)); + assertEquals("b", cycle.get(0), "Cycle contains 'b'"); - assertEquals("Cycle contains 'c'", "c", cycle.get(1)); + assertEquals("c", cycle.get(1), "Cycle contains 'c'"); - assertEquals("Cycle contains 'd'", "d", cycle.get(2)); + assertEquals("d", cycle.get(2), "Cycle contains 'd'"); - assertEquals("Cycle contains 'e'", "e", (String) cycle.get(3)); + assertEquals("e", cycle.get(3), "Cycle contains 'e'"); - assertEquals("Cycle contains 'b'", "b", (String) cycle.get(4)); + assertEquals("b", cycle.get(4), "Cycle contains 'b'"); - assertTrue("Edge exists", dag5.hasEdge("a", "b")); + assertTrue(dag5.hasEdge("a", "b"), "Edge exists"); - assertTrue("Edge exists", dag5.hasEdge("b", "c")); + assertTrue(dag5.hasEdge("b", "c"), "Edge exists"); - assertTrue("Edge exists", dag5.hasEdge("b", "f")); + assertTrue(dag5.hasEdge("b", "f"), "Edge exists"); - assertTrue("Edge exists", dag5.hasEdge("f", "g")); + assertTrue(dag5.hasEdge("f", "g"), "Edge exists"); - assertTrue("Edge exists", dag5.hasEdge("g", "h")); + assertTrue(dag5.hasEdge("g", "h"), "Edge exists"); - assertTrue("Edge exists", dag5.hasEdge("c", "d")); + assertTrue(dag5.hasEdge("c", "d"), "Edge exists"); - assertTrue("Edge exists", dag5.hasEdge("d", "e")); + assertTrue(dag5.hasEdge("d", "e"), "Edge exists"); assertFalse(dag5.hasEdge("e", "b")); } 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 72d1b12e..7f0cf922 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java @@ -20,11 +20,11 @@ import java.util.List; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** *

DAGTest class.

@@ -33,14 +33,14 @@ * @version $Id: $Id * @since 3.4.0 */ -public class DAGTest { +class DAGTest { /** *

testDAG.

* * @throws org.codehaus.plexus.util.dag.CycleDetectedException if any. */ @Test - public void testDAG() throws CycleDetectedException { + void dag() throws CycleDetectedException { final DAG dag = new DAG(); dag.addVertex("a"); @@ -146,7 +146,7 @@ public void testDAG() throws CycleDetectedException { * @throws org.codehaus.plexus.util.dag.CycleDetectedException if any. */ @Test - public void testGetPredecessors() throws CycleDetectedException { + void getPredecessors() throws CycleDetectedException { final DAG dag = new DAG(); dag.addEdge("a", "b"); diff --git a/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java b/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java index 87de9142..02bd14cd 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java @@ -19,9 +19,9 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** *

TopologicalSorterTest class.

@@ -30,14 +30,14 @@ * @version $Id: $Id * @since 3.4.0 */ -public class TopologicalSorterTest { +class TopologicalSorterTest { /** *

testDfs.

* * @throws org.codehaus.plexus.util.dag.CycleDetectedException if any. */ @Test - public void testDfs() throws CycleDetectedException { + void dfs() throws CycleDetectedException { // a --> b --->c // // result a,b,c @@ -47,7 +47,7 @@ public void testDfs() throws CycleDetectedException { dag1.addEdge("b", "c"); - final List expected1 = new ArrayList(); + final List expected1 = new ArrayList<>(); expected1.add("c"); @@ -57,7 +57,7 @@ public void testDfs() throws CycleDetectedException { final List actual1 = TopologicalSorter.sort(dag1); - assertEquals("Order is different then expected", expected1, actual1); + assertEquals(expected1, actual1, "Order is different then expected"); // // a <-- b <---c @@ -75,7 +75,7 @@ public void testDfs() throws CycleDetectedException { dag2.addEdge("c", "b"); - final List expected2 = new ArrayList(); + final List expected2 = new ArrayList<>(); expected2.add("a"); @@ -85,7 +85,7 @@ public void testDfs() throws CycleDetectedException { final List actual2 = TopologicalSorter.sort(dag2); - assertEquals("Order is different then expected", expected2, actual2); + assertEquals(expected2, actual2, "Order is different then expected"); // // a --> b --> c --> e @@ -124,7 +124,7 @@ public void testDfs() throws CycleDetectedException { dag3.addEdge("f", "g"); - final List expected3 = new ArrayList(); + final List expected3 = new ArrayList<>(); expected3.add("d"); @@ -142,7 +142,7 @@ public void testDfs() throws CycleDetectedException { final List actual3 = TopologicalSorter.sort(dag3); - assertEquals("Order is different then expected", expected3, actual3); + assertEquals(expected3, actual3, "Order is different then expected"); // // a --> b --> c --> e @@ -179,7 +179,7 @@ public void testDfs() throws CycleDetectedException { dag4.addEdge("e", "f"); - final List expected4 = new ArrayList(); + final List expected4 = new ArrayList<>(); expected4.add("d"); @@ -195,6 +195,6 @@ public void testDfs() throws CycleDetectedException { final List actual4 = TopologicalSorter.sort(dag4); - assertEquals("Order is different then expected", expected4, actual4); + assertEquals(expected4, actual4, "Order is different then expected"); } } 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 933f972e..f578f731 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/VertexTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/VertexTest.java @@ -1,24 +1,8 @@ package org.codehaus.plexus.util.dag; -/* - * Copyright The Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** *

VertexTest class.

@@ -27,12 +11,12 @@ * @version $Id: $Id * @since 3.4.0 */ -public class VertexTest { +class VertexTest { /** *

testVertex.

*/ @Test - public void testVertex() { + void vertex() { final Vertex vertex1 = new Vertex("a"); diff --git a/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java b/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java index 2e712149..927d3e52 100644 --- a/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java +++ b/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java @@ -21,13 +21,12 @@ import java.util.List; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; /** *

ReflectionValueExtractorTest class.

@@ -36,7 +35,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class ReflectionValueExtractorTest { +class ReflectionValueExtractorTest { private Project project; /** @@ -44,8 +43,8 @@ public class ReflectionValueExtractorTest { * * @throws java.lang.Exception if any. */ - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { Dependency dependency1 = new Dependency(); dependency1.setArtifactId("dep1"); Dependency dependency2 = new Dependency(); @@ -75,7 +74,7 @@ public void setUp() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testValueExtraction() throws Exception { + void valueExtraction() throws Exception { // ---------------------------------------------------------------------- // Top level values // ---------------------------------------------------------------------- @@ -115,11 +114,11 @@ public void testValueExtraction() throws Exception { assertNotNull(dependency); - assertTrue("dep1".equals(dependency.getArtifactId())); + assertEquals("dep1", dependency.getArtifactId()); String artifactId = (String) ReflectionValueExtractor.evaluate("project.dependencies[1].artifactId", project); - assertTrue("dep2".equals(artifactId)); + assertEquals("dep2", artifactId); // Array @@ -127,11 +126,11 @@ public void testValueExtraction() throws Exception { assertNotNull(dependency); - assertTrue("dep1".equals(dependency.getArtifactId())); + assertEquals("dep1", dependency.getArtifactId()); artifactId = (String) ReflectionValueExtractor.evaluate("project.dependenciesAsArray[1].artifactId", project); - assertTrue("dep2".equals(artifactId)); + assertEquals("dep2", artifactId); // Map @@ -139,11 +138,11 @@ public void testValueExtraction() throws Exception { assertNotNull(dependency); - assertTrue("dep1".equals(dependency.getArtifactId())); + assertEquals("dep1", dependency.getArtifactId()); artifactId = (String) ReflectionValueExtractor.evaluate("project.dependenciesAsMap(dep2).artifactId", project); - assertTrue("dep2".equals(artifactId)); + assertEquals("dep2", artifactId); // ---------------------------------------------------------------------- // Build @@ -160,7 +159,7 @@ public void testValueExtraction() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testValueExtractorWithAInvalidExpression() throws Exception { + void valueExtractorWithAInvalidExpression() throws Exception { assertNull(ReflectionValueExtractor.evaluate("project.foo", project)); assertNull(ReflectionValueExtractor.evaluate("project.dependencies[10]", project)); assertNull(ReflectionValueExtractor.evaluate("project.dependencies[0].foo", project)); @@ -172,8 +171,8 @@ public void testValueExtractorWithAInvalidExpression() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testMappedDottedKey() throws Exception { - Map map = new HashMap(); + void mappedDottedKey() throws Exception { + Map map = new HashMap<>(); map.put("a.b", "a.b-value"); assertEquals("a.b-value", ReflectionValueExtractor.evaluate("h.value(a.b)", new ValueHolder(map))); @@ -185,10 +184,10 @@ public void testMappedDottedKey() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testIndexedMapped() throws Exception { - Map map = new HashMap(); + void indexedMapped() throws Exception { + Map map = new HashMap<>(); map.put("a", "a-value"); - List list = new ArrayList(); + List list = new ArrayList<>(); list.add(map); assertEquals("a-value", ReflectionValueExtractor.evaluate("h.value[0](a)", new ValueHolder(list))); @@ -200,10 +199,10 @@ public void testIndexedMapped() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testMappedIndexed() throws Exception { - List list = new ArrayList(); + void mappedIndexed() throws Exception { + List list = new ArrayList<>(); list.add("a-value"); - Map map = new HashMap(); + Map map = new HashMap<>(); map.put("a", list); assertEquals("a-value", ReflectionValueExtractor.evaluate("h.value(a)[0]", new ValueHolder(map))); } @@ -214,8 +213,8 @@ public void testMappedIndexed() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testMappedMissingDot() throws Exception { - Map map = new HashMap(); + void mappedMissingDot() throws Exception { + Map map = new HashMap<>(); map.put("a", new ValueHolder("a-value")); assertNull(ReflectionValueExtractor.evaluate("h.value(a)value", new ValueHolder(map))); } @@ -226,8 +225,8 @@ public void testMappedMissingDot() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testIndexedMissingDot() throws Exception { - List list = new ArrayList(); + void indexedMissingDot() throws Exception { + List list = new ArrayList<>(); list.add(new ValueHolder("a-value")); assertNull(ReflectionValueExtractor.evaluate("h.value[0]value", new ValueHolder(list))); } @@ -238,7 +237,7 @@ public void testIndexedMissingDot() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testDotDot() throws Exception { + void dotDot() throws Exception { assertNull(ReflectionValueExtractor.evaluate("h..value", new ValueHolder("value"))); } @@ -248,8 +247,8 @@ public void testDotDot() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testBadIndexedSyntax() throws Exception { - List list = new ArrayList(); + void badIndexedSyntax() throws Exception { + List list = new ArrayList<>(); list.add("a-value"); Object value = new ValueHolder(list); @@ -267,8 +266,8 @@ public void testBadIndexedSyntax() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testBadMappedSyntax() throws Exception { - Map map = new HashMap(); + void badMappedSyntax() throws Exception { + Map map = new HashMap<>(); map.put("a", "a-value"); Object value = new ValueHolder(map); @@ -284,7 +283,7 @@ public void testBadMappedSyntax() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testIllegalIndexedType() throws Exception { + void illegalIndexedType() throws Exception { try { ReflectionValueExtractor.evaluate("h.value[1]", new ValueHolder("string")); } catch (Exception e) { @@ -298,7 +297,7 @@ public void testIllegalIndexedType() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testIllegalMappedType() throws Exception { + void illegalMappedType() throws Exception { try { ReflectionValueExtractor.evaluate("h.value(key)", new ValueHolder("string")); } catch (Exception e) { @@ -312,7 +311,7 @@ public void testIllegalMappedType() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testTrimRootToken() throws Exception { + void trimRootToken() throws Exception { assertNull(ReflectionValueExtractor.evaluate("project", project, true)); } @@ -322,7 +321,7 @@ public void testTrimRootToken() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testArtifactMap() throws Exception { + void artifactMap() throws Exception { assertEquals( "g0", ((Artifact) ReflectionValueExtractor.evaluate("project.artifactMap(g0:a0:c0)", project)).getGroupId()); @@ -413,7 +412,7 @@ public static class Project { private String version; - private Map artifactMap = new HashMap(); + private Map artifactMap = new HashMap<>(); private String description; public void setModelVersion(String modelVersion) { @@ -555,7 +554,7 @@ public Object getValue() { * @throws java.lang.Exception if any. */ @Test - public void testRootPropertyRegression() throws Exception { + void rootPropertyRegression() throws Exception { Project project = new Project(); project.setDescription("c:\\\\org\\apache\\test"); Object evalued = ReflectionValueExtractor.evaluate("description", project); diff --git a/src/test/java/org/codehaus/plexus/util/io/CachingOutputStreamTest.java b/src/test/java/org/codehaus/plexus/util/io/CachingOutputStreamTest.java index 1a53155a..11da4e05 100644 --- a/src/test/java/org/codehaus/plexus/util/io/CachingOutputStreamTest.java +++ b/src/test/java/org/codehaus/plexus/util/io/CachingOutputStreamTest.java @@ -24,22 +24,22 @@ import java.nio.file.attribute.FileTime; import java.util.Objects; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class CachingOutputStreamTest { +class CachingOutputStreamTest { Path tempDir; Path checkLastModified; - @Before - public void setup() throws IOException { + @BeforeEach + void setup() throws IOException { Path dir = Paths.get("target/io"); Files.createDirectories(dir); tempDir = Files.createTempDirectory(dir, "temp-"); @@ -60,7 +60,7 @@ private void waitLastModified() throws IOException, InterruptedException { } @Test - public void testWriteNoExistingFile() throws IOException, InterruptedException { + void writeNoExistingFile() throws IOException, InterruptedException { byte[] data = "Hello world!".getBytes(StandardCharsets.UTF_8); Path path = tempDir.resolve("file.txt"); assertFalse(Files.exists(path)); diff --git a/src/test/java/org/codehaus/plexus/util/io/CachingWriterTest.java b/src/test/java/org/codehaus/plexus/util/io/CachingWriterTest.java index 6c3dc9f6..5172547b 100644 --- a/src/test/java/org/codehaus/plexus/util/io/CachingWriterTest.java +++ b/src/test/java/org/codehaus/plexus/util/io/CachingWriterTest.java @@ -25,21 +25,21 @@ import java.nio.file.attribute.FileTime; import java.util.Objects; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class CachingWriterTest { +class CachingWriterTest { Path tempDir; Path checkLastModified; - @Before - public void setup() throws IOException { + @BeforeEach + void setup() throws IOException { Path dir = Paths.get("target/io"); Files.createDirectories(dir); tempDir = Files.createTempDirectory(dir, "temp-"); @@ -60,7 +60,7 @@ private void waitLastModified() throws IOException, InterruptedException { } @Test - public void testNoOverwriteWithFlush() throws IOException, InterruptedException { + void noOverwriteWithFlush() throws IOException, InterruptedException { String data = "Hello world!"; Path path = tempDir.resolve("file-bigger.txt"); assertFalse(Files.exists(path)); @@ -85,7 +85,7 @@ public void testNoOverwriteWithFlush() throws IOException, InterruptedException } @Test - public void testWriteNoExistingFile() throws IOException, InterruptedException { + void writeNoExistingFile() throws IOException, InterruptedException { String data = "Hello world!"; Path path = tempDir.resolve("file.txt"); assertFalse(Files.exists(path)); diff --git a/src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java b/src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java index d08d1415..9c3fd9bb 100644 --- a/src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java +++ b/src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java @@ -1,25 +1,9 @@ package org.codehaus.plexus.util.reflection; -/* - * Copyright The Codehaus Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** *

ReflectorTest class.

@@ -28,7 +12,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class ReflectorTest { +class ReflectorTest { private Project project; private Reflector reflector; @@ -38,8 +22,8 @@ public class ReflectorTest { * * @throws java.lang.Exception if any. */ - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { project = new Project(); project.setModelVersion("1.0.0"); project.setVersion("42"); @@ -53,7 +37,7 @@ public void setUp() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testObjectPropertyFromName() throws Exception { + void objectPropertyFromName() throws Exception { assertEquals("1.0.0", reflector.getObjectProperty(project, "modelVersion")); } @@ -63,7 +47,7 @@ public void testObjectPropertyFromName() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testObjectPropertyFromBean() throws Exception { + void objectPropertyFromBean() throws Exception { assertEquals("Foo", reflector.getObjectProperty(project, "name")); } @@ -73,7 +57,7 @@ public void testObjectPropertyFromBean() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testObjectPropertyFromField() throws Exception { + void objectPropertyFromField() throws Exception { assertEquals("42", reflector.getObjectProperty(project, "version")); } diff --git a/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java b/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java index b03e8313..f47c4c61 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java @@ -22,17 +22,18 @@ import java.io.IOException; import java.io.OutputStreamWriter; import java.io.StringWriter; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.NoSuchElementException; import org.codehaus.plexus.util.StringUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Test of {@link org.codehaus.plexus.util.xml.PrettyPrintXMLWriter} @@ -42,7 +43,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class PrettyPrintXMLWriterTest { +class PrettyPrintXMLWriterTest { StringWriter w; PrettyPrintXMLWriter writer; @@ -50,16 +51,16 @@ public class PrettyPrintXMLWriterTest { /** *

setUp.

*/ - @Before - public void setUp() { + @BeforeEach + void setUp() { initWriter(); } /** *

tearDown.

*/ - @After - public void tearDown() { + @AfterEach + void tearDown() { writer = null; w = null; } @@ -73,7 +74,7 @@ private void initWriter() { *

testDefaultPrettyPrintXMLWriter.

*/ @Test - public void testDefaultPrettyPrintXMLWriter() { + void defaultPrettyPrintXMLWriter() { writer.startElement(Tag.HTML.toString()); writeXhtmlHead(writer); @@ -89,7 +90,7 @@ public void testDefaultPrettyPrintXMLWriter() { *

testPrettyPrintXMLWriterWithGivenLineSeparator.

*/ @Test - public void testPrettyPrintXMLWriterWithGivenLineSeparator() { + void prettyPrintXMLWriterWithGivenLineSeparator() { writer.setLineSeparator("\n"); writer.startElement(Tag.HTML.toString()); @@ -107,7 +108,7 @@ public void testPrettyPrintXMLWriterWithGivenLineSeparator() { *

testPrettyPrintXMLWriterWithGivenLineIndenter.

*/ @Test - public void testPrettyPrintXMLWriterWithGivenLineIndenter() { + void prettyPrintXMLWriterWithGivenLineIndenter() { writer.setLineIndenter(" "); writer.startElement(Tag.HTML.toString()); @@ -125,7 +126,7 @@ public void testPrettyPrintXMLWriterWithGivenLineIndenter() { *

testEscapeXmlAttribute.

*/ @Test - public void testEscapeXmlAttribute() { + void escapeXmlAttribute() { // Windows writer.startElement(Tag.DIV.toString()); writer.addAttribute("class", "sect\r\nion"); @@ -151,7 +152,7 @@ public void testEscapeXmlAttribute() { *

testendElementAlreadyClosed.

*/ @Test - public void testendElementAlreadyClosed() { + void testendElementAlreadyClosed() { try { writer.startElement(Tag.DIV.toString()); writer.addAttribute("class", "someattribute"); @@ -172,18 +173,16 @@ public void testendElementAlreadyClosed() { * @throws java.io.IOException if an I/O error occurs */ @Test - public void testIssue51DetectJava7ConcatenationBug() throws IOException { + void issue51DetectJava7ConcatenationBug() throws IOException { File dir = new File("target/test-xml"); if (!dir.exists()) { - assertTrue("cannot create directory test-xml", dir.mkdir()); + assertTrue(dir.mkdir(), "cannot create directory test-xml"); } File xmlFile = new File(dir, "test-issue-51.xml"); - OutputStreamWriter osw = new OutputStreamWriter(Files.newOutputStream(xmlFile.toPath()), "UTF-8"); - writer = new PrettyPrintXMLWriter(osw); - - int iterations = 20000; - - try { + try (OutputStreamWriter osw = + new OutputStreamWriter(Files.newOutputStream(xmlFile.toPath()), StandardCharsets.UTF_8); ) { + writer = new PrettyPrintXMLWriter(osw); + int iterations = 20000; for (int i = 0; i < iterations; ++i) { writer.startElement(Tag.DIV.toString() + i); writer.addAttribute("class", "someattribute"); @@ -193,10 +192,6 @@ public void testIssue51DetectJava7ConcatenationBug() throws IOException { } } catch (NoSuchElementException e) { fail("Should not throw a NoSuchElementException"); - } finally { - if (osw != null) { - osw.close(); - } } } @@ -235,34 +230,29 @@ private String expectedResult(String lineSeparator) { } private String expectedResult(String lineIndenter, String lineSeparator) { - StringBuilder expected = new StringBuilder(); - - expected.append("").append(lineSeparator); - expected.append(StringUtils.repeat(lineIndenter, 1)).append("").append(lineSeparator); - expected.append(StringUtils.repeat(lineIndenter, 2)) - .append("title") - .append(lineSeparator); - expected.append(StringUtils.repeat(lineIndenter, 2)) - .append("") - .append(lineSeparator); - expected.append(StringUtils.repeat(lineIndenter, 2)) - .append("") - .append(lineSeparator); - expected.append(StringUtils.repeat(lineIndenter, 1)).append("").append(lineSeparator); - expected.append(StringUtils.repeat(lineIndenter, 1)).append("").append(lineSeparator); - expected.append(StringUtils.repeat(lineIndenter, 2)) - .append("

Paragraph 1, line 1. Paragraph 1, line 2.

") - .append(lineSeparator); - expected.append(StringUtils.repeat(lineIndenter, 2)) - .append("
") - .append(lineSeparator); - expected.append(StringUtils.repeat(lineIndenter, 3)) - .append("

Section title

") - .append(lineSeparator); - expected.append(StringUtils.repeat(lineIndenter, 2)).append("
").append(lineSeparator); - expected.append(StringUtils.repeat(lineIndenter, 1)).append("").append(lineSeparator); - expected.append(""); - - return expected.toString(); + return "" + lineSeparator + StringUtils.repeat(lineIndenter, 1) + + "" + lineSeparator + StringUtils.repeat(lineIndenter, 2) + + "title" + + lineSeparator + + StringUtils.repeat(lineIndenter, 2) + + "" + + lineSeparator + + StringUtils.repeat(lineIndenter, 2) + + "" + + lineSeparator + + StringUtils.repeat(lineIndenter, 1) + + "" + lineSeparator + StringUtils.repeat(lineIndenter, 1) + + "" + lineSeparator + StringUtils.repeat(lineIndenter, 2) + + "

Paragraph 1, line 1. Paragraph 1, line 2.

" + + lineSeparator + + StringUtils.repeat(lineIndenter, 2) + + "
" + + lineSeparator + + StringUtils.repeat(lineIndenter, 3) + + "

Section title

" + + lineSeparator + + StringUtils.repeat(lineIndenter, 2) + + "
" + lineSeparator + StringUtils.repeat(lineIndenter, 1) + + "" + lineSeparator + ""; } } diff --git a/src/test/java/org/codehaus/plexus/util/xml/XmlStreamReaderTest.java b/src/test/java/org/codehaus/plexus/util/xml/XmlStreamReaderTest.java index 93f4eacf..85ad8763 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/XmlStreamReaderTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/XmlStreamReaderTest.java @@ -21,9 +21,12 @@ import java.io.InputStream; import java.io.SequenceInputStream; -import junit.framework.ComparisonFailure; -import junit.framework.TestCase; import org.codehaus.plexus.util.IOUtil; +import org.junit.jupiter.api.Test; +import org.opentest4j.AssertionFailedError; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** *

XmlStreamReaderTest class.

@@ -32,7 +35,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class XmlStreamReaderTest extends TestCase { +class XmlStreamReaderTest { /** french */ private static final String TEXT_LATIN1 = "eacute: \u00E9"; @@ -49,7 +52,7 @@ public class XmlStreamReaderTest extends TestCase { private static final String TEXT_UNICODE = TEXT_LATIN1 + ", " + TEXT_LATIN7 + ", " + TEXT_LATIN15 + ", " + TEXT_EUC_JP; - /** see http://unicode.org/faq/utf_bom.html#BOM */ + /** see ... */ private static final byte[] BOM_UTF8 = {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF}; private static final byte[] BOM_UTF16BE = {(byte) 0xFE, (byte) 0xFF}; @@ -65,8 +68,7 @@ private static String createXmlContent(String text, String encoding) { if (encoding != null) { xmlDecl = ""; } - String xml = xmlDecl + "\n" + text + ""; - return xml; + return xmlDecl + "\n" + text + ""; } private static void checkXmlContent(String xml, String encoding) throws IOException { @@ -111,7 +113,8 @@ private static void checkXmlStreamReader(String text, String encoding, String ef * * @throws java.io.IOException if any. */ - public void testNoXmlHeader() throws IOException { + @Test + void noXmlHeader() throws IOException { String xml = "text with no XML header"; checkXmlContent(xml, "UTF-8"); checkXmlContent(xml, "UTF-8", BOM_UTF8); @@ -122,7 +125,8 @@ public void testNoXmlHeader() throws IOException { * * @throws java.io.IOException if any. */ - public void testDefaultEncoding() throws IOException { + @Test + void defaultEncoding() throws IOException { checkXmlStreamReader(TEXT_UNICODE, null, "UTF-8"); checkXmlStreamReader(TEXT_UNICODE, null, "UTF-8", BOM_UTF8); } @@ -132,7 +136,8 @@ public void testDefaultEncoding() throws IOException { * * @throws java.io.IOException if any. */ - public void testUTF8Encoding() throws IOException { + @Test + void utf8Encoding() throws IOException { checkXmlStreamReader(TEXT_UNICODE, "UTF-8"); checkXmlStreamReader(TEXT_UNICODE, "UTF-8", BOM_UTF8); } @@ -142,7 +147,8 @@ public void testUTF8Encoding() throws IOException { * * @throws java.io.IOException if any. */ - public void testUTF16Encoding() throws IOException { + @Test + void utf16Encoding() throws IOException { checkXmlStreamReader(TEXT_UNICODE, "UTF-16", "UTF-16BE", null); checkXmlStreamReader(TEXT_UNICODE, "UTF-16", "UTF-16LE", BOM_UTF16LE); checkXmlStreamReader(TEXT_UNICODE, "UTF-16", "UTF-16BE", BOM_UTF16BE); @@ -153,7 +159,8 @@ public void testUTF16Encoding() throws IOException { * * @throws java.io.IOException if any. */ - public void testUTF16BEEncoding() throws IOException { + @Test + void utf16beEncoding() throws IOException { checkXmlStreamReader(TEXT_UNICODE, "UTF-16BE"); } @@ -162,7 +169,8 @@ public void testUTF16BEEncoding() throws IOException { * * @throws java.io.IOException if any. */ - public void testUTF16LEEncoding() throws IOException { + @Test + void utf16leEncoding() throws IOException { checkXmlStreamReader(TEXT_UNICODE, "UTF-16LE"); } @@ -171,7 +179,8 @@ public void testUTF16LEEncoding() throws IOException { * * @throws java.io.IOException if any. */ - public void testLatin1Encoding() throws IOException { + @Test + void latin1Encoding() throws IOException { checkXmlStreamReader(TEXT_LATIN1, "ISO-8859-1"); } @@ -180,7 +189,8 @@ public void testLatin1Encoding() throws IOException { * * @throws java.io.IOException if any. */ - public void testLatin7Encoding() throws IOException { + @Test + void latin7Encoding() throws IOException { checkXmlStreamReader(TEXT_LATIN7, "ISO-8859-7"); } @@ -189,7 +199,8 @@ public void testLatin7Encoding() throws IOException { * * @throws java.io.IOException if any. */ - public void testLatin15Encoding() throws IOException { + @Test + void latin15Encoding() throws IOException { checkXmlStreamReader(TEXT_LATIN15, "ISO-8859-15"); } @@ -198,7 +209,8 @@ public void testLatin15Encoding() throws IOException { * * @throws java.io.IOException if any. */ - public void testEUC_JPEncoding() throws IOException { + @Test + void euc_jpEncoding() throws IOException { checkXmlStreamReader(TEXT_EUC_JP, "EUC-JP"); } @@ -207,7 +219,8 @@ public void testEUC_JPEncoding() throws IOException { * * @throws java.io.IOException if any. */ - public void testEBCDICEncoding() throws IOException { + @Test + void ebcdicEncoding() throws IOException { checkXmlStreamReader("simple text in EBCDIC", "CP1047"); } @@ -216,11 +229,12 @@ public void testEBCDICEncoding() throws IOException { * * @throws java.io.IOException if any. */ - public void testInappropriateEncoding() throws IOException { + @Test + void inappropriateEncoding() throws IOException { try { checkXmlStreamReader(TEXT_UNICODE, "ISO-8859-2"); fail("Check should have failed, since some characters are not available in the specified encoding"); - } catch (ComparisonFailure cf) { + } catch (AssertionFailedError cf) { // expected failure, since the encoding does not contain some characters } } @@ -230,7 +244,8 @@ public void testInappropriateEncoding() throws IOException { * * @throws java.io.IOException if any. */ - public void testEncodingAttribute() throws IOException { + @Test + void encodingAttribute() throws IOException { String xml = ""; checkXmlContent(xml, "US-ASCII"); diff --git a/src/test/java/org/codehaus/plexus/util/xml/XmlStreamWriterTest.java b/src/test/java/org/codehaus/plexus/util/xml/XmlStreamWriterTest.java index 2930665e..bbe56427 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/XmlStreamWriterTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/XmlStreamWriterTest.java @@ -18,9 +18,9 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** *

XmlStreamWriterTest class.

@@ -29,7 +29,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class XmlStreamWriterTest { +class XmlStreamWriterTest { /** french */ private static final String TEXT_LATIN1 = "eacute: \u00E9"; @@ -77,7 +77,7 @@ private static void checkXmlWriter(String text, String encoding) throws IOExcept * @throws java.io.IOException if any. */ @Test - public void testNoXmlHeader() throws IOException { + void noXmlHeader() throws IOException { String xml = "text with no XML header"; checkXmlContent(xml, "UTF-8"); } @@ -88,7 +88,7 @@ public void testNoXmlHeader() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testEmpty() throws IOException { + void empty() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); XmlStreamWriter writer = new XmlStreamWriter(out); writer.flush(); @@ -105,7 +105,7 @@ public void testEmpty() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testDefaultEncoding() throws IOException { + void defaultEncoding() throws IOException { checkXmlWriter(TEXT_UNICODE, null); } @@ -115,7 +115,7 @@ public void testDefaultEncoding() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testUTF8Encoding() throws IOException { + void utf8Encoding() throws IOException { checkXmlWriter(TEXT_UNICODE, "UTF-8"); } @@ -125,7 +125,7 @@ public void testUTF8Encoding() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testUTF16Encoding() throws IOException { + void utf16Encoding() throws IOException { checkXmlWriter(TEXT_UNICODE, "UTF-16"); } @@ -135,7 +135,7 @@ public void testUTF16Encoding() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testUTF16BEEncoding() throws IOException { + void utf16beEncoding() throws IOException { checkXmlWriter(TEXT_UNICODE, "UTF-16BE"); } @@ -145,7 +145,7 @@ public void testUTF16BEEncoding() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testUTF16LEEncoding() throws IOException { + void utf16leEncoding() throws IOException { checkXmlWriter(TEXT_UNICODE, "UTF-16LE"); } @@ -155,7 +155,7 @@ public void testUTF16LEEncoding() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testLatin1Encoding() throws IOException { + void latin1Encoding() throws IOException { checkXmlWriter(TEXT_LATIN1, "ISO-8859-1"); } @@ -165,7 +165,7 @@ public void testLatin1Encoding() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testLatin7Encoding() throws IOException { + void latin7Encoding() throws IOException { checkXmlWriter(TEXT_LATIN7, "ISO-8859-7"); } @@ -175,7 +175,7 @@ public void testLatin7Encoding() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testLatin15Encoding() throws IOException { + void latin15Encoding() throws IOException { checkXmlWriter(TEXT_LATIN15, "ISO-8859-15"); } @@ -185,7 +185,7 @@ public void testLatin15Encoding() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testEUC_JPEncoding() throws IOException { + void euc_jpEncoding() throws IOException { checkXmlWriter(TEXT_EUC_JP, "EUC-JP"); } @@ -195,7 +195,7 @@ public void testEUC_JPEncoding() throws IOException { * @throws java.io.IOException if any. */ @Test - public void testEBCDICEncoding() throws IOException { + void ebcdicEncoding() throws IOException { checkXmlWriter("simple text in EBCDIC", "CP1047"); } } diff --git a/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java b/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java index f11cb29e..cbc81868 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java @@ -29,10 +29,10 @@ import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.WriterFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test the {@link org.codehaus.plexus.util.xml.XmlUtil} class. @@ -71,7 +71,7 @@ private File getTestOutputFile(String relPath) throws IOException { * @throws java.lang.Exception if any. */ @Test - public void testPrettyFormatInputStreamOutputStream() throws Exception { + void prettyFormatInputStreamOutputStream() throws Exception { File testDocument = new File(getBasedir(), "src/test/resources/testDocument.xhtml"); assertTrue(testDocument.exists()); @@ -98,7 +98,7 @@ public void testPrettyFormatInputStreamOutputStream() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testPrettyFormatReaderWriter() throws Exception { + void prettyFormatReaderWriter() throws Exception { File testDocument = new File(getBasedir(), "src/test/resources/testDocument.xhtml"); assertTrue(testDocument.exists()); @@ -124,7 +124,7 @@ public void testPrettyFormatReaderWriter() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testPrettyFormatString() throws Exception { + void prettyFormatString() throws Exception { File testDocument = new File(getBasedir(), "src/test/resources/testDocument.xhtml"); assertTrue(testDocument.exists()); @@ -155,7 +155,7 @@ public void testPrettyFormatString() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testPrettyFormatReaderWriter2() throws Exception { + void prettyFormatReaderWriter2() throws Exception { File testDocument = new File(getBasedir(), "src/test/resources/test.xdoc.xhtml"); assertTrue(testDocument.exists()); diff --git a/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java b/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java index 23ce4263..bc490e33 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java @@ -22,12 +22,12 @@ import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.WriterFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** *

XmlWriterUtilTest class.

@@ -36,7 +36,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class XmlWriterUtilTest { +class XmlWriterUtilTest { private OutputStream output; private Writer writer; @@ -48,8 +48,8 @@ public class XmlWriterUtilTest { * * @throws java.lang.Exception if any. */ - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { output = new ByteArrayOutputStream(); writer = WriterFactory.newXmlWriter(output); xmlWriter = new PrettyPrintXMLWriter(writer); @@ -60,8 +60,8 @@ public void setUp() throws Exception { * * @throws java.lang.Exception if any. */ - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() throws Exception { xmlWriter = null; writer = null; output = null; @@ -74,10 +74,10 @@ public void tearDown() throws Exception { * @throws java.lang.Exception if any */ @Test - public void testWriteLineBreakXMLWriter() throws Exception { + void writeLineBreakXMLWriter() throws Exception { XmlWriterUtil.writeLineBreak(xmlWriter); writer.close(); - assertTrue(StringUtils.countMatches(output.toString(), XmlWriterUtil.LS) == 1); + assertEquals(1, StringUtils.countMatches(output.toString(), XmlWriterUtil.LS)); } /** @@ -87,10 +87,10 @@ public void testWriteLineBreakXMLWriter() throws Exception { * @throws java.lang.Exception if any */ @Test - public void testWriteLineBreakXMLWriterInt() throws Exception { + void writeLineBreakXMLWriterInt() throws Exception { XmlWriterUtil.writeLineBreak(xmlWriter, 10); writer.close(); - assertTrue(StringUtils.countMatches(output.toString(), XmlWriterUtil.LS) == 10); + assertEquals(10, StringUtils.countMatches(output.toString(), XmlWriterUtil.LS)); } /** @@ -100,13 +100,14 @@ public void testWriteLineBreakXMLWriterInt() throws Exception { * @throws java.lang.Exception if any */ @Test - public void testWriteLineBreakXMLWriterIntInt() throws Exception { + void writeLineBreakXMLWriterIntInt() throws Exception { XmlWriterUtil.writeLineBreak(xmlWriter, 10, 2); writer.close(); - assertTrue(StringUtils.countMatches(output.toString(), XmlWriterUtil.LS) == 10); - assertTrue(StringUtils.countMatches( - output.toString(), StringUtils.repeat(" ", 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE)) - == 1); + assertEquals(10, StringUtils.countMatches(output.toString(), XmlWriterUtil.LS)); + assertEquals( + 1, + StringUtils.countMatches( + output.toString(), StringUtils.repeat(" ", 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE))); } /** @@ -116,11 +117,11 @@ public void testWriteLineBreakXMLWriterIntInt() throws Exception { * @throws java.lang.Exception if any */ @Test - public void testWriteLineBreakXMLWriterIntIntInt() throws Exception { + void writeLineBreakXMLWriterIntIntInt() throws Exception { XmlWriterUtil.writeLineBreak(xmlWriter, 10, 2, 4); writer.close(); - assertTrue(StringUtils.countMatches(output.toString(), XmlWriterUtil.LS) == 10); - assertTrue(StringUtils.countMatches(output.toString(), StringUtils.repeat(" ", 2 * 4)) == 1); + assertEquals(10, StringUtils.countMatches(output.toString(), XmlWriterUtil.LS)); + assertEquals(1, StringUtils.countMatches(output.toString(), StringUtils.repeat(" ", 2 * 4))); } /** @@ -130,14 +131,13 @@ public void testWriteLineBreakXMLWriterIntIntInt() throws Exception { * @throws java.lang.Exception if any */ @Test - public void testWriteCommentLineBreakXMLWriter() throws Exception { + void writeCommentLineBreakXMLWriter() throws Exception { XmlWriterUtil.writeCommentLineBreak(xmlWriter); writer.close(); - StringBuilder sb = new StringBuilder(); - sb.append("") - .append(XmlWriterUtil.LS); - assertEquals(output.toString(), sb.toString()); - assertTrue(output.toString().length() == XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length()); + String sb = + "" + XmlWriterUtil.LS; + assertEquals(output.toString(), sb); + assertEquals(output.toString().length(), XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length()); } /** @@ -147,17 +147,17 @@ public void testWriteCommentLineBreakXMLWriter() throws Exception { * @throws java.lang.Exception if any */ @Test - public void testWriteCommentLineBreakXMLWriterInt() throws Exception { + void writeCommentLineBreakXMLWriterInt() throws Exception { XmlWriterUtil.writeCommentLineBreak(xmlWriter, 20); writer.close(); - assertEquals(output.toString(), "" + XmlWriterUtil.LS); + assertEquals("" + XmlWriterUtil.LS, output.toString()); tearDown(); setUp(); XmlWriterUtil.writeCommentLineBreak(xmlWriter, 10); writer.close(); - assertEquals(output.toString(), output.toString(), "" + XmlWriterUtil.LS); + assertEquals("" + XmlWriterUtil.LS, output.toString(), output.toString()); } /** @@ -167,14 +167,14 @@ public void testWriteCommentLineBreakXMLWriterInt() throws Exception { * @throws java.lang.Exception if any */ @Test - public void testWriteCommentXMLWriterString() throws Exception { + void writeCommentXMLWriterString() throws Exception { XmlWriterUtil.writeComment(xmlWriter, "hello"); writer.close(); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("") .append(XmlWriterUtil.LS); assertEquals(output.toString(), sb.toString()); - assertTrue(output.toString().length() == XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length()); + assertEquals(output.toString().length(), XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length()); tearDown(); setUp(); @@ -182,7 +182,7 @@ public void testWriteCommentXMLWriterString() throws Exception { XmlWriterUtil.writeComment( xmlWriter, "hellooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"); writer.close(); - sb = new StringBuffer(); + sb = new StringBuilder(); sb.append("") .append(XmlWriterUtil.LS); assertEquals(output.toString(), sb.toString()); @@ -193,14 +193,14 @@ public void testWriteCommentXMLWriterString() throws Exception { XmlWriterUtil.writeComment(xmlWriter, "hello\nworld"); writer.close(); - sb = new StringBuffer(); + sb = new StringBuilder(); sb.append("") .append(XmlWriterUtil.LS); sb.append("") .append(XmlWriterUtil.LS); assertEquals(output.toString(), sb.toString()); - assertTrue( - output.toString().length() == 2 * (XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length())); + assertEquals( + output.toString().length(), 2 * (XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length())); } /** @@ -210,18 +210,19 @@ public void testWriteCommentXMLWriterString() throws Exception { * @throws java.lang.Exception if any */ @Test - public void testWriteCommentXMLWriterStringInt() throws Exception { + void writeCommentXMLWriterStringInt() throws Exception { String indent = StringUtils.repeat(" ", 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE); XmlWriterUtil.writeComment(xmlWriter, "hello", 2); writer.close(); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append(indent); sb.append("") .append(XmlWriterUtil.LS); assertEquals(output.toString(), sb.toString()); - assertTrue(output.toString().length() - == XmlWriterUtil.DEFAULT_COLUMN_LINE + assertEquals( + output.toString().length(), + XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length() + 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE); @@ -231,7 +232,7 @@ public void testWriteCommentXMLWriterStringInt() throws Exception { XmlWriterUtil.writeComment(xmlWriter, "hello\nworld", 2); writer.close(); - sb = new StringBuffer(); + sb = new StringBuilder(); sb.append(indent); sb.append("") .append(XmlWriterUtil.LS); @@ -239,8 +240,9 @@ public void testWriteCommentXMLWriterStringInt() throws Exception { sb.append("") .append(XmlWriterUtil.LS); assertEquals(output.toString(), sb.toString()); - assertTrue(output.toString().length() - == 2 * (XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length()) + 2 * indent.length()); + assertEquals( + output.toString().length(), + 2 * (XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length()) + 2 * indent.length()); } /** @@ -250,25 +252,25 @@ public void testWriteCommentXMLWriterStringInt() throws Exception { * @throws java.lang.Exception if any */ @Test - public void testWriteCommentXMLWriterStringIntInt() throws Exception { + void writeCommentXMLWriterStringIntInt() throws Exception { String repeat = StringUtils.repeat(" ", 2 * 4); XmlWriterUtil.writeComment(xmlWriter, "hello", 2, 4); writer.close(); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append(repeat); sb.append("") .append(XmlWriterUtil.LS); assertEquals(output.toString(), sb.toString()); - assertTrue(output.toString().length() - == XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length() + 2 * 4); + assertEquals( + output.toString().length(), XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length() + 2 * 4); tearDown(); setUp(); XmlWriterUtil.writeComment(xmlWriter, "hello\nworld", 2, 4); writer.close(); - sb = new StringBuffer(); + sb = new StringBuilder(); sb.append(repeat); sb.append("") .append(XmlWriterUtil.LS); @@ -276,8 +278,9 @@ public void testWriteCommentXMLWriterStringIntInt() throws Exception { sb.append("") .append(XmlWriterUtil.LS); assertEquals(output.toString(), sb.toString()); - assertTrue(output.toString().length() - == 2 * (XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length()) + 2 * repeat.length()); + assertEquals( + output.toString().length(), + 2 * (XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length()) + 2 * repeat.length()); } /** @@ -287,23 +290,23 @@ public void testWriteCommentXMLWriterStringIntInt() throws Exception { * @throws java.lang.Exception if any */ @Test - public void testWriteCommentXMLWriterStringIntIntInt() throws Exception { + void writeCommentXMLWriterStringIntIntInt() throws Exception { String indent = StringUtils.repeat(" ", 2 * 4); XmlWriterUtil.writeComment(xmlWriter, "hello", 2, 4, 50); writer.close(); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append(indent); sb.append("").append(XmlWriterUtil.LS); assertEquals(output.toString(), sb.toString()); - assertTrue(output.toString().length() == 50 - 1 + XmlWriterUtil.LS.length() + 2 * 4); + assertEquals(output.toString().length(), 50 - 1 + XmlWriterUtil.LS.length() + 2 * 4); tearDown(); setUp(); XmlWriterUtil.writeComment(xmlWriter, "hello", 2, 4, 10); writer.close(); - sb = new StringBuffer(); + sb = new StringBuilder(); sb.append(indent); sb.append("").append(XmlWriterUtil.LS); assertEquals(output.toString(), sb.toString()); @@ -317,10 +320,10 @@ public void testWriteCommentXMLWriterStringIntIntInt() throws Exception { * @throws java.lang.Exception if any */ @Test - public void testWriteCommentTextXMLWriterStringInt() throws Exception { + void writeCommentTextXMLWriterStringInt() throws Exception { XmlWriterUtil.writeCommentText(xmlWriter, "hello", 0); writer.close(); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append(XmlWriterUtil.LS); sb.append("") .append(XmlWriterUtil.LS); @@ -330,8 +333,8 @@ public void testWriteCommentTextXMLWriterStringInt() throws Exception { .append(XmlWriterUtil.LS); sb.append(XmlWriterUtil.LS); assertEquals(output.toString(), sb.toString()); - assertTrue( - output.toString().length() == 3 * (80 - 1 + XmlWriterUtil.LS.length()) + 2 * XmlWriterUtil.LS.length()); + assertEquals( + output.toString().length(), 3 * (80 - 1 + XmlWriterUtil.LS.length()) + 2 * XmlWriterUtil.LS.length()); tearDown(); setUp(); @@ -344,7 +347,7 @@ public void testWriteCommentTextXMLWriterStringInt() throws Exception { + "loooooooooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnnnong line", 2); writer.close(); - sb = new StringBuffer(); + sb = new StringBuilder(); sb.append(XmlWriterUtil.LS); sb.append(indent) .append("") @@ -376,27 +379,26 @@ public void testWriteCommentTextXMLWriterStringInt() throws Exception { * @throws java.lang.Exception if any */ @Test - public void testWriteCommentTextXMLWriterStringIntInt() throws Exception { + void writeCommentTextXMLWriterStringIntInt() throws Exception { String indent = StringUtils.repeat(" ", 2 * 4); XmlWriterUtil.writeCommentText(xmlWriter, "hello", 2, 4); writer.close(); - StringBuilder sb = new StringBuilder(); - sb.append(XmlWriterUtil.LS); - sb.append(indent) - .append("") - .append(XmlWriterUtil.LS); - sb.append(indent) - .append("") - .append(XmlWriterUtil.LS); - sb.append(indent) - .append("") - .append(XmlWriterUtil.LS); - sb.append(XmlWriterUtil.LS); - sb.append(indent); - assertEquals(output.toString(), sb.toString()); - assertTrue(output.toString().length() - == 3 * (80 - 1 + XmlWriterUtil.LS.length()) + 4 * 2 * 4 + 2 * XmlWriterUtil.LS.length()); + String sb = XmlWriterUtil.LS + indent + + "" + + XmlWriterUtil.LS + + indent + + "" + + XmlWriterUtil.LS + + indent + + "" + + XmlWriterUtil.LS + + XmlWriterUtil.LS + + indent; + assertEquals(output.toString(), sb); + assertEquals( + output.toString().length(), + 3 * (80 - 1 + XmlWriterUtil.LS.length()) + 4 * 2 * 4 + 2 * XmlWriterUtil.LS.length()); } /** @@ -406,27 +408,26 @@ public void testWriteCommentTextXMLWriterStringIntInt() throws Exception { * @throws java.lang.Exception if any */ @Test - public void testWriteCommentTextXMLWriterStringIntIntInt() throws Exception { + void writeCommentTextXMLWriterStringIntIntInt() throws Exception { String indent = StringUtils.repeat(" ", 2 * 4); XmlWriterUtil.writeCommentText(xmlWriter, "hello", 2, 4, 50); writer.close(); - StringBuilder sb = new StringBuilder(); - sb.append(XmlWriterUtil.LS); - sb.append(indent) - .append("") - .append(XmlWriterUtil.LS); - sb.append(indent) - .append("") - .append(XmlWriterUtil.LS); - sb.append(indent) - .append("") - .append(XmlWriterUtil.LS); - sb.append(XmlWriterUtil.LS); - sb.append(indent); - assertEquals(output.toString(), sb.toString()); - assertTrue(output.toString().length() - == 3 * (50 - 1 + XmlWriterUtil.LS.length()) + 4 * 2 * 4 + 2 * XmlWriterUtil.LS.length()); + String sb = XmlWriterUtil.LS + indent + + "" + + XmlWriterUtil.LS + + indent + + "" + + XmlWriterUtil.LS + + indent + + "" + + XmlWriterUtil.LS + + XmlWriterUtil.LS + + indent; + assertEquals(output.toString(), sb); + assertEquals( + output.toString().length(), + 3 * (50 - 1 + XmlWriterUtil.LS.length()) + 4 * 2 * 4 + 2 * XmlWriterUtil.LS.length()); } /** @@ -436,13 +437,12 @@ public void testWriteCommentTextXMLWriterStringIntIntInt() throws Exception { * @throws java.lang.Exception if any */ @Test - public void testWriteCommentNull() throws Exception { + void writeCommentNull() throws Exception { XmlWriterUtil.writeComment(xmlWriter, null); writer.close(); - StringBuilder sb = new StringBuilder(); - sb.append("") - .append(XmlWriterUtil.LS); - assertEquals(output.toString(), sb.toString()); + String sb = + "" + XmlWriterUtil.LS; + assertEquals(output.toString(), sb); } /** @@ -452,13 +452,12 @@ public void testWriteCommentNull() throws Exception { * @throws java.lang.Exception if any */ @Test - public void testWriteCommentShort() throws Exception { + void writeCommentShort() throws Exception { XmlWriterUtil.writeComment(xmlWriter, "This is a short text"); writer.close(); - StringBuilder sb = new StringBuilder(); - sb.append("") - .append(XmlWriterUtil.LS); - assertEquals(output.toString(), sb.toString()); + String sb = + "" + XmlWriterUtil.LS; + assertEquals(output.toString(), sb); } /** @@ -468,22 +467,20 @@ public void testWriteCommentShort() throws Exception { * @throws java.lang.Exception if any */ @Test - public void testWriteCommentLong() throws Exception { + void writeCommentLong() throws Exception { XmlWriterUtil.writeComment( xmlWriter, "Maven is a software project management and comprehension tool. " + "Based on the concept of a project object model (POM), Maven can manage a project's build, reporting " + "and documentation from a central piece of information."); writer.close(); - StringBuilder sb = new StringBuilder(); - sb.append("") - .append(XmlWriterUtil.LS); - sb.append("") - .append(XmlWriterUtil.LS); - sb.append("") - .append(XmlWriterUtil.LS); - sb.append("") - .append(XmlWriterUtil.LS); - assertEquals(output.toString(), sb.toString()); + String sb = "" + XmlWriterUtil.LS + + "" + + XmlWriterUtil.LS + + "" + + XmlWriterUtil.LS + + "" + + XmlWriterUtil.LS; + assertEquals(output.toString(), sb); } } diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java index f9faac45..36a91ca5 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java @@ -23,11 +23,11 @@ import org.codehaus.plexus.util.xml.pull.MXParser; import org.codehaus.plexus.util.xml.pull.XmlPullParser; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test the Xpp3DomBuilder. @@ -36,7 +36,7 @@ * @version $Id: $Id * @since 3.4.0 */ -public class Xpp3DomBuilderTest { +class Xpp3DomBuilderTest { private static final String LS = System.lineSeparator(); /** @@ -45,14 +45,14 @@ public class Xpp3DomBuilderTest { * @throws java.lang.Exception if any. */ @Test - public void testBuildFromReader() throws Exception { + void buildFromReader() throws Exception { String domString = createDomString(); Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(domString)); Xpp3Dom expectedDom = createExpectedDom(); - assertEquals("check DOMs match", expectedDom, dom); + assertEquals(expectedDom, dom, "check DOMs match"); } /** @@ -61,17 +61,16 @@ public void testBuildFromReader() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testBuildTrimming() throws Exception { + void buildTrimming() throws Exception { String domString = createDomString(); Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(domString), true); - assertEquals("test with trimming on", "element1", dom.getChild("el1").getValue()); + assertEquals("element1", dom.getChild("el1").getValue(), "test with trimming on"); dom = Xpp3DomBuilder.build(new StringReader(domString), false); - assertEquals( - "test with trimming off", " element1\n ", dom.getChild("el1").getValue()); + assertEquals(" element1\n ", dom.getChild("el1").getValue(), "test with trimming off"); } /** @@ -80,7 +79,7 @@ public void testBuildTrimming() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testBuildFromXpp3Dom() throws Exception { + void buildFromXpp3Dom() throws Exception { Xpp3Dom expectedDom = createExpectedDom(); Xpp3Dom dom = null; @@ -116,17 +115,17 @@ public void testBuildFromXpp3Dom() throws Exception { eventType = parser.next(); } - assertEquals("Check DOM matches", expectedDom, dom); - assertFalse("Check closing root was consumed", rootClosed); - assertTrue("Check continued to parse configuration", configurationClosed); - assertTrue("Check continued to parse newRoot", newRootClosed); + assertEquals(expectedDom, dom, "Check DOM matches"); + assertFalse(rootClosed, "Check closing root was consumed"); + assertTrue(configurationClosed, "Check continued to parse configuration"); + assertTrue(newRootClosed, "Check continued to parse newRoot"); } /** * Test we get an error from the parser, and don't hit the IllegalStateException. */ @Test - public void testUnclosedXml() { + void unclosedXml() { String domString = "" + createDomString(); try { Xpp3DomBuilder.build(new StringReader(domString)); @@ -146,18 +145,16 @@ public void testUnclosedXml() { * @throws org.codehaus.plexus.util.xml.pull.XmlPullParserException if any. */ @Test - public void testEscapingInContent() throws IOException, XmlPullParserException { + void escapingInContent() throws IOException, XmlPullParserException { Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(getEncodedString())); - assertEquals("Check content value", "\"text\"", dom.getChild("el").getValue()); - assertEquals( - "Check content value", "\"text\"", dom.getChild("ela").getValue()); - assertEquals( - "Check content value", "\"text\"", dom.getChild("elb").getValue()); + assertEquals("\"text\"", dom.getChild("el").getValue(), "Check content value"); + assertEquals("\"text\"", dom.getChild("ela").getValue(), "Check content value"); + assertEquals("\"text\"", dom.getChild("elb").getValue(), "Check content value"); StringWriter w = new StringWriter(); Xpp3DomWriter.write(w, dom); - assertEquals("Compare stringified DOMs", getExpectedString(), w.toString()); + assertEquals(getExpectedString(), w.toString(), "Compare stringified DOMs"); } /** @@ -167,16 +164,16 @@ public void testEscapingInContent() throws IOException, XmlPullParserException { * @throws org.codehaus.plexus.util.xml.pull.XmlPullParserException if any. */ @Test - public void testEscapingInAttributes() throws IOException, XmlPullParserException { + void escapingInAttributes() throws IOException, XmlPullParserException { String s = getAttributeEncodedString(); Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(s)); - assertEquals("Check attribute value", "", dom.getChild("el").getAttribute("att")); + assertEquals("", dom.getChild("el").getAttribute("att"), "Check attribute value"); StringWriter w = new StringWriter(); Xpp3DomWriter.write(w, dom); String newString = w.toString(); - assertEquals("Compare stringified DOMs", newString, s); + assertEquals(newString, s, "Compare stringified DOMs"); } /** @@ -186,63 +183,51 @@ public void testEscapingInAttributes() throws IOException, XmlPullParserExceptio * @throws org.codehaus.plexus.util.xml.pull.XmlPullParserException if any. */ @Test - public void testInputLocationTracking() throws IOException, XmlPullParserException { - Xpp3DomBuilder.InputLocationBuilder ilb = new Xpp3DomBuilder.InputLocationBuilder() { - public Object toInputLocation(XmlPullParser parser) { - return parser.getLineNumber(); // store only line number as a simple Integer - } - }; + void inputLocationTracking() throws IOException, XmlPullParserException { + // store only line number as a simple Integer + Xpp3DomBuilder.InputLocationBuilder ilb = XmlPullParser::getLineNumber; Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(createDomString()), true, ilb); Xpp3Dom expectedDom = createExpectedDom(); - assertEquals("root input location", expectedDom.getInputLocation(), dom.getInputLocation()); + assertEquals(expectedDom.getInputLocation(), dom.getInputLocation(), "root input location"); for (int i = 0; i < dom.getChildCount(); i++) { Xpp3Dom elt = dom.getChild(i); Xpp3Dom expectedElt = expectedDom.getChild(i); - assertEquals(elt.getName() + " input location", expectedElt.getInputLocation(), elt.getInputLocation()); + assertEquals(expectedElt.getInputLocation(), elt.getInputLocation(), elt.getName() + " input location"); if ("el2".equals(elt.getName())) { Xpp3Dom el3 = elt.getChild(0); Xpp3Dom expectedEl3 = expectedElt.getChild(0); - assertEquals(el3.getName() + " input location", expectedEl3.getInputLocation(), el3.getInputLocation()); + assertEquals(expectedEl3.getInputLocation(), el3.getInputLocation(), el3.getName() + " input location"); } } } private static String getAttributeEncodedString() { - StringBuilder domString = new StringBuilder(); - domString.append(""); - domString.append(LS); - domString.append(" bar"); - domString.append(LS); - domString.append(""); - - return domString.toString(); + String domString = "" + LS + " bar" + LS + ""; + + return domString; } private static String getEncodedString() { - StringBuilder domString = new StringBuilder(); - domString.append("\n"); - domString.append(" \"text\"\n"); - domString.append(" \"text\"]]>\n"); - domString.append(" <b>"text"</b>\n"); - domString.append(""); - - return domString.toString(); + String domString = "\n" + " \"text\"\n" + + " \"text\"]]>\n" + + " <b>"text"</b>\n" + + ""; + + return domString; } private static String getExpectedString() { - StringBuilder domString = new StringBuilder(); - domString.append(""); - domString.append(LS); - domString.append(" "text""); - domString.append(LS); - domString.append(" <b>"text"</b>"); - domString.append(LS); - domString.append(" <b>"text"</b>"); - domString.append(LS); - domString.append(""); - - return domString.toString(); + String domString = "" + LS + + " "text"" + + LS + + " <b>"text"</b>" + + LS + + " <b>"text"</b>" + + LS + + ""; + + return domString; } // @@ -250,18 +235,16 @@ private static String getExpectedString() { // private static String createDomString() { - StringBuilder buf = new StringBuilder(); - buf.append("\n"); - buf.append(" element1\n \n"); - buf.append(" \n"); - buf.append(" element3\n"); - buf.append(" \n"); - buf.append(" \n"); - buf.append(" \n"); - buf.append(" do not trim \n"); - buf.append("\n"); - - return buf.toString(); + String buf = "\n" + " element1\n \n" + + " \n" + + " element3\n" + + " \n" + + " \n" + + " \n" + + " do not trim \n" + + "\n"; + + return buf; } private static Xpp3Dom createExpectedDom() { diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java index c4f21029..33cd5057 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java @@ -22,14 +22,14 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParser; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; /** *

Xpp3DomTest class.

@@ -38,12 +38,12 @@ * @version $Id: $Id * @since 3.4.0 */ -public class Xpp3DomTest { +class Xpp3DomTest { /** *

testShouldPerformAppendAtFirstSubElementLevel.

*/ @Test - public void testShouldPerformAppendAtFirstSubElementLevel() { + void shouldPerformAppendAtFirstSubElementLevel() { // create the dominant DOM Xpp3Dom t1 = new Xpp3Dom("top"); t1.setAttribute(Xpp3Dom.CHILDREN_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.CHILDREN_COMBINATION_APPEND); @@ -81,7 +81,7 @@ public void testShouldPerformAppendAtFirstSubElementLevel() { *

testShouldOverrideAppendAndDeepMerge.

*/ @Test - public void testShouldOverrideAppendAndDeepMerge() { + void shouldOverrideAppendAndDeepMerge() { // create the dominant DOM Xpp3Dom t1 = new Xpp3Dom("top"); t1.setAttribute(Xpp3Dom.CHILDREN_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.CHILDREN_COMBINATION_APPEND); @@ -117,7 +117,7 @@ public void testShouldOverrideAppendAndDeepMerge() { *

testShouldPerformSelfOverrideAtTopLevel.

*/ @Test - public void testShouldPerformSelfOverrideAtTopLevel() { + void shouldPerformSelfOverrideAtTopLevel() { // create the dominant DOM Xpp3Dom t1 = new Xpp3Dom("top"); t1.setAttribute("attr", "value"); @@ -143,7 +143,7 @@ public void testShouldPerformSelfOverrideAtTopLevel() { *

testShouldMergeValuesAtTopLevelByDefault.

*/ @Test - public void testShouldMergeValuesAtTopLevelByDefault() { + void shouldMergeValuesAtTopLevelByDefault() { // create the dominant DOM Xpp3Dom t1 = new Xpp3Dom("top"); t1.setAttribute("attr", "value"); @@ -169,7 +169,7 @@ public void testShouldMergeValuesAtTopLevelByDefault() { *

testShouldMergeValuesAtTopLevel.

*/ @Test - public void testShouldMergeValuesAtTopLevel() { + void shouldMergeValuesAtTopLevel() { // create the dominant DOM Xpp3Dom t1 = new Xpp3Dom("top"); t1.setAttribute("attr", "value"); @@ -192,7 +192,7 @@ public void testShouldMergeValuesAtTopLevel() { *

testNullAttributeNameOrValue.

*/ @Test - public void testNullAttributeNameOrValue() { + void nullAttributeNameOrValue() { Xpp3Dom t1 = new Xpp3Dom("top"); try { t1.setAttribute("attr", null); @@ -212,12 +212,12 @@ public void testNullAttributeNameOrValue() { *

testEquals.

*/ @Test - public void testEquals() { + void equals() { Xpp3Dom dom = new Xpp3Dom("top"); assertEquals(dom, dom); - assertFalse(dom.equals(null)); - assertFalse(dom.equals(new Xpp3Dom((String) null))); + assertNotEquals(null, dom); + assertNotEquals(new Xpp3Dom((String) null), dom); } /** @@ -227,20 +227,20 @@ public void testEquals() { * @throws java.io.IOException if any. */ @Test - public void testEqualsIsNullSafe() throws XmlPullParserException, IOException { + void equalsIsNullSafe() throws XmlPullParserException, IOException { String testDom = "onetwo"; Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(testDom)); Xpp3Dom dom2 = Xpp3DomBuilder.build(new StringReader(testDom)); try { - dom2.attributes = new HashMap(); + dom2.attributes = new HashMap<>(); dom2.attributes.put("nullValue", null); dom2.attributes.put(null, "nullKey"); dom2.childList.clear(); dom2.childList.add(null); - assertFalse(dom.equals(dom2)); - assertFalse(dom2.equals(dom)); + assertNotEquals(dom, dom2); + assertNotEquals(dom2, dom); } catch (NullPointerException ex) { ex.printStackTrace(); @@ -255,7 +255,7 @@ public void testEqualsIsNullSafe() throws XmlPullParserException, IOException { * @throws java.io.IOException if any. */ @Test - public void testShouldOverwritePluginConfigurationSubItemsByDefault() throws XmlPullParserException, IOException { + void shouldOverwritePluginConfigurationSubItemsByDefault() throws XmlPullParserException, IOException { String parentConfigStr = "onetwo"; Xpp3Dom parentConfig = Xpp3DomBuilder.build(new StringReader(parentConfigStr), new FixedInputLocationBuilder("parent")); @@ -281,8 +281,7 @@ public void testShouldOverwritePluginConfigurationSubItemsByDefault() throws Xml * @throws java.io.IOException if any. */ @Test - public void testShouldMergePluginConfigurationSubItemsWithMergeAttributeSet() - throws XmlPullParserException, IOException { + void shouldMergePluginConfigurationSubItemsWithMergeAttributeSet() throws XmlPullParserException, IOException { String parentConfigStr = "onetwo"; Xpp3Dom parentConfig = Xpp3DomBuilder.build(new StringReader(parentConfigStr), new FixedInputLocationBuilder("parent")); @@ -313,7 +312,7 @@ public void testShouldMergePluginConfigurationSubItemsWithMergeAttributeSet() * @throws java.lang.Exception if any. */ @Test - public void testShouldNotChangeUponMergeWithItselfWhenFirstOrLastSubItemIsEmpty() throws Exception { + void shouldNotChangeUponMergeWithItselfWhenFirstOrLastSubItemIsEmpty() throws Exception { String configStr = "test"; Xpp3Dom dominantConfig = Xpp3DomBuilder.build(new StringReader(configStr)); Xpp3Dom recessiveConfig = Xpp3DomBuilder.build(new StringReader(configStr)); @@ -323,9 +322,9 @@ public void testShouldNotChangeUponMergeWithItselfWhenFirstOrLastSubItemIsEmpty( assertEquals(3, items.getChildCount()); - assertEquals(null, items.getChild(0).getValue()); + assertNull(items.getChild(0).getValue()); assertEquals("test", items.getChild(1).getValue()); - assertEquals(null, items.getChild(2).getValue()); + assertNull(items.getChild(2).getValue()); } /** @@ -334,7 +333,7 @@ public void testShouldNotChangeUponMergeWithItselfWhenFirstOrLastSubItemIsEmpty( * @throws java.lang.Exception if any. */ @Test - public void testShouldCopyRecessiveChildrenNotPresentInTarget() throws Exception { + void shouldCopyRecessiveChildrenNotPresentInTarget() throws Exception { String dominantStr = "x"; String recessiveStr = "y"; Xpp3Dom dominantConfig = Xpp3DomBuilder.build(new StringReader(dominantStr)); @@ -356,7 +355,7 @@ public void testShouldCopyRecessiveChildrenNotPresentInTarget() throws Exception * @throws org.codehaus.plexus.util.xml.pull.XmlPullParserException if any. */ @Test - public void testDupeChildren() throws IOException, XmlPullParserException { + void dupeChildren() throws IOException, XmlPullParserException { String dupes = "xy"; Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(dupes)); assertNotNull(dom); @@ -369,7 +368,7 @@ public void testDupeChildren() throws IOException, XmlPullParserException { * @throws java.lang.Exception if any. */ @Test - public void testShouldRemoveEntireElementWithAttributesAndChildren() throws Exception { + void shouldRemoveEntireElementWithAttributesAndChildren() throws Exception { String dominantStr = ""; String recessiveStr = "parameter"; Xpp3Dom dominantConfig = Xpp3DomBuilder.build(new StringReader(dominantStr)); @@ -387,7 +386,7 @@ public void testShouldRemoveEntireElementWithAttributesAndChildren() throws Exce * @throws java.lang.Exception if any. */ @Test - public void testShouldRemoveDoNotRemoveTagWhenSwappedInputDOMs() throws Exception { + void shouldRemoveDoNotRemoveTagWhenSwappedInputDOMs() throws Exception { String dominantStr = ""; String recessiveStr = "parameter"; Xpp3Dom dominantConfig = Xpp3DomBuilder.build(new StringReader(dominantStr)); diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java index ea21509a..64c31430 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java @@ -21,9 +21,9 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParser; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** *

Xpp3DomUtilsTest class.

@@ -32,14 +32,14 @@ * @version $Id: $Id * @since 3.4.0 */ -public class Xpp3DomUtilsTest { +class Xpp3DomUtilsTest { /** *

testCombineId.

* * @throws java.lang.Exception if any. */ @Test - public void testCombineId() throws Exception { + void combineId() throws Exception { String lhs = "" + "LHS-ONLYLHS" + "TOOVERWRITELHS" + ""; @@ -85,7 +85,7 @@ public void testCombineId() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testCombineKeys() throws Exception { + void combineKeys() throws Exception { String lhs = "" + "LHS-ONLYLHS" + "TOOVERWRITELHS" + ""; @@ -126,7 +126,7 @@ public void testCombineKeys() throws Exception { } @Test - public void testPreserveDominantBlankValue() throws XmlPullParserException, IOException { + void preserveDominantBlankValue() throws XmlPullParserException, IOException { String lhs = " "; String rhs = "recessive"; @@ -139,7 +139,7 @@ public void testPreserveDominantBlankValue() throws XmlPullParserException, IOEx } @Test - public void testPreserveDominantEmptyNode() throws XmlPullParserException, IOException { + void preserveDominantEmptyNode() throws XmlPullParserException, IOException { String lhs = ""; String rhs = "recessive"; @@ -152,7 +152,7 @@ public void testPreserveDominantEmptyNode() throws XmlPullParserException, IOExc } @Test - public void testIsNotEmptyNegatesIsEmpty() { + void isNotEmptyNegatesIsEmpty() { assertEquals(!Xpp3DomUtils.isEmpty(null), Xpp3DomUtils.isNotEmpty(null)); assertEquals(!Xpp3DomUtils.isEmpty(""), Xpp3DomUtils.isNotEmpty("")); assertEquals(!Xpp3DomUtils.isEmpty(" "), Xpp3DomUtils.isNotEmpty(" ")); diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomWriterTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomWriterTest.java index 55853d0b..9d28efc5 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomWriterTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomWriterTest.java @@ -18,9 +18,9 @@ import java.io.StringWriter; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** *

Xpp3DomWriterTest class.

@@ -29,31 +29,31 @@ * @version $Id: $Id * @since 3.4.0 */ -public class Xpp3DomWriterTest { - private static final String LS = System.getProperty("line.separator"); +class Xpp3DomWriterTest { + private static final String LS = System.lineSeparator(); /** *

testWriter.

*/ @Test - public void testWriter() { + void writer() { StringWriter writer = new StringWriter(); Xpp3DomWriter.write(writer, createXpp3Dom()); - assertEquals("Check if output matches", createExpectedXML(true), writer.toString()); + assertEquals(createExpectedXML(true), writer.toString(), "Check if output matches"); } /** *

testWriterNoEscape.

*/ @Test - public void testWriterNoEscape() { + void writerNoEscape() { StringWriter writer = new StringWriter(); Xpp3DomWriter.write(new PrettyPrintXMLWriter(writer), createXpp3Dom(), false); - assertEquals("Check if output matches", createExpectedXML(false), writer.toString()); + assertEquals(createExpectedXML(false), writer.toString(), "Check if output matches"); } private String createExpectedXML(boolean escape) { @@ -77,7 +77,7 @@ private String createExpectedXML(boolean escape) { if (escape) { buf.append(" element7").append(LS).append("&"'<>"); } else { - buf.append(" element7").append(LS).append("&\"\'<>"); + buf.append(" element7").append(LS).append("&\"'<>"); } buf.append(LS); buf.append(" "); @@ -116,7 +116,7 @@ private Xpp3Dom createXpp3Dom() { dom.addChild(el6); Xpp3Dom el7 = new Xpp3Dom("el7"); - el7.setValue("element7\n&\"\'<>"); + el7.setValue("element7\n&\"'<>"); el6.addChild(el7); return dom; diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test.java b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test.java index becde36c..2e1fd7fe 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test.java @@ -5,11 +5,11 @@ import java.io.IOException; import java.io.Reader; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Test class that execute a particular set of tests associated to a TESCASES tag from the XML W3C Conformance Tests. @@ -20,7 +20,6 @@ * @version $Id: $Id * @since 3.4.0 */ -public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test { static final File testResourcesDir = new File("src/test/resources/", "xmlconf/ibm/"); @@ -30,8 +29,8 @@ class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConfo /** *

setUp.

*/ - @Before - public void setUp() { + @BeforeEach + void setUp() { parser = new MXParser(); } @@ -45,7 +44,7 @@ public void setUp() { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P24_ibm24n01xml() throws IOException { + void testibm_not_wf_P24_ibm24n01xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P24/ibm24n01.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -68,7 +67,7 @@ public void testibm_not_wf_P24_ibm24n01xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P24_ibm24n02xml() throws IOException { + void testibm_not_wf_P24_ibm24n02xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P24/ibm24n02.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -90,7 +89,7 @@ public void testibm_not_wf_P24_ibm24n02xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P24_ibm24n03xml() throws IOException { + void testibm_not_wf_P24_ibm24n03xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P24/ibm24n03.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -112,7 +111,7 @@ public void testibm_not_wf_P24_ibm24n03xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P24_ibm24n04xml() throws IOException { + void testibm_not_wf_P24_ibm24n04xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P24/ibm24n04.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -134,7 +133,7 @@ public void testibm_not_wf_P24_ibm24n04xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P24_ibm24n05xml() throws IOException { + void testibm_not_wf_P24_ibm24n05xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P24/ibm24n05.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -156,7 +155,7 @@ public void testibm_not_wf_P24_ibm24n05xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P24_ibm24n06xml() throws IOException { + void testibm_not_wf_P24_ibm24n06xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P24/ibm24n06.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -177,7 +176,7 @@ public void testibm_not_wf_P24_ibm24n06xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P24_ibm24n07xml() throws IOException { + void testibm_not_wf_P24_ibm24n07xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P24/ibm24n07.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -198,7 +197,7 @@ public void testibm_not_wf_P24_ibm24n07xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P24_ibm24n08xml() throws IOException { + void testibm_not_wf_P24_ibm24n08xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P24/ibm24n08.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -220,7 +219,7 @@ public void testibm_not_wf_P24_ibm24n08xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P24_ibm24n09xml() throws IOException { + void testibm_not_wf_P24_ibm24n09xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P24/ibm24n09.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production2_Test.java b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production2_Test.java index 71a342a2..c4150edc 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production2_Test.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production2_Test.java @@ -12,11 +12,12 @@ import java.nio.file.Files; import java.nio.file.Paths; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Test class that execute a particular set of tests associated to a TESCASES tag from the XML W3C Conformance Tests. @@ -37,8 +38,8 @@ class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConfo /** *

setUp.

*/ - @Before - public void setUp() { + @BeforeEach + void setUp() { parser = new MXParser(); } @@ -52,7 +53,7 @@ public void setUp() { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n01xml() throws IOException { + void testibm_not_wf_P02_ibm02n01xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n01.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -73,7 +74,7 @@ public void testibm_not_wf_P02_ibm02n01xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n02xml() throws IOException { + void testibm_not_wf_P02_ibm02n02xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n02.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -94,7 +95,7 @@ public void testibm_not_wf_P02_ibm02n02xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n03xml() throws IOException { + void testibm_not_wf_P02_ibm02n03xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n03.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -115,7 +116,7 @@ public void testibm_not_wf_P02_ibm02n03xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n04xml() throws IOException { + void testibm_not_wf_P02_ibm02n04xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n04.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -136,7 +137,7 @@ public void testibm_not_wf_P02_ibm02n04xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n05xml() throws IOException { + void testibm_not_wf_P02_ibm02n05xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n05.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -157,7 +158,7 @@ public void testibm_not_wf_P02_ibm02n05xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n06xml() throws IOException { + void testibm_not_wf_P02_ibm02n06xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n06.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -178,7 +179,7 @@ public void testibm_not_wf_P02_ibm02n06xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n07xml() throws IOException { + void testibm_not_wf_P02_ibm02n07xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n07.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -199,7 +200,7 @@ public void testibm_not_wf_P02_ibm02n07xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n08xml() throws IOException { + void testibm_not_wf_P02_ibm02n08xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n08.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -220,7 +221,7 @@ public void testibm_not_wf_P02_ibm02n08xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n09xml() throws IOException { + void testibm_not_wf_P02_ibm02n09xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n09.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -241,7 +242,7 @@ public void testibm_not_wf_P02_ibm02n09xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n10xml() throws IOException { + void testibm_not_wf_P02_ibm02n10xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n10.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -262,7 +263,7 @@ public void testibm_not_wf_P02_ibm02n10xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n11xml() throws IOException { + void testibm_not_wf_P02_ibm02n11xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n11.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -283,7 +284,7 @@ public void testibm_not_wf_P02_ibm02n11xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n12xml() throws IOException { + void testibm_not_wf_P02_ibm02n12xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n12.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -304,7 +305,7 @@ public void testibm_not_wf_P02_ibm02n12xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n13xml() throws IOException { + void testibm_not_wf_P02_ibm02n13xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n13.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -325,7 +326,7 @@ public void testibm_not_wf_P02_ibm02n13xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n14xml() throws IOException { + void testibm_not_wf_P02_ibm02n14xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n14.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -346,7 +347,7 @@ public void testibm_not_wf_P02_ibm02n14xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n15xml() throws IOException { + void testibm_not_wf_P02_ibm02n15xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n15.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -367,7 +368,7 @@ public void testibm_not_wf_P02_ibm02n15xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n16xml() throws IOException { + void testibm_not_wf_P02_ibm02n16xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n16.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -388,7 +389,7 @@ public void testibm_not_wf_P02_ibm02n16xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n17xml() throws IOException { + void testibm_not_wf_P02_ibm02n17xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n17.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -409,7 +410,7 @@ public void testibm_not_wf_P02_ibm02n17xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n18xml() throws IOException { + void testibm_not_wf_P02_ibm02n18xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n18.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -430,7 +431,7 @@ public void testibm_not_wf_P02_ibm02n18xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n19xml() throws IOException { + void testibm_not_wf_P02_ibm02n19xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n19.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -451,7 +452,7 @@ public void testibm_not_wf_P02_ibm02n19xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n20xml() throws IOException { + void testibm_not_wf_P02_ibm02n20xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n20.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -472,7 +473,7 @@ public void testibm_not_wf_P02_ibm02n20xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n21xml() throws IOException { + void testibm_not_wf_P02_ibm02n21xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n21.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -493,7 +494,7 @@ public void testibm_not_wf_P02_ibm02n21xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n22xml() throws IOException { + void testibm_not_wf_P02_ibm02n22xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n22.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -514,7 +515,7 @@ public void testibm_not_wf_P02_ibm02n22xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n23xml() throws IOException { + void testibm_not_wf_P02_ibm02n23xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n23.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -535,7 +536,7 @@ public void testibm_not_wf_P02_ibm02n23xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n24xml() throws IOException { + void testibm_not_wf_P02_ibm02n24xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n24.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -556,7 +557,7 @@ public void testibm_not_wf_P02_ibm02n24xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n25xml() throws IOException { + void testibm_not_wf_P02_ibm02n25xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n25.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -577,7 +578,7 @@ public void testibm_not_wf_P02_ibm02n25xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n26xml() throws IOException { + void testibm_not_wf_P02_ibm02n26xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n26.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -598,7 +599,7 @@ public void testibm_not_wf_P02_ibm02n26xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n27xml() throws IOException { + void testibm_not_wf_P02_ibm02n27xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n27.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -619,7 +620,7 @@ public void testibm_not_wf_P02_ibm02n27xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n28xml() throws IOException { + void testibm_not_wf_P02_ibm02n28xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n28.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -640,7 +641,7 @@ public void testibm_not_wf_P02_ibm02n28xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n29xml() throws IOException { + void testibm_not_wf_P02_ibm02n29xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n29.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -662,7 +663,8 @@ public void testibm_not_wf_P02_ibm02n29xml() throws IOException { * * NOTE: This test file is malformed into the original test suite, so I skip it. */ - // @Test + @Test + @Disabled public void testibm_not_wf_P02_ibm02n30xml() throws IOException { try (BufferedReader reader = Files.newBufferedReader( Paths.get(testResourcesDir.getCanonicalPath(), "not-wf/P02/ibm02n30.xml"), @@ -687,7 +689,8 @@ public void testibm_not_wf_P02_ibm02n30xml() throws IOException { * * NOTE: This test file is malformed into the original test suite, so I skip it. */ - // @Test + @Test + @Disabled public void testibm_not_wf_P02_ibm02n31xml() throws IOException { try (FileInputStream is = new FileInputStream(new File(testResourcesDir, "not-wf/P02/ibm02n31.xml")); InputStreamReader reader = new InputStreamReader(is, "ISO-8859-15")) { @@ -710,7 +713,7 @@ public void testibm_not_wf_P02_ibm02n31xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n32xml() throws IOException { + void testibm_not_wf_P02_ibm02n32xml() throws IOException { try (FileInputStream is = new FileInputStream(new File(testResourcesDir, "not-wf/P02/ibm02n32.xml")); InputStreamReader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) { parser.setInput(reader); @@ -732,7 +735,7 @@ public void testibm_not_wf_P02_ibm02n32xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P02_ibm02n33xml() throws IOException { + void testibm_not_wf_P02_ibm02n33xml() throws IOException { try (FileInputStream is = new FileInputStream(new File(testResourcesDir, "not-wf/P02/ibm02n33.xml")); InputStreamReader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) { parser.setInput(reader); diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production32_Test.java b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production32_Test.java index 91effa9d..cfc2c532 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production32_Test.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production32_Test.java @@ -5,11 +5,12 @@ import java.io.IOException; import java.io.Reader; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Test class that execute a particular set of tests associated to a TESCASES tag from the XML W3C Conformance Tests. @@ -30,8 +31,8 @@ class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConfo /** *

setUp.

*/ - @Before - public void setUp() { + @BeforeEach + void setUp() { parser = new MXParser(); } @@ -45,7 +46,7 @@ public void setUp() { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P32_ibm32n01xml() throws IOException { + void testibm_not_wf_P32_ibm32n01xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P32/ibm32n01.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -67,7 +68,7 @@ public void testibm_not_wf_P32_ibm32n01xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P32_ibm32n02xml() throws IOException { + void testibm_not_wf_P32_ibm32n02xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P32/ibm32n02.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -89,7 +90,7 @@ public void testibm_not_wf_P32_ibm32n02xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P32_ibm32n03xml() throws IOException { + void testibm_not_wf_P32_ibm32n03xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P32/ibm32n03.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -110,7 +111,7 @@ public void testibm_not_wf_P32_ibm32n03xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P32_ibm32n04xml() throws IOException { + void testibm_not_wf_P32_ibm32n04xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P32/ibm32n04.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -131,7 +132,7 @@ public void testibm_not_wf_P32_ibm32n04xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P32_ibm32n05xml() throws IOException { + void testibm_not_wf_P32_ibm32n05xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P32/ibm32n05.xml"))) { parser.setInput(reader); @@ -153,7 +154,7 @@ public void testibm_not_wf_P32_ibm32n05xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P32_ibm32n06xml() throws IOException { + void testibm_not_wf_P32_ibm32n06xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P32/ibm32n06.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -174,7 +175,7 @@ public void testibm_not_wf_P32_ibm32n06xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P32_ibm32n07xml() throws IOException { + void testibm_not_wf_P32_ibm32n07xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P32/ibm32n07.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -195,7 +196,7 @@ public void testibm_not_wf_P32_ibm32n07xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P32_ibm32n08xml() throws IOException { + void testibm_not_wf_P32_ibm32n08xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P32/ibm32n08.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -218,7 +219,8 @@ public void testibm_not_wf_P32_ibm32n08xml() throws IOException { * * NOTE: This test is SKIPPED as MXParser does not support parsing inside DOCTYPEDECL. */ - // @Test + @Test + @Disabled public void testibm_not_wf_P32_ibm32n09xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P32/ibm32n09.xml"))) { parser.setInput(reader); diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production66_Test.java b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production66_Test.java index 3266b725..c08b1142 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production66_Test.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production66_Test.java @@ -6,11 +6,11 @@ import java.io.IOException; import java.io.Reader; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Test class that execute a particular set of tests associated to a TESCASES tag from the XML W3C Conformance Tests. @@ -21,7 +21,6 @@ * @version $Id: $Id * @since 3.4.0 */ -public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production66_Test { static final File testResourcesDir = new File("src/test/resources/", "xmlconf/ibm/"); @@ -31,8 +30,8 @@ class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConfo /** *

setUp.

*/ - @Before - public void setUp() { + @BeforeEach + void setUp() { parser = new MXParser(); } @@ -46,7 +45,7 @@ public void setUp() { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P66_ibm66n01xml() throws IOException { + void testibm_not_wf_P66_ibm66n01xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n01.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -68,7 +67,7 @@ public void testibm_not_wf_P66_ibm66n01xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P66_ibm66n02xml() throws IOException { + void testibm_not_wf_P66_ibm66n02xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n02.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -90,7 +89,7 @@ public void testibm_not_wf_P66_ibm66n02xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P66_ibm66n03xml() throws IOException { + void testibm_not_wf_P66_ibm66n03xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n03.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -112,7 +111,7 @@ public void testibm_not_wf_P66_ibm66n03xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P66_ibm66n04xml() throws IOException { + void testibm_not_wf_P66_ibm66n04xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n04.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -136,7 +135,7 @@ public void testibm_not_wf_P66_ibm66n04xml() throws IOException { * @throws org.codehaus.plexus.util.xml.pull.XmlPullParserException if any. */ @Test - public void testibm_not_wf_P66_ibm66n05xml() throws FileNotFoundException, IOException, XmlPullParserException { + void testibm_not_wf_P66_ibm66n05xml() throws FileNotFoundException, IOException, XmlPullParserException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n05.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -158,7 +157,7 @@ public void testibm_not_wf_P66_ibm66n05xml() throws FileNotFoundException, IOExc * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P66_ibm66n06xml() throws IOException { + void testibm_not_wf_P66_ibm66n06xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n06.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -180,7 +179,7 @@ public void testibm_not_wf_P66_ibm66n06xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P66_ibm66n07xml() throws IOException { + void testibm_not_wf_P66_ibm66n07xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n07.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -202,7 +201,7 @@ public void testibm_not_wf_P66_ibm66n07xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P66_ibm66n08xml() throws IOException { + void testibm_not_wf_P66_ibm66n08xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n08.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -224,7 +223,7 @@ public void testibm_not_wf_P66_ibm66n08xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P66_ibm66n09xml() throws IOException { + void testibm_not_wf_P66_ibm66n09xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n09.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -246,7 +245,7 @@ public void testibm_not_wf_P66_ibm66n09xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P66_ibm66n10xml() throws IOException { + void testibm_not_wf_P66_ibm66n10xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n10.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -268,7 +267,7 @@ public void testibm_not_wf_P66_ibm66n10xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P66_ibm66n11xml() throws IOException { + void testibm_not_wf_P66_ibm66n11xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n11.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -290,7 +289,7 @@ public void testibm_not_wf_P66_ibm66n11xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P66_ibm66n12xml() throws IOException { + void testibm_not_wf_P66_ibm66n12xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n12.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -312,7 +311,7 @@ public void testibm_not_wf_P66_ibm66n12xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P66_ibm66n13xml() throws IOException { + void testibm_not_wf_P66_ibm66n13xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n13.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -334,7 +333,7 @@ public void testibm_not_wf_P66_ibm66n13xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P66_ibm66n14xml() throws IOException { + void testibm_not_wf_P66_ibm66n14xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n14.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -356,7 +355,7 @@ public void testibm_not_wf_P66_ibm66n14xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P66_ibm66n15xml() throws IOException { + void testibm_not_wf_P66_ibm66n15xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P66/ibm66n15.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production80_Test.java b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production80_Test.java index 9b109a67..a2b2c165 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production80_Test.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production80_Test.java @@ -5,11 +5,11 @@ import java.io.IOException; import java.io.Reader; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Test class that execute a particular set of tests associated to a TESCASES tag from the XML W3C Conformance Tests. @@ -20,7 +20,6 @@ * @version $Id: $Id * @since 3.4.0 */ -public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production80_Test { static final File testResourcesDir = new File("src/test/resources/", "xmlconf/ibm/"); @@ -30,8 +29,8 @@ class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConfo /** *

setUp.

*/ - @Before - public void setUp() { + @BeforeEach + void setUp() { parser = new MXParser(); } @@ -45,7 +44,7 @@ public void setUp() { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P80_ibm80n01xml() throws IOException { + void testibm_not_wf_P80_ibm80n01xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P80/ibm80n01.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -67,7 +66,7 @@ public void testibm_not_wf_P80_ibm80n01xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P80_ibm80n02xml() throws IOException { + void testibm_not_wf_P80_ibm80n02xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P80/ibm80n02.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -89,7 +88,7 @@ public void testibm_not_wf_P80_ibm80n02xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P80_ibm80n03xml() throws IOException { + void testibm_not_wf_P80_ibm80n03xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P80/ibm80n03.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -112,7 +111,7 @@ public void testibm_not_wf_P80_ibm80n03xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P80_ibm80n04xml() throws IOException { + void testibm_not_wf_P80_ibm80n04xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P80/ibm80n04.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -134,7 +133,7 @@ public void testibm_not_wf_P80_ibm80n04xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P80_ibm80n05xml() throws IOException { + void testibm_not_wf_P80_ibm80n05xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P80/ibm80n05.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -156,7 +155,7 @@ public void testibm_not_wf_P80_ibm80n05xml() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testibm_not_wf_P80_ibm80n06xml() throws IOException { + void testibm_not_wf_P80_ibm80n06xml() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P80/ibm80n06.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java index f0f748fb..c74c28cc 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java @@ -27,12 +27,13 @@ import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.ReaderFactory; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** *

MXParserTest class.

@@ -41,14 +42,14 @@ * @version $Id: $Id * @since 3.4.0 */ -public class MXParserTest { +class MXParserTest { /** *

testHexadecimalEntities.

* * @throws java.lang.Exception if any. */ @Test - public void testHexadecimalEntities() throws Exception { + void hexadecimalEntities() throws Exception { MXParser parser = new MXParser(); parser.defineEntityReplacementText("test", "replacement"); @@ -72,7 +73,7 @@ public void testHexadecimalEntities() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testDecimalEntities() throws Exception { + void decimalEntities() throws Exception { MXParser parser = new MXParser(); parser.defineEntityReplacementText("test", "replacement"); @@ -96,7 +97,7 @@ public void testDecimalEntities() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testPredefinedEntities() throws Exception { + void predefinedEntities() throws Exception { MXParser parser = new MXParser(); parser.defineEntityReplacementText("test", "replacement"); @@ -121,7 +122,7 @@ public void testPredefinedEntities() throws Exception { * @throws java.io.IOException if any. */ @Test - public void testEntityReplacementMap() throws XmlPullParserException, IOException { + void entityReplacementMap() throws XmlPullParserException, IOException { EntityReplacementMap erm = new EntityReplacementMap(new String[][] {{"abc", "CDE"}, {"EFG", "HIJ"}}); MXParser parser = new MXParser(erm); @@ -140,7 +141,7 @@ public void testEntityReplacementMap() throws XmlPullParserException, IOExceptio * @throws java.lang.Exception if any. */ @Test - public void testCustomEntities() throws Exception { + void customEntities() throws Exception { MXParser parser = new MXParser(); String input = "&myentity;"; @@ -168,7 +169,7 @@ public void testCustomEntities() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testUnicodeEntities() throws Exception { + void unicodeEntities() throws Exception { MXParser parser = new MXParser(); String input = "𝟭"; parser.setInput(new StringReader(input)); @@ -194,7 +195,7 @@ public void testUnicodeEntities() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testInvalidCharacterReferenceHexa() throws Exception { + void invalidCharacterReferenceHexa() throws Exception { MXParser parser = new MXParser(); String input = ""; parser.setInput(new StringReader(input)); @@ -214,42 +215,42 @@ public void testInvalidCharacterReferenceHexa() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testValidCharacterReferenceHexa() throws Exception { + void validCharacterReferenceHexa() throws Exception { MXParser parser = new MXParser(); String input = " Ȁ퟿ᄁ�𐀀􏿽􏿿"; parser.setInput(new StringReader(input)); - try { - assertEquals(XmlPullParser.START_TAG, parser.nextToken()); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(0x9, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(0xA, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(0xD, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(0x20, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(0x200, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(0xD7FF, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(0xE000, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(0xFFA2, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(0xFFFD, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(0x10000, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(0x10FFFD, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(0x10FFFF, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.END_TAG, parser.nextToken()); - } catch (XmlPullParserException e) { - fail("Should success since the input represents all legal character references"); - } + Assertions.assertDoesNotThrow( + () -> { + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0x9, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0xA, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0xD, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0x20, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0x200, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0xD7FF, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0xE000, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0xFFA2, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0xFFFD, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0x10000, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0x10FFFD, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(0x10FFFF, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); + }, + "Should success since the input represents all legal character references"); } /** @@ -258,7 +259,7 @@ public void testValidCharacterReferenceHexa() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testInvalidCharacterReferenceDecimal() throws Exception { + void invalidCharacterReferenceDecimal() throws Exception { MXParser parser = new MXParser(); String input = ""; parser.setInput(new StringReader(input)); @@ -278,42 +279,42 @@ public void testInvalidCharacterReferenceDecimal() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testValidCharacterReferenceDecimal() throws Exception { + void validCharacterReferenceDecimal() throws Exception { MXParser parser = new MXParser(); String input = " Ȁ퟿ᄁ�𐀀􏿽􏿿"; parser.setInput(new StringReader(input)); - try { - assertEquals(XmlPullParser.START_TAG, parser.nextToken()); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(9, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(10, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(13, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(32, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(512, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(55295, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(57344, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(65442, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(65533, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(65536, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(1114109, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(1114111, parser.getText().codePointAt(0)); - assertEquals(XmlPullParser.END_TAG, parser.nextToken()); - } catch (XmlPullParserException e) { - fail("Should success since the input represents all legal character references"); - } + Assertions.assertDoesNotThrow( + () -> { + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(9, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(10, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(13, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(32, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(512, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(55295, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(57344, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(65442, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(65533, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(65536, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(1114109, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(1114111, parser.getText().codePointAt(0)); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); + }, + "Should success since the input represents all legal character references"); } /** @@ -322,7 +323,7 @@ public void testValidCharacterReferenceDecimal() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testParserPosition() throws Exception { + void parserPosition() throws Exception { String input = " \n \tnnn\n"; @@ -350,7 +351,7 @@ public void testParserPosition() throws Exception { } @Test - public void testProcessingInstruction() throws Exception { + void processingInstruction() throws Exception { String input = "nnn"; MXParser parser = new MXParser(); @@ -368,19 +369,16 @@ public void testProcessingInstruction() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testProcessingInstructionsContainingXml() throws Exception { - StringBuffer sb = new StringBuffer(); - - sb.append(""); - sb.append("\n"); - sb.append(" \n"); - sb.append(" \n"); - sb.append(" ?>\n"); - sb.append(""); + void processingInstructionsContainingXml() throws Exception { + String sb = "" + "\n" + + " \n" + + " \n" + + " ?>\n" + + ""; MXParser parser = new MXParser(); - parser.setInput(new StringReader(sb.toString())); + parser.setInput(new StringReader(sb)); assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken()); assertEquals(XmlPullParser.START_TAG, parser.nextToken()); @@ -396,16 +394,14 @@ public void testProcessingInstructionsContainingXml() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testMalformedProcessingInstructionsContainingXmlNoClosingQuestionMark() throws Exception { - StringBuffer sb = new StringBuffer(); - sb.append("\n"); - sb.append("\n"); - sb.append("\n"); - sb.append(" >\n"); + void malformedProcessingInstructionsContainingXmlNoClosingQuestionMark() throws Exception { + String sb = "\n" + "\n" + + "\n" + + " >\n"; MXParser parser = new MXParser(); - parser.setInput(new StringReader(sb.toString())); + parser.setInput(new StringReader(sb)); try { assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken()); @@ -423,17 +419,15 @@ public void testMalformedProcessingInstructionsContainingXmlNoClosingQuestionMar } @Test - public void testSubsequentProcessingInstructionShort() throws Exception { - StringBuffer sb = new StringBuffer(); + void subsequentProcessingInstructionShort() throws Exception { - sb.append(""); - sb.append(""); - sb.append(""); - sb.append(""); - sb.append(""); + String sb = "" + "" + + "" + + "" + + ""; MXParser parser = new MXParser(); - parser.setInput(new StringReader(sb.toString())); + parser.setInput(new StringReader(sb)); assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken()); assertEquals(XmlPullParser.START_TAG, parser.nextToken()); @@ -448,8 +442,8 @@ public void testSubsequentProcessingInstructionShort() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testSubsequentProcessingInstructionMoreThan8k() throws Exception { - StringBuffer sb = new StringBuffer(); + void subsequentProcessingInstructionMoreThan8k() throws Exception { + StringBuilder sb = new StringBuilder(); sb.append(""); sb.append(""); @@ -492,18 +486,17 @@ public void testSubsequentProcessingInstructionMoreThan8k() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testLargeText_NoOverflow() throws Exception { - StringBuffer sb = new StringBuffer(); - sb.append(""); - sb.append(""); - // Anything above 33,554,431 would fail without a fix for - // https://web.archive.org/web/20070831191548/http://www.extreme.indiana.edu/bugzilla/show_bug.cgi?id=228 - // with java.io.IOException: error reading input, returned 0 - sb.append(new String(new char[33554432])); - sb.append(""); + void largeTextNoOverflow() throws Exception { + String sb = "" + "" + + + // Anything above 33,554,431 would fail without a fix for + // https://web.archive.org/web/20070831191548/http://www.extreme.indiana.edu/bugzilla/show_bug.cgi?id=228 + // with java.io.IOException: error reading input, returned 0 + new String(new char[33554432]) + + ""; MXParser parser = new MXParser(); - parser.setInput(new StringReader(sb.toString())); + parser.setInput(new StringReader(sb)); assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken()); assertEquals(XmlPullParser.START_TAG, parser.nextToken()); @@ -517,7 +510,7 @@ public void testLargeText_NoOverflow() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testMalformedProcessingInstructionAfterTag() throws Exception { + void malformedProcessingInstructionAfterTag() throws Exception { MXParser parser = new MXParser(); String input = ""; @@ -543,7 +536,7 @@ public void testMalformedProcessingInstructionAfterTag() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testMalformedProcessingInstructionBeforeTag() throws Exception { + void malformedProcessingInstructionBeforeTag() throws Exception { MXParser parser = new MXParser(); String input = ""; @@ -569,14 +562,12 @@ public void testMalformedProcessingInstructionBeforeTag() throws Exception { * @throws java.lang.Exception if any. */ @Test - public void testMalformedProcessingInstructionSpaceBeforeName() throws Exception { + void malformedProcessingInstructionSpaceBeforeName() throws Exception { MXParser parser = new MXParser(); - StringBuilder sb = new StringBuilder(); - sb.append(""); - sb.append(""); + String sb = "" + ""; - parser.setInput(new StringReader(sb.toString())); + parser.setInput(new StringReader(sb)); try { assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.next()); @@ -599,14 +590,12 @@ public void testMalformedProcessingInstructionSpaceBeforeName() throws Exception * @throws java.lang.Exception if any. */ @Test - public void testMalformedProcessingInstructionNoClosingQuestionMark() throws Exception { + void malformedProcessingInstructionNoClosingQuestionMark() throws Exception { MXParser parser = new MXParser(); - StringBuilder sb = new StringBuilder(); - sb.append(""); - sb.append(""); + String sb = "" + ""; - parser.setInput(new StringReader(sb.toString())); + parser.setInput(new StringReader(sb)); try { assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.next()); @@ -628,14 +617,12 @@ public void testMalformedProcessingInstructionNoClosingQuestionMark() throws Exc * @throws java.lang.Exception if any. */ @Test - public void testSubsequentMalformedProcessingInstructionNoClosingQuestionMark() throws Exception { + void subsequentMalformedProcessingInstructionNoClosingQuestionMark() throws Exception { MXParser parser = new MXParser(); - StringBuilder sb = new StringBuilder(); - sb.append(""); - sb.append(""); + String sb = "" + ""; - parser.setInput(new StringReader(sb.toString())); + parser.setInput(new StringReader(sb)); try { assertEquals(XmlPullParser.START_TAG, parser.next()); @@ -657,13 +644,11 @@ public void testSubsequentMalformedProcessingInstructionNoClosingQuestionMark() * @throws java.lang.Exception if any. */ @Test - public void testSubsequentAbortedProcessingInstruction() throws Exception { + void subsequentAbortedProcessingInstruction() throws Exception { MXParser parser = new MXParser(); - StringBuilder sb = new StringBuilder(); - sb.append(""); - sb.append("" + ""); - sb.append("  

"; - try { - MXParser parser = new MXParser(); - parser.setInput(new StringReader(input)); - parser.defineEntityReplacementText("nbsp", " "); - - assertEquals(XmlPullParser.START_TAG, parser.nextToken()); - assertEquals("p", parser.getName()); - assertEquals(XmlPullParser.COMMENT, parser.nextToken()); - assertEquals(" a pagebreak: ", parser.getText()); - assertEquals(XmlPullParser.COMMENT, parser.nextToken()); - assertEquals(" PB ", parser.getText()); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals("\u00A0", parser.getText()); - assertEquals("#160", parser.getName()); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals(" ", parser.getText()); - assertEquals("nbsp", parser.getName()); - assertEquals(XmlPullParser.START_TAG, parser.nextToken()); - assertEquals("unknown", parser.getName()); - assertEquals(XmlPullParser.END_TAG, parser.nextToken()); - assertEquals("unknown", parser.getName()); - assertEquals(XmlPullParser.END_TAG, parser.nextToken()); - assertEquals("p", parser.getName()); - assertEquals(XmlPullParser.END_DOCUMENT, parser.nextToken()); - } catch (XmlPullParserException e) { - fail("should not raise exception: " + e); - } + Assertions.assertDoesNotThrow( + () -> { + MXParser parser = new MXParser(); + parser.setInput(new StringReader(input)); + parser.defineEntityReplacementText("nbsp", " "); + + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals("p", parser.getName()); + assertEquals(XmlPullParser.COMMENT, parser.nextToken()); + assertEquals(" a pagebreak: ", parser.getText()); + assertEquals(XmlPullParser.COMMENT, parser.nextToken()); + assertEquals(" PB ", parser.getText()); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals("\u00A0", parser.getText()); + assertEquals("#160", parser.getName()); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals(" ", parser.getText()); + assertEquals("nbsp", parser.getName()); + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals("unknown", parser.getName()); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); + assertEquals("unknown", parser.getName()); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); + assertEquals("p", parser.getName()); + assertEquals(XmlPullParser.END_DOCUMENT, parser.nextToken()); + }, + "should not raise exception: "); } /** @@ -1303,50 +1286,50 @@ public void testEntityReplacement() throws IOException { * @since 3.4.2 */ @Test - public void testReplacementInPCArrayWithShorterCharArray() throws IOException { + void replacementInPCArrayWithShorterCharArray() throws IOException { String input = "]>" + "

&&foo;&tritPos;

"; - try { - MXParser parser = new MXParser(); - parser.setInput(new StringReader(new String(input.getBytes(), "ISO-8859-1"))); - parser.defineEntityReplacementText("foo", "ř"); - parser.defineEntityReplacementText("tritPos", "𝟭"); - - assertEquals(XmlPullParser.DOCDECL, parser.nextToken()); - assertEquals(" test []", parser.getText()); - assertEquals(XmlPullParser.START_TAG, parser.nextToken()); - assertEquals("section", parser.getName()); - assertEquals(1, parser.getAttributeCount()); - assertEquals("name", parser.getAttributeName(0)); - assertEquals("&ř𝟭", parser.getAttributeValue(0)); - assertEquals(XmlPullParser.START_TAG, parser.nextToken()); - assertEquals("

", parser.getText()); - assertEquals("p", parser.getName()); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals("&", parser.getText()); - assertEquals("amp", parser.getName()); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals("ř", parser.getText()); - assertEquals("foo", parser.getName()); - assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); - assertEquals("𝟭", parser.getText()); - assertEquals("tritPos", parser.getName()); - assertEquals(XmlPullParser.END_TAG, parser.nextToken()); - assertEquals("p", parser.getName()); - assertEquals(XmlPullParser.END_TAG, parser.nextToken()); - assertEquals("section", parser.getName()); - assertEquals(XmlPullParser.END_DOCUMENT, parser.nextToken()); - } catch (XmlPullParserException e) { - fail("should not raise exception: " + e); - } + Assertions.assertDoesNotThrow( + () -> { + MXParser parser = new MXParser(); + parser.setInput(new StringReader(new String(input.getBytes(), "ISO-8859-1"))); + parser.defineEntityReplacementText("foo", "ř"); + parser.defineEntityReplacementText("tritPos", "𝟭"); + + assertEquals(XmlPullParser.DOCDECL, parser.nextToken()); + assertEquals(" test []", parser.getText()); + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals("section", parser.getName()); + assertEquals(1, parser.getAttributeCount()); + assertEquals("name", parser.getAttributeName(0)); + assertEquals("&ř𝟭", parser.getAttributeValue(0)); + assertEquals(XmlPullParser.START_TAG, parser.nextToken()); + assertEquals("

", parser.getText()); + assertEquals("p", parser.getName()); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals("&", parser.getText()); + assertEquals("amp", parser.getName()); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals("ř", parser.getText()); + assertEquals("foo", parser.getName()); + assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken()); + assertEquals("𝟭", parser.getText()); + assertEquals("tritPos", parser.getName()); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); + assertEquals("p", parser.getName()); + assertEquals(XmlPullParser.END_TAG, parser.nextToken()); + assertEquals("section", parser.getName()); + assertEquals(XmlPullParser.END_DOCUMENT, parser.nextToken()); + }, + "should not raise exception: "); } /** * Ensures emoji can be parsed correctly */ @Test - public void testUnicode() throws IOException { + void unicode() throws IOException { String input = ""; try { diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test.java b/src/test/java/org/codehaus/plexus/util/xml/pull/eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test.java index 2ae6de39..56cef5e8 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test.java @@ -8,11 +8,12 @@ import java.io.Reader; import java.nio.charset.StandardCharsets; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Test class that execute a particular set of tests associated to a TESCASES tag from the XML W3C Conformance Tests. @@ -32,8 +33,8 @@ public class eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test { /** *

setUp.

*/ - @Before - public void setUp() { + @BeforeEach + void setUp() { parser = new MXParser(); } @@ -47,7 +48,7 @@ public void setUp() { * @throws java.io.IOException if there is an I/O error */ @Test - public void testhst_bh_001() throws IOException { + void testhst_bh_001() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "001.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -68,7 +69,7 @@ public void testhst_bh_001() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testhst_bh_002() throws IOException { + void testhst_bh_002() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "002.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -89,7 +90,7 @@ public void testhst_bh_002() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testhst_bh_003() throws IOException { + void testhst_bh_003() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "003.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -110,7 +111,7 @@ public void testhst_bh_003() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testhst_bh_004() throws IOException { + void testhst_bh_004() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "004.xml"))) { parser.setInput(reader); while (parser.nextToken() != XmlPullParser.END_DOCUMENT) @@ -133,7 +134,8 @@ public void testhst_bh_004() throws IOException { * * NOTE: This test is SKIPPED as MXParser do not supports DOCDECL parsing. */ - // @Test + @Test + @Disabled public void testhst_bh_005() throws IOException { try (Reader reader = new FileReader(new File(testResourcesDir, "005.xml"))) { parser.setInput(reader); @@ -178,7 +180,7 @@ public void testhst_bh_006() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testhst_lhs_007() throws IOException { + void testhst_lhs_007() throws IOException { try (FileInputStream is = new FileInputStream(new File(testResourcesDir, "007.xml")); InputStreamReader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) { parser.setInput(reader); @@ -200,7 +202,7 @@ public void testhst_lhs_007() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testhst_lhs_008() throws IOException { + void testhst_lhs_008() throws IOException { try (FileInputStream is = new FileInputStream(new File(testResourcesDir, "008.xml")); InputStreamReader reader = new InputStreamReader(is, StandardCharsets.UTF_16)) { parser.setInput(reader); @@ -222,7 +224,7 @@ public void testhst_lhs_008() throws IOException { * @throws java.io.IOException if there is an I/O error */ @Test - public void testhst_lhs_009() throws IOException { + void testhst_lhs_009() throws IOException { try (FileInputStream is = new FileInputStream(new File(testResourcesDir, "009.xml")); InputStreamReader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) { parser.setInput(reader);