diff --git a/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java b/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java index 4419f212..953576ef 100644 --- a/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java @@ -41,7 +41,7 @@ class CollectionUtilsTest { */ @Test void mergeMaps() { - Map dominantMap = new HashMap(); + Map dominantMap = new HashMap<>(); dominantMap.put("a", "a"); dominantMap.put("b", "b"); dominantMap.put("c", "c"); @@ -49,7 +49,7 @@ void mergeMaps() { 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 @@ void mergeMaps() { 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")); @@ -86,7 +86,7 @@ void mergeMapArray() { 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 @@ void mergeMapArray() { 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 @@ void mergeMapArray() { 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"); @@ -175,18 +175,18 @@ void mavenPropertiesLoading() { }); // 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")); } /** @@ -194,7 +194,7 @@ void mavenPropertiesLoading() { */ @Test void iteratorToListWithAPopulatedList() { - List original = new ArrayList(); + List original = new ArrayList<>(); original.add("en"); original.add("to"); @@ -216,7 +216,7 @@ void iteratorToListWithAPopulatedList() { */ @Test void iteratorToListWithAEmptyList() { - List original = new ArrayList(); + 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 ed4e0471..340964f3 100644 --- a/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java +++ b/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java @@ -551,7 +551,7 @@ void doNotScanUnnecesaryDirectories() 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 @@ -570,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); } @@ -626,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); @@ -635,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/FileBasedTestCase.java b/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java index d47e3ac2..988ed2c3 100644 --- a/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java +++ b/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java @@ -67,14 +67,9 @@ protected byte[] createFile(final File file, final long size) throws IOException byte[] data = generateTestData(size); - final BufferedOutputStream output = new BufferedOutputStream(Files.newOutputStream(file.toPath())); - - try { + try (BufferedOutputStream output = new BufferedOutputStream(Files.newOutputStream(file.toPath()))) { output.write(data); - return data; - } finally { - output.close(); } } diff --git a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java index ed51f99a..839477c0 100644 --- a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java @@ -26,6 +26,7 @@ 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; @@ -227,7 +228,7 @@ void mkdir() { File winFile = new File(getTestDirectory(), "bla*bla"); winFile.deleteOnExit(); FileUtils.mkdir(winFile.getAbsolutePath()); - assertTrue(false); + fail(); } catch (IllegalArgumentException e) { assertTrue(true); } @@ -307,12 +308,9 @@ void copyURLToFile() throws Exception { FileUtils.copyURLToFile(getClass().getResource(resourceName), file); // Tests that resource was copied correctly - final InputStream fis = Files.newInputStream(file.toPath()); - try { + try (InputStream fis = Files.newInputStream(file.toPath())) { assertTrue( IOUtil.contentEquals(getClass().getResourceAsStream(resourceName), fis), "Content is not equal."); - } finally { - fis.close(); } } @@ -367,7 +365,7 @@ void forceMkdir() throws Exception { File winFile = new File(getTestDirectory(), "bla*bla"); winFile.deleteOnExit(); FileUtils.forceMkdir(winFile); - assertTrue(false); + fail(); } catch (IllegalArgumentException e) { assertTrue(true); } @@ -883,9 +881,9 @@ void getExtensionWithPaths() { 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", ""} @@ -1410,14 +1408,14 @@ void deleteLongPathOnWindows() 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); diff --git a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java index 8a9dff50..a11c2020 100644 --- a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java @@ -26,16 +26,11 @@ import java.io.Reader; import java.io.Writer; import java.nio.file.Files; -import java.util.Arrays; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.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; +import static org.junit.jupiter.api.Assertions.*; /** * This is used to test IOUtil for correctness. The following checks are performed: @@ -104,19 +99,18 @@ private void createFile(File file, long size) throws IOException { /** Assert that the contents of two byte arrays are the same. */ private void assertEqualContent(byte[] b0, byte[] b1) { - assertTrue(Arrays.equals(b0, b1), "Content not equal according to java.util.Arrays#equals()"); + assertArrayEquals(b0, b1, "Content not equal according to java.util.Arrays#equals()"); } /** Assert that the content of two files is the same. */ 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); @@ -125,11 +119,8 @@ private void assertEqualContent(File f0, File f1) throws IOException { "The files " + f0 + " and " + f1 + " have differing number of bytes available (" + n0 + " vs " + n1 + ")"); - assertTrue(Arrays.equals(buf0, buf1), "The files " + f0 + " and " + f1 + " have different content"); + assertArrayEquals(buf0, buf1, "The files " + f0 + " and " + f1 + " have different content"); } - } finally { - is0.close(); - is1.close(); } } diff --git a/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java b/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java index 20b5bcda..a8f86410 100644 --- a/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java +++ b/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java @@ -43,7 +43,7 @@ class InterpolationFilterReaderTest { */ @Test void shouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Exception { - Map m = new HashMap(); + Map m = new HashMap<>(); m.put("test", "TestValue"); String testStr = "This is a ${test"; @@ -61,7 +61,7 @@ void shouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Excep */ @Test void shouldNotInterpolateExpressionWithMissingEndToken() throws Exception { - Map m = new HashMap(); + Map m = new HashMap<>(); m.put("test", "TestValue"); String testStr = "This is a ${test, really"; @@ -76,7 +76,7 @@ void shouldNotInterpolateExpressionWithMissingEndToken() throws Exception { */ @Test void shouldNotInterpolateWithMalformedStartToken() throws Exception { - Map m = new HashMap(); + Map m = new HashMap<>(); m.put("test", "testValue"); String foo = "This is a $!test} again"; @@ -91,7 +91,7 @@ void shouldNotInterpolateWithMalformedStartToken() throws Exception { */ @Test void shouldNotInterpolateWithMalformedEndToken() throws Exception { - Map m = new HashMap(); + Map m = new HashMap<>(); m.put("test", "testValue"); String foo = "This is a ${test!} again"; @@ -106,7 +106,7 @@ void shouldNotInterpolateWithMalformedEndToken() throws Exception { */ @Test void interpolationWithMulticharDelimiters() throws Exception { - Map m = new HashMap(); + Map m = new HashMap<>(); m.put("test", "testValue"); String foo = "This is a ${test$} again"; @@ -121,7 +121,7 @@ void interpolationWithMulticharDelimiters() throws Exception { */ @Test void defaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { - Map m = new HashMap(); + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -137,7 +137,7 @@ void defaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { */ @Test void defaultInterpolationWithInterpolatedValueAtEnd() throws Exception { - Map m = new HashMap(); + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -153,7 +153,7 @@ void defaultInterpolationWithInterpolatedValueAtEnd() throws Exception { */ @Test void interpolationWithSpecifiedBoundaryTokens() throws Exception { - Map m = new HashMap(); + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -169,7 +169,7 @@ void interpolationWithSpecifiedBoundaryTokens() throws Exception { */ @Test void interpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd() throws Exception { - Map m = new HashMap(); + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -185,7 +185,7 @@ void interpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd() thr */ @Test void interpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd() throws Exception { - Map m = new HashMap(); + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); @@ -201,7 +201,7 @@ void interpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd() throws */ @Test void interpolationWithSpecifiedBoundaryTokensAndAdditionalTokenCharacter() throws Exception { - Map m = new HashMap(); + 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 44253fb3..612d41a8 100644 --- a/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java +++ b/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java @@ -78,7 +78,7 @@ void defaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { } private Map getStandardMap() { - Map m = new HashMap(); + Map m = new HashMap<>(); m.put("name", "jason"); m.put("noun", "asshole"); return m; diff --git a/src/test/java/org/codehaus/plexus/util/PerfTest.java b/src/test/java/org/codehaus/plexus/util/PerfTest.java index 235ccb8c..b59c34ef 100644 --- a/src/test/java/org/codehaus/plexus/util/PerfTest.java +++ b/src/test/java/org/codehaus/plexus/util/PerfTest.java @@ -23,7 +23,7 @@ void subString() { 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(); diff --git a/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java b/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java index 9817a75a..527f7d1a 100644 --- a/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java @@ -32,7 +32,7 @@ * @since 3.4.0 */ public final class ReflectionUtilsTest { - public ReflectionUtilsTestClass testClass = new ReflectionUtilsTestClass(); + private final ReflectionUtilsTestClass testClass = new ReflectionUtilsTestClass(); /** *

testSimpleVariableAccess.

@@ -41,7 +41,7 @@ public final class ReflectionUtilsTest { */ @Test void simpleVariableAccess() throws IllegalAccessException { - assertEquals("woohoo", (String) ReflectionUtils.getValueIncludingSuperclasses("myString", testClass)); + assertEquals("woohoo", ReflectionUtils.getValueIncludingSuperclasses("myString", testClass)); } /** @@ -55,8 +55,8 @@ void complexVariableAccess() throws IllegalAccessException { 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")); } /** @@ -66,7 +66,7 @@ void complexVariableAccess() throws IllegalAccessException { */ @Test void superClassVariableAccess() throws IllegalAccessException { - assertEquals("super-duper", (String) ReflectionUtils.getValueIncludingSuperclasses("mySuperString", testClass)); + assertEquals("super-duper", ReflectionUtils.getValueIncludingSuperclasses("mySuperString", testClass)); } /** @@ -78,12 +78,12 @@ void superClassVariableAccess() 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/StringUtilsTest.java b/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java index 25a67203..8640fa45 100644 --- a/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java @@ -17,14 +17,12 @@ */ import java.util.Arrays; +import java.util.Collections; import java.util.Locale; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Test string utils. @@ -160,8 +158,8 @@ void removeAndHumpTurkish() { */ @Test void quoteEscapeEmbeddedSingleQuotes() { - String src = "This \'is a\' test"; - String check = "\'This \\\'is a\\\' test\'"; + String src = "This 'is a' test"; + String check = "'This \\'is a\\' test'"; char[] escaped = {'\'', '\"'}; String result = StringUtils.quoteAndEscape(src, '\'', escaped, '\\', false); @@ -174,8 +172,8 @@ void quoteEscapeEmbeddedSingleQuotes() { */ @Test void quoteEscapeEmbeddedSingleQuotesWithPattern() { - String src = "This \'is a\' test"; - String check = "\'This pre'postis apre'post test\'"; + 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); @@ -189,7 +187,7 @@ void quoteEscapeEmbeddedSingleQuotesWithPattern() { @Test 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); @@ -216,7 +214,7 @@ void quoteDontQuoteIfUnneeded() { @Test 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); @@ -229,7 +227,7 @@ void quoteWrapWithSingleQuotes() { */ @Test void quotePreserveExistingQuotes() { - String src = "\'This is a test\'"; + String src = "'This is a test'"; char[] escaped = {'\'', '\"'}; String result = StringUtils.quoteAndEscape(src, '\'', escaped, '\\', false); @@ -242,8 +240,8 @@ void quotePreserveExistingQuotes() { */ @Test void quoteWrapExistingQuotesWhenForceIsTrue() { - String src = "\'This is a test\'"; - String check = "\'\\\'This is a test\\\'\'"; + String src = "'This is a test'"; + String check = "'\\'This is a test\\''"; char[] escaped = {'\'', '\"'}; String result = StringUtils.quoteAndEscape(src, '\'', escaped, '\\', true); @@ -256,7 +254,7 @@ void quoteWrapExistingQuotesWhenForceIsTrue() { */ @Test void quoteShortVersionSingleQuotesPreserved() { - String src = "\'This is a test\'"; + String src = "'This is a test'"; String result = StringUtils.quoteAndEscape(src, '\''); @@ -272,27 +270,27 @@ void split() { 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)); } /** @@ -323,7 +321,7 @@ void unifyLineSeparators() throws Exception { try { StringUtils.unifyLineSeparators(s, "abs"); - assertTrue(false, "Exception NOT catched"); + fail("Exception NOT catched"); } catch (IllegalArgumentException e) { assertTrue(true, "Exception catched"); } diff --git a/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java b/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java index 37805e0a..46267a46 100644 --- a/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java +++ b/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java @@ -144,7 +144,7 @@ void tearDown() throws Exception { } 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 03b31636..41514a1c 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java @@ -52,10 +52,10 @@ void quoteArguments() { assertEquals("\"Hello World\"", result); result = CommandLineUtils.quote("\"Hello World\""); System.out.println(result); - assertEquals("\'\"Hello World\"\'", result); + assertEquals("'\"Hello World\"'", result); }); try { - CommandLineUtils.quote("\"Hello \'World\'\'"); + CommandLineUtils.quote("\"Hello 'World''"); fail(); } catch (Exception e) { } 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 804c5c50..3d39ed01 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java @@ -234,7 +234,7 @@ void getShellCommandLineBash() throws Exception { assertEquals("-c", shellCommandline[1]); String expectedShellCmd = "'/bin/echo' 'hello world'"; if (Os.isFamily(Os.FAMILY_WINDOWS)) { - expectedShellCmd = "'\\bin\\echo' \'hello world\'"; + expectedShellCmd = "'\\bin\\echo' 'hello world'"; } assertEquals(expectedShellCmd, shellCommandline[2]); } @@ -275,7 +275,7 @@ void getShellCommandLineBashWithWorkingDirectory() 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(); @@ -418,7 +418,7 @@ void quotedPathWithQuotationMarkAndApostrophe() throws Exception { */ @Test void onlyQuotedPath() throws Exception { - File dir = new File(System.getProperty("basedir"), "target/test/quotedpath\'test"); + File dir = new File(System.getProperty("basedir"), "target/test/quotedpath'test"); File javaHome = new File(System.getProperty("java.home")); File java; @@ -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/StreamPumperTest.java b/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java index ef916648..f3887a0c 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java @@ -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 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 f45ab268..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 @@ -89,7 +89,7 @@ void quoteWorkingDirectoryAndExecutableWDPathWithSingleQuotesBackslashFileSep() 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); } /** @@ -102,7 +102,7 @@ void preserveSingleQuotesOnArgument() { sh.setWorkingDirectory("/usr/bin"); sh.setExecutable("chmod"); - String[] args = {"\'some arg with spaces\'"}; + String[] args = {"'some arg with spaces'"}; List shellCommandLine = sh.getShellCommandLine(args); @@ -127,7 +127,7 @@ void addSingleQuotesOnArgumentWithSpaces() { String cli = StringUtils.join(shellCommandLine.iterator(), " "); System.out.println(cli); - assertTrue(cli.endsWith("\'" + args[0] + "\'")); + assertTrue(cli.endsWith("'" + args[0] + "'")); } /** @@ -169,7 +169,7 @@ void argumentsWithsemicolon() { 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"); 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 89b67224..97ddfcec 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java @@ -36,7 +36,7 @@ class CycleDetectedExceptionTest { */ @Test void exception() { - final List cycle = new ArrayList(); + 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 aeaa86ee..e900ca83 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java @@ -129,13 +129,13 @@ void cycyleDetection() { assertNotNull(cycle, "Cycle should be not null"); - assertEquals("a", (String) cycle.get(0), "Cycle contains 'a'"); + assertEquals("a", cycle.get(0), "Cycle contains 'a'"); assertEquals("b", cycle.get(1), "Cycle contains 'b'"); assertEquals("c", cycle.get(2), "Cycle contains 'c'"); - assertEquals("a", (String) cycle.get(3), "Cycle contains 'a'"); + assertEquals("a", cycle.get(3), "Cycle contains 'a'"); } // f --> g --> h @@ -175,15 +175,15 @@ void cycyleDetection() { assertEquals(5, cycle.size(), "Cycle contains 5 elements"); - assertEquals("b", (String) cycle.get(0), "Cycle contains 'b'"); + assertEquals("b", cycle.get(0), "Cycle contains 'b'"); assertEquals("c", cycle.get(1), "Cycle contains 'c'"); assertEquals("d", cycle.get(2), "Cycle contains 'd'"); - assertEquals("e", (String) cycle.get(3), "Cycle contains 'e'"); + assertEquals("e", cycle.get(3), "Cycle contains 'e'"); - assertEquals("b", (String) cycle.get(4), "Cycle contains 'b'"); + assertEquals("b", cycle.get(4), "Cycle contains 'b'"); assertTrue(dag5.hasEdge("a", "b"), "Edge exists"); diff --git a/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java b/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java index 91c3b1d0..02bd14cd 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java @@ -47,7 +47,7 @@ void dfs() throws CycleDetectedException { dag1.addEdge("b", "c"); - final List expected1 = new ArrayList(); + final List expected1 = new ArrayList<>(); expected1.add("c"); @@ -75,7 +75,7 @@ void dfs() throws CycleDetectedException { dag2.addEdge("c", "b"); - final List expected2 = new ArrayList(); + final List expected2 = new ArrayList<>(); expected2.add("a"); @@ -124,7 +124,7 @@ void dfs() throws CycleDetectedException { dag3.addEdge("f", "g"); - final List expected3 = new ArrayList(); + final List expected3 = new ArrayList<>(); expected3.add("d"); @@ -179,7 +179,7 @@ void dfs() throws CycleDetectedException { dag4.addEdge("e", "f"); - final List expected4 = new ArrayList(); + final List expected4 = new ArrayList<>(); expected4.add("d"); diff --git a/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java b/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java index 0b1fb1a3..927d3e52 100644 --- a/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java +++ b/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java @@ -172,7 +172,7 @@ void valueExtractorWithAInvalidExpression() throws Exception { */ @Test void mappedDottedKey() throws Exception { - Map map = new HashMap(); + 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,9 +185,9 @@ void mappedDottedKey() throws Exception { */ @Test void indexedMapped() throws Exception { - Map map = new HashMap(); + 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,9 +200,9 @@ void indexedMapped() throws Exception { */ @Test void mappedIndexed() throws Exception { - List list = new ArrayList(); + 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,7 +214,7 @@ void mappedIndexed() throws Exception { */ @Test void mappedMissingDot() throws Exception { - Map map = new HashMap(); + Map map = new HashMap<>(); map.put("a", new ValueHolder("a-value")); assertNull(ReflectionValueExtractor.evaluate("h.value(a)value", new ValueHolder(map))); } @@ -226,7 +226,7 @@ void mappedMissingDot() throws Exception { */ @Test void indexedMissingDot() throws Exception { - List list = new ArrayList(); + List list = new ArrayList<>(); list.add(new ValueHolder("a-value")); assertNull(ReflectionValueExtractor.evaluate("h.value[0]value", new ValueHolder(list))); } @@ -248,7 +248,7 @@ void dotDot() throws Exception { */ @Test void badIndexedSyntax() throws Exception { - List list = new ArrayList(); + List list = new ArrayList<>(); list.add("a-value"); Object value = new ValueHolder(list); @@ -267,7 +267,7 @@ void badIndexedSyntax() throws Exception { */ @Test void badMappedSyntax() throws Exception { - Map map = new HashMap(); + Map map = new HashMap<>(); map.put("a", "a-value"); Object value = new ValueHolder(map); @@ -412,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) { 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 bb327865..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,6 +22,7 @@ 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; @@ -178,12 +179,10 @@ void issue51DetectJava7ConcatenationBug() throws IOException { 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 @@ void issue51DetectJava7ConcatenationBug() 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/XmlWriterUtilTest.java b/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java index 15c56cb8..bc490e33 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java @@ -134,10 +134,9 @@ void writeLineBreakXMLWriterIntIntInt() 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()); + String sb = + "" + XmlWriterUtil.LS; + assertEquals(output.toString(), sb); assertEquals(output.toString().length(), XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + XmlWriterUtil.LS.length()); } @@ -151,14 +150,14 @@ void writeCommentLineBreakXMLWriter() 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(), "" + XmlWriterUtil.LS, output.toString()); + assertEquals("" + XmlWriterUtil.LS, output.toString(), output.toString()); } /** @@ -171,7 +170,7 @@ void writeCommentLineBreakXMLWriterInt() 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()); @@ -183,7 +182,7 @@ void writeCommentXMLWriterString() throws Exception { XmlWriterUtil.writeComment( xmlWriter, "hellooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"); writer.close(); - sb = new StringBuffer(); + sb = new StringBuilder(); sb.append("") .append(XmlWriterUtil.LS); assertEquals(output.toString(), sb.toString()); @@ -194,7 +193,7 @@ void writeCommentXMLWriterString() throws Exception { XmlWriterUtil.writeComment(xmlWriter, "hello\nworld"); writer.close(); - sb = new StringBuffer(); + sb = new StringBuilder(); sb.append("") .append(XmlWriterUtil.LS); sb.append("") @@ -216,7 +215,7 @@ void writeCommentXMLWriterStringInt() throws Exception { XmlWriterUtil.writeComment(xmlWriter, "hello", 2); writer.close(); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append(indent); sb.append("") .append(XmlWriterUtil.LS); @@ -233,7 +232,7 @@ void writeCommentXMLWriterStringInt() throws Exception { XmlWriterUtil.writeComment(xmlWriter, "hello\nworld", 2); writer.close(); - sb = new StringBuffer(); + sb = new StringBuilder(); sb.append(indent); sb.append("") .append(XmlWriterUtil.LS); @@ -258,7 +257,7 @@ void writeCommentXMLWriterStringIntInt() throws Exception { XmlWriterUtil.writeComment(xmlWriter, "hello", 2, 4); writer.close(); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append(repeat); sb.append("") .append(XmlWriterUtil.LS); @@ -271,7 +270,7 @@ void writeCommentXMLWriterStringIntInt() throws Exception { XmlWriterUtil.writeComment(xmlWriter, "hello\nworld", 2, 4); writer.close(); - sb = new StringBuffer(); + sb = new StringBuilder(); sb.append(repeat); sb.append("") .append(XmlWriterUtil.LS); @@ -296,7 +295,7 @@ void writeCommentXMLWriterStringIntIntInt() throws Exception { 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()); @@ -307,7 +306,7 @@ void writeCommentXMLWriterStringIntIntInt() throws Exception { 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()); @@ -324,7 +323,7 @@ void writeCommentXMLWriterStringIntIntInt() 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); @@ -348,7 +347,7 @@ void writeCommentTextXMLWriterStringInt() throws Exception { + "loooooooooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnnnong line", 2); writer.close(); - sb = new StringBuffer(); + sb = new StringBuilder(); sb.append(XmlWriterUtil.LS); sb.append(indent) .append("") @@ -385,20 +384,18 @@ void writeCommentTextXMLWriterStringIntInt() throws Exception { 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()); + 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()); @@ -416,20 +413,18 @@ void writeCommentTextXMLWriterStringIntIntInt() throws Exception { 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()); + 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()); @@ -445,10 +440,9 @@ void writeCommentTextXMLWriterStringIntIntInt() 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); } /** @@ -461,10 +455,9 @@ void writeCommentNull() 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); } /** @@ -481,15 +474,13 @@ void writeCommentLong() throws Exception { + "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 41467c48..36a91ca5 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java @@ -184,11 +184,8 @@ void escapingInAttributes() throws IOException, XmlPullParserException { */ @Test void inputLocationTracking() 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 - } - }; + // 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(expectedDom.getInputLocation(), dom.getInputLocation(), "root input location"); @@ -206,40 +203,31 @@ public Object toInputLocation(XmlPullParser parser) { } 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; } // @@ -247,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 d0d84c36..33cd5057 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java @@ -217,7 +217,7 @@ void equals() { assertEquals(dom, dom); assertNotEquals(null, dom); - assertNotEquals(dom, new Xpp3Dom((String) null)); + assertNotEquals(new Xpp3Dom((String) null), dom); } /** @@ -233,7 +233,7 @@ void equalsIsNullSafe() throws XmlPullParserException, IOException { 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(); 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 f3f33755..9d28efc5 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomWriterTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomWriterTest.java @@ -30,7 +30,7 @@ * @since 3.4.0 */ class Xpp3DomWriterTest { - private static final String LS = System.getProperty("line.separator"); + private static final String LS = System.lineSeparator(); /** *

testWriter.

@@ -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_Production2_Test.java b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production2_Test.java index 43279b83..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 @@ -13,6 +13,7 @@ import java.nio.file.Paths; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -662,7 +663,8 @@ 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")) { 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 cda5f99e..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 @@ -6,6 +6,7 @@ import java.io.Reader; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -218,7 +219,8 @@ 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/MXParserTest.java b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java index 13adda0c..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 @@ -370,18 +370,15 @@ void processingInstruction() throws Exception { */ @Test void processingInstructionsContainingXml() throws Exception { - StringBuffer sb = new StringBuffer(); - - sb.append(""); - sb.append("\n"); - sb.append(" \n"); - sb.append(" \n"); - sb.append(" ?>\n"); - sb.append(""); + 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()); @@ -398,15 +395,13 @@ void processingInstructionsContainingXml() throws Exception { */ @Test void malformedProcessingInstructionsContainingXmlNoClosingQuestionMark() throws Exception { - StringBuffer sb = new StringBuffer(); - sb.append("\n"); - sb.append("\n"); - sb.append("\n"); - sb.append(" >\n"); + 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()); @@ -425,16 +420,14 @@ void malformedProcessingInstructionsContainingXmlNoClosingQuestionMark() throws @Test void subsequentProcessingInstructionShort() throws Exception { - StringBuffer sb = new StringBuffer(); - 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()); @@ -450,7 +443,7 @@ void subsequentProcessingInstructionShort() throws Exception { */ @Test void subsequentProcessingInstructionMoreThan8k() throws Exception { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append(""); sb.append(""); @@ -494,17 +487,16 @@ void subsequentProcessingInstructionMoreThan8k() throws Exception { */ @Test void largeTextNoOverflow() 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(""); + 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()); @@ -573,11 +565,9 @@ void malformedProcessingInstructionBeforeTag() 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()); @@ -603,11 +593,9 @@ void malformedProcessingInstructionSpaceBeforeName() 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()); @@ -632,11 +620,9 @@ void malformedProcessingInstructionNoClosingQuestionMark() 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()); @@ -660,11 +646,9 @@ void subsequentMalformedProcessingInstructionNoClosingQuestionMark() throws Exce @Test void subsequentAbortedProcessingInstruction() throws Exception { MXParser parser = new MXParser(); - StringBuilder sb = new StringBuilder(); - sb.append(""); - sb.append("" + ""); - sb.append("