|
61 | 61 | import java.nio.file.Path; |
62 | 62 | import java.util.Arrays; |
63 | 63 | import java.util.List; |
| 64 | +import java.util.concurrent.atomic.AtomicBoolean; |
| 65 | +import java.util.function.Consumer; |
64 | 66 | import java.util.function.Supplier; |
65 | 67 | import java.util.stream.Stream; |
66 | 68 |
|
@@ -364,9 +366,40 @@ public void testCloseQuietly_AllCloseableIOException() { |
364 | 366 | } |
365 | 367 |
|
366 | 368 | @Test |
367 | | - public void testCloseQuietly_CloseableIOException() { |
| 369 | + public void testCloseQuietly_CloseableException() { |
| 370 | + // IOException |
368 | 371 | assertDoesNotThrow(() -> IOUtils.closeQuietly(BrokenInputStream.INSTANCE)); |
369 | 372 | assertDoesNotThrow(() -> IOUtils.closeQuietly(BrokenOutputStream.INSTANCE)); |
| 373 | + // IOException subclass |
| 374 | + assertDoesNotThrow(() -> IOUtils.closeQuietly(new BrokenOutputStream((Throwable) new EOFException()))); |
| 375 | + // RuntimeException |
| 376 | + assertDoesNotThrow(() -> IOUtils.closeQuietly(new BrokenOutputStream(new RuntimeException()))); |
| 377 | + // RuntimeException subclass |
| 378 | + assertDoesNotThrow(() -> IOUtils.closeQuietly(new BrokenOutputStream(new UnsupportedOperationException()))); |
| 379 | + } |
| 380 | + |
| 381 | + @Test |
| 382 | + public void testCloseQuietly_CloseableExceptionConsumer() { |
| 383 | + final AtomicBoolean b = new AtomicBoolean(); |
| 384 | + final Consumer<Exception> consumer = e -> b.set(true); |
| 385 | + // IOException |
| 386 | + assertDoesNotThrow(() -> IOUtils.closeQuietly(BrokenInputStream.INSTANCE, consumer)); |
| 387 | + assertTrue(b.get()); |
| 388 | + b.set(false); |
| 389 | + assertDoesNotThrow(() -> IOUtils.closeQuietly(BrokenOutputStream.INSTANCE, consumer)); |
| 390 | + assertTrue(b.get()); |
| 391 | + b.set(false); |
| 392 | + // IOException subclass |
| 393 | + assertDoesNotThrow(() -> IOUtils.closeQuietly(new BrokenOutputStream((Throwable) new EOFException()), consumer)); |
| 394 | + assertTrue(b.get()); |
| 395 | + b.set(false); |
| 396 | + // RuntimeException |
| 397 | + assertDoesNotThrow(() -> IOUtils.closeQuietly(new BrokenOutputStream(new RuntimeException()), consumer)); |
| 398 | + assertTrue(b.get()); |
| 399 | + b.set(false); |
| 400 | + // RuntimeException subclass |
| 401 | + assertDoesNotThrow(() -> IOUtils.closeQuietly(new BrokenOutputStream(new UnsupportedOperationException()), consumer)); |
| 402 | + assertTrue(b.get()); |
370 | 403 | } |
371 | 404 |
|
372 | 405 | @SuppressWarnings("squid:S2699") // Suppress "Add at least one assertion to this test case" |
|
0 commit comments