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/07/11 12:00:47 UTC
[maven-dependency-analyzer] branch close created (now 5f9884c)
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a change to branch close
in repository https://gitbox.apache.org/repos/asf/maven-dependency-analyzer.git.
at 5f9884c use try with resources to avoid leaks
This branch includes the following new commits:
new 5f9884c use try with resources to avoid leaks
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[maven-dependency-analyzer] 01/01: use try with resources to avoid
leaks
Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch close
in repository https://gitbox.apache.org/repos/asf/maven-dependency-analyzer.git
commit 5f9884cb718ba03793485e6f7c0c25b71a5cef7b
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Sat Jul 11 08:00:32 2020 -0400
use try with resources to avoid leaks
---
.../analyzer/ClassFileVisitorUtilsTest.java | 18 +++++++++------
.../analyzer/DefaultClassAnalyzerTest.java | 26 ++++++++++------------
2 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/src/test/java/org/apache/maven/shared/dependency/analyzer/ClassFileVisitorUtilsTest.java b/src/test/java/org/apache/maven/shared/dependency/analyzer/ClassFileVisitorUtilsTest.java
index 72fe2d7..c705f6d 100644
--- a/src/test/java/org/apache/maven/shared/dependency/analyzer/ClassFileVisitorUtilsTest.java
+++ b/src/test/java/org/apache/maven/shared/dependency/analyzer/ClassFileVisitorUtilsTest.java
@@ -44,10 +44,11 @@ public class ClassFileVisitorUtilsTest
throws IOException
{
File file = createJar();
- JarOutputStream out = new JarOutputStream( new FileOutputStream( file ) );
- writeEntry( out, "a/b/c.class", "class a.b.c" );
- writeEntry( out, "x/y/z.class", "class x.y.z" );
- out.close();
+ try ( JarOutputStream out = new JarOutputStream( new FileOutputStream( file ) ) )
+ {
+ writeEntry( out, "a/b/c.class", "class a.b.c" );
+ writeEntry( out, "x/y/z.class", "class x.y.z" );
+ }
Mock mock = mock( ClassFileVisitor.class );
expectVisitClass( mock, "a.b.c", "class a.b.c" );
@@ -62,9 +63,10 @@ public class ClassFileVisitorUtilsTest
throws IOException
{
File file = createJar();
- JarOutputStream out = new JarOutputStream( new FileOutputStream( file ) );
- writeEntry( out, "a/b/c.jpg", "jpeg a.b.c" );
- out.close();
+ try ( JarOutputStream out = new JarOutputStream( new FileOutputStream( file ) ) )
+ {
+ writeEntry( out, "a/b/c.jpg", "jpeg a.b.c" );
+ }
Mock mock = mock( ClassFileVisitor.class );
@@ -125,6 +127,7 @@ public class ClassFileVisitorUtilsTest
try
{
ClassFileVisitorUtils.accept( url, (ClassFileVisitor) mock.proxy() );
+ fail("expected IllegalArgumntException");
}
catch ( IllegalArgumentException exception )
{
@@ -142,6 +145,7 @@ public class ClassFileVisitorUtilsTest
try
{
ClassFileVisitorUtils.accept( url, (ClassFileVisitor) mock.proxy() );
+ fail("expected IllegalArgumntException");
}
catch ( IllegalArgumentException exception )
{
diff --git a/src/test/java/org/apache/maven/shared/dependency/analyzer/DefaultClassAnalyzerTest.java b/src/test/java/org/apache/maven/shared/dependency/analyzer/DefaultClassAnalyzerTest.java
index bcb7a7d..40b3553 100644
--- a/src/test/java/org/apache/maven/shared/dependency/analyzer/DefaultClassAnalyzerTest.java
+++ b/src/test/java/org/apache/maven/shared/dependency/analyzer/DefaultClassAnalyzerTest.java
@@ -41,17 +41,21 @@ import org.codehaus.plexus.util.IOUtil;
public class DefaultClassAnalyzerTest
extends AbstractFileTest
{
- // tests ------------------------------------------------------------------
+ private File file;
+ public void setUp() throws IOException {
+ file = createJar();
+ try ( JarOutputStream out = new JarOutputStream( new FileOutputStream( file ) ) )
+ {
+ writeEntry( out, "a/b/c.class", "class a.b.c" );
+ writeEntry( out, "x/y/z.class", "class x.y.z" );
+ }
+ }
+
+
public void testAnalyzeWithJar()
throws IOException
{
- File file = createJar();
- JarOutputStream out = new JarOutputStream( new FileOutputStream( file ) );
- writeEntry( out, "a/b/c.class", "class a.b.c" );
- writeEntry( out, "x/y/z.class", "class x.y.z" );
- out.close();
-
Set<String> expectedClasses = new HashSet<String>();
expectedClasses.add( "a.b.c" );
expectedClasses.add( "x.y.z" );
@@ -66,13 +70,7 @@ public class DefaultClassAnalyzerTest
throws IOException
{
//to reproduce MDEP-143
- File file = createJar();
- JarOutputStream out = new JarOutputStream( new FileOutputStream( file ) );
- writeEntry( out, "a/b/c.class", "class a.b.c" );
- writeEntry( out, "x/y/z.class", "class x.y.z" );
- out.close();
-
- //corrupt the jar file by alter its contents
+ // corrupt the jar file by altering its contents
FileInputStream fis = new FileInputStream( file );
ByteArrayOutputStream baos = new ByteArrayOutputStream( 100 );
IOUtil.copy( fis, baos, 100 );