|
|
@@ -44,17 +44,17 @@ public class IOUtilsTest {
|
|
|
public void testClose_Object() throws Exception {
|
|
|
List<Integer> out = new ArrayList<>();
|
|
|
|
|
|
- assertFalse( IOUtils.close((Object)null) );
|
|
|
- assertTrue( IOUtils.close((Object) (Closeable)() -> { out.add(7); }) );
|
|
|
- assertTrue( IOUtils.close((Object) (AutoCloseable)() -> { out.add(8); }) );
|
|
|
+ assertFalse( IOUtils.closeAny(null) );
|
|
|
+ assertTrue( IOUtils.closeAny((Closeable)() -> { out.add(7); }) );
|
|
|
+ assertTrue( IOUtils.closeAny((AutoCloseable)() -> { out.add(8); }) );
|
|
|
|
|
|
assertEquals(Arrays.asList(7,8), out);
|
|
|
|
|
|
assertThrows(IOException.class, ()->{
|
|
|
- IOUtils.close((Object)new CFile("IO"));
|
|
|
+ IOUtils.closeAny(new CFile("IO"));
|
|
|
});
|
|
|
assertThrows(SQLException.class, ()->{
|
|
|
- IOUtils.close((Object)new SFile());
|
|
|
+ IOUtils.closeAny(new SFile());
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -62,8 +62,8 @@ public class IOUtilsTest {
|
|
|
public void testClose_Closeable() throws IOException {
|
|
|
List<Integer> out = new ArrayList<>();
|
|
|
|
|
|
- assertFalse( IOUtils.close((Closeable)null) );
|
|
|
- assertTrue( IOUtils.close((Closeable)() -> { out.add(7); }) );
|
|
|
+ assertFalse( IOUtils.close(null) );
|
|
|
+ assertTrue( IOUtils.close(() -> { out.add(7); }) );
|
|
|
|
|
|
assertEquals(Arrays.asList(7), out);
|
|
|
|
|
|
@@ -76,27 +76,25 @@ public class IOUtilsTest {
|
|
|
public void testClose_Consumer() {
|
|
|
List<Throwable> errors = new ArrayList<>();
|
|
|
|
|
|
- EventListener<Events.Failure> listener = (e) -> {
|
|
|
- errors.add(e.cause());
|
|
|
- };
|
|
|
+ EventListener<Events.Failure> listener = (e) -> errors.add(e.cause());
|
|
|
|
|
|
// listener
|
|
|
- IOUtils.close(new CFile("IO"), listener.consumer(e -> Events.failure(e)));
|
|
|
+ IOUtils.close(new CFile("IO"), listener.consumer(Events::failure));
|
|
|
|
|
|
// listener
|
|
|
- IOUtils.close(new SFile(), listener.consumer(Events::failure));
|
|
|
+ IOUtils.closeAny(new SFile(), listener.consumer(Events::failure));
|
|
|
|
|
|
// consumer
|
|
|
- IOUtils.close(new CFile("NC"), (Exception e) -> errors.add(e));
|
|
|
+ IOUtils.closeAny(new CFile("NC"), e -> errors.add(e));
|
|
|
|
|
|
// real NOP - ignore exception silently
|
|
|
- IOUtils.close(new SFile(), e -> {});
|
|
|
+ IOUtils.closeAny(new SFile(), e -> {});
|
|
|
|
|
|
// "safe" NOP - write exception to log (with WARN level)
|
|
|
- IOUtils.close(new SFile(), null);
|
|
|
+ IOUtils.closeAny(new SFile(), null);
|
|
|
|
|
|
// explicit logger
|
|
|
- IOUtils.close(new SFile(), e -> LOGGER.error("close!", e));
|
|
|
+ IOUtils.closeAny(new SFile(), e -> LOGGER.error("close!", e));
|
|
|
|
|
|
List<String> expected = Arrays.asList(
|
|
|
"java.io.IOException: IO",
|