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

    IOUtils.closeQuietly(in);
  }
Пример #3
0
 @Test
 public void testCloseQuietlyServerSocketOpen() throws IOException {
   final ServerSocket s = new ServerSocket(0);
   assertFalse(s.isClosed());
   IOUtils.closeQuietly(s);
   assertTrue(s.isClosed());
 }
Пример #4
0
 @Test
 public void testCloseQuietlySocketClosed() throws IOException {
   final Socket s = new Socket();
   s.close();
   assertTrue(s.isClosed());
   IOUtils.closeQuietly(s);
   assertTrue(s.isClosed());
 }
Пример #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().
    }
  }
Пример #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().
    }
  }
Пример #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);
  }
Пример #8
0
 @Test
 public void testCloseQuietlyImageInputStreamNull() {
   IOUtils.closeQuietly((ImageInputStream) null);
 }
Пример #9
0
 @Test
 public void testCloseQuietlyZipFileNull() {
   IOUtils.closeQuietly((ZipFile) null);
 }
Пример #10
0
 @Test
 public void testCloseQuietlyZipFileClosed() throws IOException {
   final ZipFile zf = new ZipFile("test/VASSAL/tools/io/test.zip");
   zf.close();
   IOUtils.closeQuietly(zf);
 }
Пример #11
0
 @Test
 public void testCloseQuietlySocketNull() {
   IOUtils.closeQuietly((Socket) null);
 }
Пример #12
0
 @Test
 public void testCloseQuietlyCloseableNull() {
   IOUtils.closeQuietly((Closeable) null);
 }