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

    IOUtils.closeQuietly(in);
  }
Exemplo n.º 3
0
 @Test
 public void testCloseQuietlyServerSocketOpen() throws IOException {
   final ServerSocket s = new ServerSocket(0);
   assertFalse(s.isClosed());
   IOUtils.closeQuietly(s);
   assertTrue(s.isClosed());
 }
Exemplo 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());
 }
Exemplo 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().
    }
  }
Exemplo 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().
    }
  }
Exemplo 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);
  }
Exemplo n.º 8
0
 @Test
 public void testCloseQuietlyImageInputStreamNull() {
   IOUtils.closeQuietly((ImageInputStream) null);
 }
Exemplo n.º 9
0
 @Test
 public void testCloseQuietlyZipFileNull() {
   IOUtils.closeQuietly((ZipFile) null);
 }
Exemplo 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);
 }
Exemplo n.º 11
0
 @Test
 public void testCloseQuietlySocketNull() {
   IOUtils.closeQuietly((Socket) null);
 }
Exemplo n.º 12
0
 @Test
 public void testCloseQuietlyCloseableNull() {
   IOUtils.closeQuietly((Closeable) null);
 }