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 deb07d21..851cffbf 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 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 3ffb98d3..2e305382 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 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 @@ private static String createXmlContent( String text, String encoding )
return xmlDecl + "\n" + 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 @@ private static void checkXmlContent( String xml, String encoding, byte[] bom ) t
{
byte[] xmlContent = xml.getBytes( encoding );
InputStream in = new ByteArrayInputStream( xmlContent );
-
+
if ( bom != null )
{
in = new SequenceInputStream( new ByteArrayInputStream( bom ), in );
@@ -84,7 +84,7 @@ private static void checkXmlContent( String xml, String encoding, byte[] bom ) t
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 c7f4ff7b..6c7e11d3 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 @@
/**
* @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 1a5d5a68..84b41f96 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 @@
/**
* @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 ad4283fd..750015a7 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 @@
/**
* Test the {@link SelectorUtils} class.
- *
*/
+@SuppressWarnings( "deprecation" )
public class SelectorUtilsTest
{
@@ -67,7 +67,6 @@ public void testAntPatternStrings()
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 8d153b4b..00000000
--- 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 hasCause( Class extends Throwable> cause )
- {
- return new HasCause( cause );
- }
-
- private static class HasCause
- extends BaseMatcher
- {
- 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 81d4fad6..aa7323cd 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 @@
* 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 static void generateTestFile( File testfile, int size )
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 static void createLineBasedFile( File file, String[] data )
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 static File newFile( TemporaryFolder folder, String filename )
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 5679512f..4145cd04 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 @@
* 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 @@
*/
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 @@ private void writeXhtmlBody( XMLWriter writer ) throws IOException
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();