You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2020/05/30 14:53:10 UTC

[maven-shared-utils] branch master updated: [MSHARED-860] suppress deprecations and clean up test methods (#46)

This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-shared-utils.git


The following commit(s) were added to refs/heads/master by this push:
     new b879ee5  [MSHARED-860] suppress deprecations and clean up test methods (#46)
b879ee5 is described below

commit b879ee53ad0c628e4500c52486223616d9f801c4
Author: Elliotte Rusty Harold <el...@users.noreply.github.com>
AuthorDate: Sat May 30 10:53:00 2020 -0400

    [MSHARED-860] suppress deprecations and clean up test methods (#46)
    
    * suppress deprecations and clean up test methods
    * remove deprecated methods
---
 .../shared/utils/xml/PrettyPrintXMLWriter.java     |  6 +-
 .../maven/shared/utils/XmlStreamReaderTest.java    | 10 ++--
 .../maven/shared/utils/io/MatchPatternTest.java    |  2 +-
 .../maven/shared/utils/io/MatchPatternsTest.java   |  2 +-
 .../maven/shared/utils/io/SelectorUtilsTest.java   |  3 +-
 .../shared/utils/testhelpers/ExceptionHelper.java  | 67 ----------------------
 .../shared/utils/testhelpers/FileTestHelper.java   | 33 ++++++-----
 .../shared/utils/xml/PrettyPrintXmlWriterTest.java | 39 ++++---------
 8 files changed, 41 insertions(+), 121 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/utils/xml/PrettyPrintXMLWriter.java b/src/main/java/org/apache/maven/shared/utils/xml/PrettyPrintXMLWriter.java
index deb07d2..851cffb 100644
--- a/src/main/java/org/apache/maven/shared/utils/xml/PrettyPrintXMLWriter.java
+++ b/src/main/java/org/apache/maven/shared/utils/xml/PrettyPrintXMLWriter.java
@@ -26,11 +26,9 @@ import java.util.ArrayList;
 import org.apache.maven.shared.utils.Os;
 
 /**
- * XMLWriter with nice indentation
- */
-/**
+ * XMLWriter with nice indentation.
+ * 
  * @author kama
- *
  */
 public class PrettyPrintXMLWriter
     implements XMLWriter
diff --git a/src/test/java/org/apache/maven/shared/utils/XmlStreamReaderTest.java b/src/test/java/org/apache/maven/shared/utils/XmlStreamReaderTest.java
index 3ffb98d..2e30538 100644
--- a/src/test/java/org/apache/maven/shared/utils/XmlStreamReaderTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/XmlStreamReaderTest.java
@@ -27,7 +27,8 @@ import java.io.SequenceInputStream;
 
 import junit.framework.ComparisonFailure;
 import junit.framework.TestCase;
-import org.apache.maven.shared.utils.io.IOUtil;
+
+import org.apache.commons.io.IOUtils;
 import org.apache.maven.shared.utils.xml.XmlStreamReader;
 
 /**
@@ -66,8 +67,7 @@ public class XmlStreamReaderTest
         return xmlDecl + "\n<text>" + text + "</text>";
     }
 
-    private static void checkXmlContent( String xml, String encoding )
-    throws IOException
+    private static void checkXmlContent( String xml, String encoding ) throws IOException
     {
         checkXmlContent( xml, encoding, null );
     }
@@ -76,7 +76,7 @@ public class XmlStreamReaderTest
     {
         byte[] xmlContent = xml.getBytes( encoding );
         InputStream in = new ByteArrayInputStream( xmlContent );
-
+        
         if ( bom != null )
         {
             in = new SequenceInputStream( new ByteArrayInputStream( bom ), in );
@@ -84,7 +84,7 @@ public class XmlStreamReaderTest
 
         XmlStreamReader reader = new XmlStreamReader( in );
         assertEquals( encoding, reader.getEncoding() );
-        String result = IOUtil.toString( reader );
+        String result = IOUtils.toString( reader );
         assertEquals( xml, result );
     }
 
diff --git a/src/test/java/org/apache/maven/shared/utils/io/MatchPatternTest.java b/src/test/java/org/apache/maven/shared/utils/io/MatchPatternTest.java
index c7f4ff7..6c7e11d 100644
--- a/src/test/java/org/apache/maven/shared/utils/io/MatchPatternTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/io/MatchPatternTest.java
@@ -25,11 +25,11 @@ import static org.junit.Assert.*;
 /**
  * @author Kristian Rosenvold
  */
+@SuppressWarnings( "deprecation" )
 public class MatchPatternTest
 {
     @Test
     public void matchPath()
-        throws Exception
     {
         MatchPattern mp = MatchPattern.fromString( "ABC*" );
         assertTrue( mp.matchPath( "ABCD", true ) );
diff --git a/src/test/java/org/apache/maven/shared/utils/io/MatchPatternsTest.java b/src/test/java/org/apache/maven/shared/utils/io/MatchPatternsTest.java
index 1a5d5a6..84b41f9 100644
--- a/src/test/java/org/apache/maven/shared/utils/io/MatchPatternsTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/io/MatchPatternsTest.java
@@ -26,11 +26,11 @@ import static org.junit.Assert.*;
 /**
  * @author Kristian Rosenvold
  */
+@SuppressWarnings( "deprecation" )
 public class MatchPatternsTest
 {
     @Test
     public void matches()
-        throws Exception
     {
         MatchPatterns from = MatchPatterns.from( "ABC**", "CDE**" );
         assertTrue( from.matches( "ABCDE", true ) );
diff --git a/src/test/java/org/apache/maven/shared/utils/io/SelectorUtilsTest.java b/src/test/java/org/apache/maven/shared/utils/io/SelectorUtilsTest.java
index ad4283f..750015a 100644
--- a/src/test/java/org/apache/maven/shared/utils/io/SelectorUtilsTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/io/SelectorUtilsTest.java
@@ -27,8 +27,8 @@ import org.junit.Test;
 
 /**
  * Test the {@link SelectorUtils} class.
- *
  */
+@SuppressWarnings( "deprecation" )
 public class SelectorUtilsTest
 {
 
@@ -67,7 +67,6 @@ public class SelectorUtilsTest
         assertAntDoesNotMatch( "/aaa/", "\\aaa\\bbb" );
     }
 
-
     private void assertAntDoesNotMatch( String pattern, String target )
     {
         assertEquals( false, SelectorUtils.matchPatternStart( wrapWithAntHandler( pattern ), target ) );
diff --git a/src/test/java/org/apache/maven/shared/utils/testhelpers/ExceptionHelper.java b/src/test/java/org/apache/maven/shared/utils/testhelpers/ExceptionHelper.java
deleted file mode 100644
index 8d153b4..0000000
--- a/src/test/java/org/apache/maven/shared/utils/testhelpers/ExceptionHelper.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package org.apache.maven.shared.utils.testhelpers;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
-import org.hamcrest.Matcher;
-
-
-public class ExceptionHelper
-{
-
-    /**
-     * A matcher that verifies that the a root cause of an exception is of the specified type.
-     *
-     * @param cause the type of exception that caused this.
-     * @return A matcher that verifies that the a root cause of an exception is of the specified type.
-     */
-    public static Matcher<Throwable> hasCause( Class<? extends Throwable> cause )
-    {
-        return new HasCause( cause );
-    }
-
-    private static class HasCause
-            extends BaseMatcher<Throwable>
-    {
-        private final Class<? extends Throwable> cause;
-
-        public HasCause( Class<? extends Throwable> cause )
-        {
-            this.cause = cause;
-        }
-
-        public boolean matches( Object item )
-        {
-            Throwable throwable = (Throwable) item;
-            while ( throwable != null && !cause.isInstance( throwable ) )
-            {
-                throwable = throwable.getCause();
-            }
-            return cause.isInstance( throwable );
-        }
-
-        public void describeTo( Description description )
-        {
-            description.appendText( "was caused by a " ).appendValue( cause ).appendText( " being thrown" );
-        }
-    }
-}
diff --git a/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java b/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java
index 81d4fad..aa7323c 100644
--- a/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java
+++ b/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java
@@ -19,20 +19,26 @@ package org.apache.maven.shared.utils.testhelpers;
  * under the License.
  */
 
-import org.apache.maven.shared.utils.io.FileUtils;
-import org.junit.rules.TemporaryFolder;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+
+import org.apache.commons.io.FileUtils;
 
-import java.io.*;
+import org.junit.rules.TemporaryFolder;
 
 /**
- * A few utility methods for file based tests
+ * A few utility methods for file based tests.
  */
 public final class FileTestHelper
 {
 
     private FileTestHelper()
     {
-        // utility function doesn't need a public ct
+        // utility function doesn't need a public constructor
     }
 
     public static void generateTestData( OutputStream out, long size )
@@ -54,14 +60,12 @@ public final class FileTestHelper
             testfile.delete();
         }
 
-        OutputStream os = new FileOutputStream( testfile );
-        generateTestData( os, size );
-        os.flush();
-        os.close();
+        try ( OutputStream os = new FileOutputStream( testfile ) ) {
+            generateTestData( os, size );
+            os.flush();
+        }
     }
 
-
-
     public static void createLineBasedFile( File file, String[] data )
         throws IOException
     {
@@ -70,11 +74,12 @@ public final class FileTestHelper
             throw new IOException( "Cannot create file " + file + " as the parent directory does not exist" );
         }
 
-        try ( PrintWriter out = new PrintWriter( new OutputStreamWriter( new FileOutputStream( file ), "UTF-8" ) ) )
+        try ( Writer out = new OutputStreamWriter( new FileOutputStream( file ), "UTF-8" ) )
         {
             for ( String aData : data )
             {
-                out.println( aData );
+                out.write( aData );
+                out.write( System.lineSeparator() );
             }
         }
     }
@@ -92,7 +97,7 @@ public final class FileTestHelper
 
         if ( destination.exists() )
         {
-            FileUtils.forceDelete( destination );
+            FileUtils.deleteQuietly( destination );
         }
         return destination;
     }
diff --git a/src/test/java/org/apache/maven/shared/utils/xml/PrettyPrintXmlWriterTest.java b/src/test/java/org/apache/maven/shared/utils/xml/PrettyPrintXmlWriterTest.java
index 5679512..4145cd0 100644
--- a/src/test/java/org/apache/maven/shared/utils/xml/PrettyPrintXmlWriterTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/xml/PrettyPrintXmlWriterTest.java
@@ -1,8 +1,9 @@
 package org.apache.maven.shared.utils.xml;
 
-import java.io.IOException;
-import javax.swing.text.html.HTML;
-import java.io.StringWriter;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.FileOutputStream;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -23,13 +24,14 @@ import java.io.StringWriter;
  * under the License.
  */
 
+import java.io.IOException;
 
+import javax.swing.text.html.HTML;
+import java.io.StringWriter;
 
 import org.apache.maven.shared.utils.Os;
 import org.apache.maven.shared.utils.StringUtils;
-import org.junit.After;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 
 /**
@@ -40,26 +42,9 @@ import org.junit.Test;
  */
 public class PrettyPrintXmlWriterTest
 {
-    StringWriter w;
-
-    PrettyPrintXMLWriter writer;
-
-    @Before
-    public void before()
-            throws Exception
-    {
-        w = new StringWriter();
-        writer = new PrettyPrintXMLWriter( w );
-    }
-
-    @After
-    public void after()
-            throws Exception
-    {
-        writer = null;
-        w = null;
-    }
-
+    private StringWriter w = new StringWriter();
+    private PrettyPrintXMLWriter writer = new PrettyPrintXMLWriter( w );
+    
     @Test
     public void testDefaultPrettyPrintXMLWriter() throws IOException
     {
@@ -178,12 +163,12 @@ public class PrettyPrintXmlWriterTest
         writer.endElement(); // Tag.BODY
     }
 
-    private String expectedResult( String lineSeparator )
+    private static String expectedResult( String lineSeparator )
     {
         return expectedResult( "  ", lineSeparator );
     }
 
-    private String expectedResult( String lineIndenter, String lineSeparator )
+    private static String expectedResult( String lineIndenter, String lineSeparator )
     {
         StringBuilder expected = new StringBuilder();