### Question:
GlusterFileChannel extends FileChannel { @Override public int write(ByteBuffer byteBuffer) throws IOException { guardClosed(); byte[] buf = byteBuffer.array(); int written = GLFS.glfs_write(fileptr, buf, buf.length, 0); if (written < 0) { throw new IOException(UtilJNI.strerror()); } position += written; byteBuffer.position(written); return written; }  @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 = ClosedChannelException.class) public void testWrite3Arg_whenClosedChannel() throws IOException { channel.setClosed(true); int length = 2; int offset = 0; ByteBuffer buffer1 = Mockito.mock(ByteBuffer.class); ByteBuffer buffer2 = Mockito.mock(ByteBuffer.class); ByteBuffer[] buffers = new ByteBuffer[]{buffer1, buffer2}; channel.write(buffers, offset, length); }
@Test(expected = ClosedChannelException.class) public void testWrite2Arg_whenChannelClosed() throws IOException { channel.setClosed(true); ByteBuffer buffer = Mockito.mock(ByteBuffer.class); long position = 0L; channel.write(buffer, position); }