Closing { @VisibleForTesting static void closeQuietly(@Nullable final Object object) { if (object instanceof Closeable) { try { ((Closeable) object).close(); } catch (final IOException e) { log.warn("IOException thrown while closing Closeable.", e); } } } private  Closing();   }
@Test void closes() throws IOException { final Closeable closeable = mock(Closeable.class); closeQuietly(closeable); verify(closeable).close(); }
@Test void ignoresNonCloseable() { closeQuietly(new Object()); }
@Test void ignoresNull() { closeQuietly(null); }
@Test void swallowsException() throws IOException { final Closeable closeable = mock(Closeable.class); doThrow(new IOException()).when(closeable).close(); closeQuietly(closeable); verify(closeable).close(); }