How to force an IOException in jimfs

I have a file related code to check where I want to test my error handling for an existing file that I cannot read.

class SomeClass {
    //...
    public void load(Path path) {
       if (!Files.isRegularFile(path)) {
           return null;
       }
       //...
       try {
           // ...
       catch (IOException e) {
           // cleanup
       }
    }
}

      

I am using jimfs to isolate tests from the real filesystem.

So how do I create a jimfs file that is unreadable?

I've already tried to assign posix and other user's permissions to the path through Files.setAttribute

to the desired path, both of which seem to have been ignored when trying to read or write the path.

+3


source to share


1 answer


Unfortunately, there is currently no support for actual file permissions / permissions in Jimfs. This is what I think would be nice, but I haven't worked out the details: see this question and this somewhat related issue .



+2


source







All Articles