5

I have file related code to test where I would like 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 the tests from the real file system.

So how would I create a file on jimfs that is not readable?

I have already tried assigning posix permissions and a different user to the path through Files.setAttribute on the desired path, both of which seem to have been ignored when attempting to read or write to the path.

EdJoJob
  • 1,139
  • 9
  • 15

1 Answers1

2

Unfortunately there isn't currently any support for actual permission/access checking for files in Jimfs. It's something that I think would be good to have, but I haven't worked out the details: see this issue and this somewhat related issue.

ColinD
  • 108,630
  • 30
  • 201
  • 202
  • Is there any other way to induce an `IOExcetpion` from jimfs, so that the error handling code could be tested? – bruno Jul 29 '19 at 16:11