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/29 23:26:33 UTC
[maven-shared-utils] 01/01: suppress deprecations and clean up test
methods
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch suppress
in repository https://gitbox.apache.org/repos/asf/maven-shared-utils.git
commit fbba19197a95d15fa63b041ea29dfbc33272fe55
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Fri May 29 19:26:09 2020 -0400
suppress deprecations and clean up test methods
---
.../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 ++++++-----
5 files changed, 22 insertions(+), 85 deletions(-)
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..b7dfb68 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.getProperty( "line.separator" ) );
}
}
}
@@ -92,7 +97,7 @@ public final class FileTestHelper
if ( destination.exists() )
{
- FileUtils.forceDelete( destination );
+ FileUtils.deleteQuietly( destination );
}
return destination;
}