private static void assertClosedByInterrupt(FileChannelMethod method) throws IOException {
    FileChannel channel = channel(regularFile(10), READ, WRITE);
    Thread.currentThread().interrupt();
    try {
      method.call(channel);
      fail(
          "expected the method to throw ClosedByInterruptException or "
              + "FileLockInterruptionException");
    } catch (ClosedByInterruptException | FileLockInterruptionException expected) {
      assertFalse("expected the channel to be closed", channel.isOpen());
      assertTrue("expected the thread to still be interrupted", Thread.interrupted());
    } finally {
      Thread.interrupted(); // ensure the thread isn't interrupted when this method returns
    }
  }
Asserts that when the given operation is run on an interrupted thread, {@code
ClosedByInterruptException} is thrown, the channel is closed and the thread is no longer
interrupted.
jimfs/src/test/java/com/google/common/jimfs/JimfsFileChannelTest.java