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-rar-plugin.git
The following commit(s) were added to refs/heads/master by this push: new 90579fe use try with resources (#32) 90579fe is described below commit 90579fe0d52e6a7bb598fb6a2c613c6a18a51643 Author: Elliotte Rusty Harold <elh...@users.noreply.github.com> AuthorDate: Sun Dec 8 13:07:06 2024 +0000 use try with resources (#32) --- .../org/apache/maven/plugins/rar/RarMojoTest.java | 36 +++++++++------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/rar/RarMojoTest.java b/src/test/java/org/apache/maven/plugins/rar/RarMojoTest.java index 2290f34..8dcb9db 100644 --- a/src/test/java/org/apache/maven/plugins/rar/RarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/rar/RarMojoTest.java @@ -136,15 +136,13 @@ public class RarMojoTest extends AbstractMojoTestCase { expectedFiles.add("maven-artifact02-1.0-SNAPSHOT.jar"); expectedFiles.add("test-rar.jar"); - ZipFile rar = new ZipFile(rarFile); + try (ZipFile rar = new ZipFile(rarFile)) { + Enumeration<? extends ZipEntry> entries = rar.entries(); - Enumeration<? extends ZipEntry> entries = rar.entries(); + assertTrue(entries.hasMoreElements()); - assertTrue(entries.hasMoreElements()); - - assertEquals(0, getSizeOfExpectedFiles(entries, expectedFiles)); - - rar.close(); + assertEquals(0, getSizeOfExpectedFiles(entries, expectedFiles)); + } } public void testBasicRarWithDescriptor() throws Exception { @@ -207,15 +205,13 @@ public class RarMojoTest extends AbstractMojoTestCase { expectedFiles.add("maven-artifact01-1.0-SNAPSHOT.jar"); expectedFiles.add("maven-artifact02-1.0-SNAPSHOT.jar"); - ZipFile rar = new ZipFile(rarFile); - - Enumeration<? extends ZipEntry> entries = rar.entries(); - - assertTrue(entries.hasMoreElements()); + try (ZipFile rar = new ZipFile(rarFile)) { + Enumeration<? extends ZipEntry> entries = rar.entries(); - assertEquals(0, getSizeOfExpectedFiles(entries, expectedFiles)); + assertTrue(entries.hasMoreElements()); - rar.close(); + assertEquals(0, getSizeOfExpectedFiles(entries, expectedFiles)); + } } public void testBasicRarWithManifest() throws Exception { @@ -279,15 +275,13 @@ public class RarMojoTest extends AbstractMojoTestCase { expectedFiles.add("maven-artifact01-1.0-SNAPSHOT.jar"); expectedFiles.add("maven-artifact02-1.0-SNAPSHOT.jar"); - ZipFile rar = new ZipFile(rarFile); - - Enumeration<? extends ZipEntry> entries = rar.entries(); + try (ZipFile rar = new ZipFile(rarFile)) { + Enumeration<? extends ZipEntry> entries = rar.entries(); - assertTrue(entries.hasMoreElements()); + assertTrue(entries.hasMoreElements()); - assertEquals(0, getSizeOfExpectedFiles(entries, expectedFiles)); - - rar.close(); + assertEquals(0, getSizeOfExpectedFiles(entries, expectedFiles)); + } } private int getSizeOfExpectedFiles(Enumeration<? extends ZipEntry> entries, List<String> expectedFiles) {