### Question:
GlusterFileChannel extends FileChannel { @Override public void force(boolean b) throws IOException { guardClosed(); int fsync = GLFS.glfs_fsync(fileptr); if (0 != fsync) { throw new IOException("Unable to fsync"); } }  @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 testForce_whenFailing() throws IOException { long fileptr = 1234l; channel.setFileptr(fileptr); mockStatic(GLFS.class); when(GLFS.glfs_fsync(fileptr)).thenReturn(-1); channel.force(true); }
@Test public void testForce() throws IOException { doNothing().when(channel).guardClosed(); long fileptr = 1234l; channel.setFileptr(fileptr); mockStatic(GLFS.class); when(GLFS.glfs_fsync(fileptr)).thenReturn(0); channel.force(true); verify(channel).guardClosed(); verifyStatic(); GLFS.glfs_fsync(fileptr); }