From 4fcb7175941bf4bf7f227569da0aab0e1b01fb12 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 16 Jul 2020 07:20:16 -0400 Subject: [PATCH] replace deprecated methods --- ...nterpolatorFilterReaderLineEndingTest.java | 37 ++++++++++--------- .../filtering/DefaultMavenFileFilterTest.java | 19 ++++++---- .../DefaultMavenReaderFilterTest.java | 10 ++--- .../DefaultMavenResourcesFilteringTest.java | 6 +-- .../shared/filtering/EscapeStringTest.java | 5 ++- 5 files changed, 41 insertions(+), 36 deletions(-) diff --git a/src/test/java/org/apache/maven/shared/filtering/AbstractInterpolatorFilterReaderLineEndingTest.java b/src/test/java/org/apache/maven/shared/filtering/AbstractInterpolatorFilterReaderLineEndingTest.java index 82e7bba..1e25c78 100644 --- a/src/test/java/org/apache/maven/shared/filtering/AbstractInterpolatorFilterReaderLineEndingTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/AbstractInterpolatorFilterReaderLineEndingTest.java @@ -24,12 +24,13 @@ import static org.mockito.Matchers.isA; import static org.mockito.Mockito.when; +import java.io.IOException; import java.io.Reader; import java.io.StringReader; +import org.apache.commons.io.IOUtils; import org.codehaus.plexus.interpolation.Interpolator; import org.codehaus.plexus.interpolation.RecursionInterceptor; -import org.codehaus.plexus.util.IOUtil; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -55,39 +56,39 @@ public void testDefaults() Reader in = new StringReader( "text without expression" ); Reader reader = getDollarBracesReader( in, interpolator, "\\" ); - assertEquals( "text without expression", IOUtil.toString( reader ) ); + assertEquals( "text without expression", IOUtils.toString( reader ) ); in = new StringReader( "valid expression ${a}" ); reader = getDollarBracesReader( in, interpolator, null ); - assertEquals( "valid expression DONE_A", IOUtil.toString( reader ) ); + assertEquals( "valid expression DONE_A", IOUtils.toString( reader ) ); in = new StringReader( "empty expression ${}" ); reader = getDollarBracesReader( in, interpolator, null ); - assertEquals( "empty expression ${}", IOUtil.toString( reader ) ); + assertEquals( "empty expression ${}", IOUtils.toString( reader ) ); in = new StringReader( "dollar space expression $ {a}" ); reader = getDollarBracesReader( in, interpolator, "\\" ); - assertEquals( "dollar space expression $ {a}", IOUtil.toString( reader ) ); + assertEquals( "dollar space expression $ {a}", IOUtils.toString( reader ) ); in = new StringReader( "space in expression ${ a}" ); reader = getDollarBracesReader( in, interpolator, "\\" ); - assertEquals( "space in expression ${ a}", IOUtil.toString( reader ) ); + assertEquals( "space in expression ${ a}", IOUtils.toString( reader ) ); in = new StringReader( "escape dollar with expression \\${a}" ); reader = getDollarBracesReader( in, interpolator, "\\" ); - assertEquals( "escape dollar with expression ${a}", IOUtil.toString( reader ) ); + assertEquals( "escape dollar with expression ${a}", IOUtils.toString( reader ) ); // in = new StringReader( "escape escape string before expression \\\\${a}" ); // reader = getDollarBracesReader( in, interpolator, "\\" ); -// assertEquals( "escape escape string before expression \\DONE_A", IOUtil.toString( reader ) ); +// assertEquals( "escape escape string before expression \\DONE_A", IOUtils.toString( reader ) ); // // in = new StringReader( "escape escape string and expression \\\\\\${a}" ); // reader = getDollarBracesReader( in, interpolator, "\\" ); -// assertEquals( "escape escape string before expression \\${a}", IOUtil.toString( reader ) ); +// assertEquals( "escape escape string before expression \\${a}", IOUtils.toString( reader ) ); in = new StringReader( "unknown expression ${unknown}" ); reader = getDollarBracesReader( in, interpolator, "\\" ); - assertEquals( "unknown expression ${unknown}", IOUtil.toString( reader ) ); + assertEquals( "unknown expression ${unknown}", IOUtils.toString( reader ) ); } // MSHARED-198: custom delimiters doesn't work as expected @@ -101,22 +102,22 @@ public void testCustomDelimiters() Reader in = new StringReader( "aaaFILTER.a.MEaaa" ); Reader reader = getAaa_AaaReader( in, interpolator ); - assertEquals( "DONE", IOUtil.toString( reader ) ); + assertEquals( "DONE", IOUtils.toString( reader ) ); in = new StringReader( "abcFILTER.a.MEabc" ); reader = getAbc_AbcReader( in, interpolator ); - assertEquals( "DONE", IOUtil.toString( reader ) ); + assertEquals( "DONE", IOUtils.toString( reader ) ); } // MSHARED-235: reader exceeds readAheadLimit @Test - public void testMarkInvalid() - throws Exception + public void testMarkInvalid() throws IOException { - Reader in = new StringReader( "@\").replace(p,\"]\").replace(q,\"" ); - Reader reader = getAtReader( in, interpolator, "\\" ); - - assertEquals( "@\").replace(p,\"]\").replace(q,\"", IOUtil.toString( reader ) ); + try ( Reader reader = + getAtReader( new StringReader( "@\").replace(p,\"]\").replace(q,\"" ), interpolator, "\\" ) ) + { + assertEquals( "@\").replace(p,\"]\").replace(q,\"", IOUtils.toString( reader ) ); + } } protected abstract Reader getAbc_AbcReader( Reader in, Interpolator interpolator ); diff --git a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenFileFilterTest.java b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenFileFilterTest.java index 2eb0220..04f58f7 100644 --- a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenFileFilterTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenFileFilterTest.java @@ -29,10 +29,10 @@ import java.util.List; import java.util.Properties; +import org.apache.commons.io.IOUtils; import org.apache.maven.project.MavenProject; import org.apache.maven.shared.utils.io.FileUtils; import org.apache.maven.shared.utils.io.FileUtils.FilterWrapper; -import org.apache.maven.shared.utils.io.IOUtil; import org.codehaus.plexus.PlexusTestCase; /** @@ -149,9 +149,10 @@ public void testMavenBasedir() List wrappers = mavenFileFilter.getDefaultFilterWrappers( req ); - Reader reader = wrappers.get( 0 ).getReader( new StringReader( "${filefilter} ${buildfilter}" ) ); - - assertEquals( "true true", IOUtil.toString( reader ) ); + try ( Reader reader = wrappers.get( 0 ).getReader( new StringReader( "${filefilter} ${buildfilter}" ) ) ) + { + assertEquals( "true true", IOUtils.toString( reader ) ); + } } // MSHARED-198: custom delimiters doesn't work as expected @@ -169,10 +170,10 @@ public void testCustomDelimiters() List wrappers = mavenFileFilter.getDefaultFilterWrappers( req ); Reader reader = wrappers.get( 0 ).getReader( new StringReader( "aaaFILTER.a.MEaaa" ) ); - assertEquals( "DONE", IOUtil.toString( reader ) ); + assertEquals( "DONE", IOUtils.toString( reader ) ); reader = wrappers.get( 0 ).getReader( new StringReader( "abcFILTER.a.MEabc" ) ); - assertEquals( "DONE", IOUtil.toString( reader ) ); + assertEquals( "DONE", IOUtils.toString( reader ) ); } // MSHARED-199: Filtering doesn't work if 2 delimiters are used on the same line, the first one being left open @@ -188,7 +189,9 @@ public void testLineWithSingleAtAndExpression() List wrappers = mavenFileFilter.getDefaultFilterWrappers( req ); - Reader reader = wrappers.get( 0 ).getReader( new StringReader( "toto@titi.com ${foo}" ) ); - assertEquals( "toto@titi.com bar", IOUtil.toString( reader ) ); + try ( Reader reader = wrappers.get( 0 ).getReader( new StringReader( "toto@titi.com ${foo}" ) ) ) + { + assertEquals( "toto@titi.com bar", IOUtils.toString( reader ) ); + } } } diff --git a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenReaderFilterTest.java b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenReaderFilterTest.java index f440b25..49d6ec6 100644 --- a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenReaderFilterTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenReaderFilterTest.java @@ -23,7 +23,7 @@ import java.io.StringReader; import java.util.Properties; -import org.apache.maven.shared.utils.io.IOUtil; +import org.apache.commons.io.IOUtils; import org.codehaus.plexus.PlexusTestCase; /** @@ -35,7 +35,6 @@ public class DefaultMavenReaderFilterTest public void testJustDoSomeFiltering() throws Exception { - assertNotNull( DefaultMavenReaderFilter.class ); MavenReaderFilter readerFilter = lookup( MavenReaderFilter.class ); StringReader src = new StringReader( "toto@titi.com ${foo}" ); @@ -46,8 +45,9 @@ public void testJustDoSomeFiltering() req.setFiltering( true ); req.setAdditionalProperties( additionalProperties ); - final Reader filter = readerFilter.filter( req ); - - assertEquals( "toto@titi.com bar", IOUtil.toString( filter ) ); + try ( Reader filter = readerFilter.filter( req ) ) + { + assertEquals( "toto@titi.com bar", IOUtils.toString( filter ) ); + } } } diff --git a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java index 253634a..a47fc01 100644 --- a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java @@ -28,11 +28,11 @@ import java.util.List; import java.util.Properties; +import org.apache.commons.io.IOUtils; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Resource; import org.apache.maven.settings.Settings; import org.apache.maven.shared.utils.io.FileUtils; -import org.apache.maven.shared.utils.io.IOUtil; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.interpolation.PrefixedObjectValueSource; import org.codehaus.plexus.interpolation.ValueSource; @@ -395,9 +395,9 @@ public static boolean filesAreIdentical( File expected, File current ) FileInputStream currentIn = new FileInputStream( current ) ) { - byte[] expectedBuffer = IOUtil.toByteArray( expectedIn ); + byte[] expectedBuffer = IOUtils.toByteArray( expectedIn ); - byte[] currentBuffer = IOUtil.toByteArray( currentIn ); + byte[] currentBuffer = IOUtils.toByteArray( currentIn ); if ( expectedBuffer.length != currentBuffer.length ) { return false; diff --git a/src/test/java/org/apache/maven/shared/filtering/EscapeStringTest.java b/src/test/java/org/apache/maven/shared/filtering/EscapeStringTest.java index 535d49c..d755f6c 100644 --- a/src/test/java/org/apache/maven/shared/filtering/EscapeStringTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/EscapeStringTest.java @@ -21,14 +21,15 @@ import java.io.File; import java.io.FileInputStream; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Properties; +import org.apache.commons.io.IOUtils; import org.apache.maven.model.Resource; import org.apache.maven.shared.utils.io.FileUtils; -import org.apache.maven.shared.utils.io.IOUtil; import org.codehaus.plexus.PlexusTestCase; /** @@ -91,7 +92,7 @@ public void testEscape() try ( FileInputStream in = new FileInputStream( new File( outputDirectory, "content.xml" ) ) ) { - String content = IOUtil.toString( in ); + String content = IOUtils.toString( in, StandardCharsets.UTF_8 ); assertTrue( content.contains( "Content with replacement: I am the replacement !" ) ); assertTrue( content.contains( "Content with escaped replacement: Do not ${replaceThis} !" ) ); }