### Question:
GlusterFileChannel extends FileChannel { @Override protected void implCloseChannel() throws IOException { if (!closed) { int close = GLFS.glfs_close(fileptr); if (0 != close) { throw new IOException("Close returned nonzero"); } closed = true; } }  @Override int read(ByteBuffer byteBuffer); @Override long read(ByteBuffer[] byteBuffers, int offset, int length); @Override int write(ByteBuffer byteBuffer); @Override long write(ByteBuffer[] byteBuffers, int offset, int length); @Override long position(); @Override FileChannel position(long offset); @Override long size(); @Override FileChannel truncate(long l); @Override void force(boolean b); @Override long transferTo(long l, long l2, WritableByteChannel writableByteChannel); @Override long transferFrom(ReadableByteChannel readableByteChannel, long l, long l2); @Override int read(ByteBuffer byteBuffer, long position); @Override int write(ByteBuffer byteBuffer, long position); @Override MappedByteBuffer map(MapMode mapMode, long l, long l2); @Override FileLock lock(long l, long l2, boolean b); @Override FileLock tryLock(long l, long l2, boolean b); static final Map<StandardOpenOption, Integer> optionMap; static final Map<PosixFilePermission, Integer> perms; }### Answer:
@Test(expected = IOException.class) public void testImplCloseChannel_whenFailing() throws IOException { long fileptr = 1234l; channel.setFileptr(fileptr); mockStatic(GLFS.class); when(GLFS.glfs_close(fileptr)).thenReturn(1); channel.implCloseChannel(); }
@Test public void testImplCloseChannel_whenAlreadyClosed() throws IOException { channel.setClosed(true); long fileptr = 1234l; channel.setFileptr(fileptr); mockStatic(GLFS.class); when(GLFS.glfs_close(fileptr)).thenReturn(0); channel.implCloseChannel(); assertTrue(channel.isClosed()); verifyStatic(never()); GLFS.glfs_close(fileptr); }
@Test public void testImplCloseChannel() throws IOException { long fileptr = 1234l; channel.setFileptr(fileptr); mockStatic(GLFS.class); when(GLFS.glfs_close(fileptr)).thenReturn(0); channel.implCloseChannel(); assertTrue(channel.isClosed()); verifyStatic(); GLFS.glfs_close(fileptr); }