@Test public void testCloseQuietlySocketOpen() { final Socket s = new Socket(); assertFalse(s.isClosed()); IOUtils.closeQuietly(s); assertTrue(s.isClosed()); }
@Test public void testCloseQuietlyImageInputStreamClosed() throws IOException { final ImageInputStream in = new MemoryCacheImageInputStream(new ClosedInputStream()); in.close(); IOUtils.closeQuietly(in); }
@Test public void testCloseQuietlyServerSocketOpen() throws IOException { final ServerSocket s = new ServerSocket(0); assertFalse(s.isClosed()); IOUtils.closeQuietly(s); assertTrue(s.isClosed()); }
@Test public void testCloseQuietlySocketClosed() throws IOException { final Socket s = new Socket(); s.close(); assertTrue(s.isClosed()); IOUtils.closeQuietly(s); assertTrue(s.isClosed()); }
@Test public void testCloseQuietlyZipFileOpen() throws IOException { final ZipFile zf = new ZipFile("test/VASSAL/tools/io/test.zip"); IOUtils.closeQuietly(zf); try { zf.size(); fail(); } catch (IllegalStateException e) { // This is the expected behavior of size(). } }
@Test public void testCloseQuietlyImageInputStreamOpen() { final ImageInputStream in = new MemoryCacheImageInputStream(new NullInputStream(1000)); IOUtils.closeQuietly(in); try { in.close(); fail(); } catch (IOException e) { // This, oddly, the expected behavior of close(). } }
@Test public void testCloseQuietlyCloseableOk() throws IOException { final Closeable c = context.mock(Closeable.class); context.checking( new Expectations() { { oneOf(c).close(); } }); IOUtils.closeQuietly(c); }
@Test public void testCloseQuietlyImageInputStreamNull() { IOUtils.closeQuietly((ImageInputStream) null); }
@Test public void testCloseQuietlyZipFileNull() { IOUtils.closeQuietly((ZipFile) null); }
@Test public void testCloseQuietlyZipFileClosed() throws IOException { final ZipFile zf = new ZipFile("test/VASSAL/tools/io/test.zip"); zf.close(); IOUtils.closeQuietly(zf); }
@Test public void testCloseQuietlySocketNull() { IOUtils.closeQuietly((Socket) null); }
@Test public void testCloseQuietlyCloseableNull() { IOUtils.closeQuietly((Closeable) null); }