Consider some code that calls, say,
file = new RandomAccessFile(x, "r");
file.getChannel().map(....)
and wants to handle a ClosedByInterruptException circumstance. I'm stumped by how to make a realistic, repeatable unit test.
To make a test, I need to somehow synchronize this thread with some other thread, and cause the other thread to call Thread#interrupt at the right time. However, all the primitives for waiting are, well, interruptible, and clear out the interrupt.
For now I've got Thread.currentThread().interrupt in the code being tested (as requested by the unit test), but this isn't really quite the same thing as an actual async interrupt, is it?