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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With