Esempio n. 1
0
 @Test
 public void testCloseQuietlySocketOpen() {
   final Socket s = new Socket();
   assertFalse(s.isClosed());
   IOUtils.closeQuietly(s);
   assertTrue(s.isClosed());
 }
Esempio n. 2
0
  @Test
  public void testCloseQuietlyImageInputStreamClosed() throws IOException {
    final ImageInputStream in = new MemoryCacheImageInputStream(new ClosedInputStream());
    in.close();

    IOUtils.closeQuietly(in);
  }
Esempio n. 3
0
 @Test
 public void testCloseQuietlyServerSocketOpen() throws IOException {
   final ServerSocket s = new ServerSocket(0);
   assertFalse(s.isClosed());
   IOUtils.closeQuietly(s);
   assertTrue(s.isClosed());
 }
Esempio n. 4
0
 @Test
 public void testCloseQuietlySocketClosed() throws IOException {
   final Socket s = new Socket();
   s.close();
   assertTrue(s.isClosed());
   IOUtils.closeQuietly(s);
   assertTrue(s.isClosed());
 }
Esempio n. 5
0
  @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().
    }
  }
Esempio n. 6
0
  @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().
    }
  }
Esempio n. 7
0
  @Test
  public void testCloseQuietlyCloseableOk() throws IOException {
    final Closeable c = context.mock(Closeable.class);

    context.checking(
        new Expectations() {
          {
            oneOf(c).close();
          }
        });

    IOUtils.closeQuietly(c);
  }
Esempio n. 8
0
 @Test
 public void testCloseQuietlyImageInputStreamNull() {
   IOUtils.closeQuietly((ImageInputStream) null);
 }
Esempio n. 9
0
 @Test
 public void testCloseQuietlyZipFileNull() {
   IOUtils.closeQuietly((ZipFile) null);
 }
Esempio n. 10
0
 @Test
 public void testCloseQuietlyZipFileClosed() throws IOException {
   final ZipFile zf = new ZipFile("test/VASSAL/tools/io/test.zip");
   zf.close();
   IOUtils.closeQuietly(zf);
 }
Esempio n. 11
0
 @Test
 public void testCloseQuietlySocketNull() {
   IOUtils.closeQuietly((Socket) null);
 }
Esempio n. 12
0
 @Test
 public void testCloseQuietlyCloseableNull() {
   IOUtils.closeQuietly((Closeable) null);
 }