Skip to content

Commit 40af9d6

Browse files
committed
Use try-with-resources
Use fail() instead of a runtime exception
1 parent aef6472 commit 40af9d6

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

src/test/java/org/apache/commons/io/IOUtilsTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import static org.junit.jupiter.api.Assertions.assertSame;
2727
import static org.junit.jupiter.api.Assertions.assertThrows;
2828
import static org.junit.jupiter.api.Assertions.assertTrue;
29+
import static org.junit.jupiter.api.Assertions.fail;
2930

3031
import java.io.BufferedInputStream;
3132
import java.io.BufferedOutputStream;
@@ -147,15 +148,11 @@ public void setUp() {
147148
if (!testFile.getParentFile().exists()) {
148149
throw new IOException("Cannot create file " + testFile + " as the parent directory does not exist");
149150
}
150-
final BufferedOutputStream output = new BufferedOutputStream(Files.newOutputStream(testFilePath));
151-
try {
151+
try (BufferedOutputStream output = new BufferedOutputStream(Files.newOutputStream(testFilePath))) {
152152
TestUtils.generateTestData(output, FILE_SIZE);
153-
} finally {
154-
IOUtils.closeQuietly(output);
155153
}
156-
} catch (final IOException ioe) {
157-
throw new RuntimeException(
158-
"Can't run this test because the environment could not be built: " + ioe.getMessage());
154+
} catch (final IOException e) {
155+
fail("Can't run this test because the environment could not be built: " + e.getMessage());
159156
}
160157
// Create and init a byte array as input data
161158
iarr = new byte[200];

0 commit comments

Comments
 (0)