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

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git


The following commit(s) were added to refs/heads/master by this push:
     new 40af9d67 Use try-with-resources
40af9d67 is described below

commit 40af9d674997f20cfb5f1820b3a77d46266aadba
Author: Gary Gregory <[email protected]>
AuthorDate: Fri Dec 15 16:17:37 2023 -0500

    Use try-with-resources
    
    Use fail() instead of a runtime exception
---
 src/test/java/org/apache/commons/io/IOUtilsTest.java | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/src/test/java/org/apache/commons/io/IOUtilsTest.java 
b/src/test/java/org/apache/commons/io/IOUtilsTest.java
index 572dc9fb..6abeab6b 100644
--- a/src/test/java/org/apache/commons/io/IOUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/IOUtilsTest.java
@@ -26,6 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertSame;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
@@ -147,15 +148,11 @@ public class IOUtilsTest {
             if (!testFile.getParentFile().exists()) {
                 throw new IOException("Cannot create file " + testFile + " as 
the parent directory does not exist");
             }
-            final BufferedOutputStream output = new 
BufferedOutputStream(Files.newOutputStream(testFilePath));
-            try {
+            try (BufferedOutputStream output = new 
BufferedOutputStream(Files.newOutputStream(testFilePath))) {
                 TestUtils.generateTestData(output, FILE_SIZE);
-            } finally {
-                IOUtils.closeQuietly(output);
             }
-        } catch (final IOException ioe) {
-            throw new RuntimeException(
-                "Can't run this test because the environment could not be 
built: " + ioe.getMessage());
+        } catch (final IOException e) {
+            fail("Can't run this test because the environment could not be 
built: " + e.getMessage());
         }
         // Create and init a byte array as input data
         iarr = new byte[200];

Reply via email to