我需要为使用java.nio.Files.isReadable(Path)的方法编写测试
。
如何模拟存在但无法读取的路径?
我无法创建文件(或目录)并删除执行用户的读取权限,因为这样我就无法在执行测试后清理它;我没有说如何模拟 Files.isReadable(Path)
因为它是一个静态方法,在要测试的方法中调用。
更新:我尝试了File#setReadable(false)
,但这似乎没有效果。
最佳答案
File tempFile = File.createTempFile("hello", ".tmp");
boolean success = file.setReadOnly();
// and execute your test
// make sure you need to capture various error scenario that might occur during
file creation and setting the file to ready only.
关于java - 如何模拟存在但无法读取的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60637040/