I've been trying to devise a file path and if possible a file name that is impossible for Java to create on Linux/MacOS/Windows using the following code:
File directory = new Directory(dir);
directory.mkdirs(); // should always fail and not affect an existing file/dir
File file = new File(dir, filename);
file.createNewFile(); // should always fail and not affect an existing file/dir
This kind of path will be used in unit tests to prove certain error conditions are being handled correctly Assume the tests are being run as root
(they aren't, but I want to focus on invalid paths vice privs). So far everything I've tried will fail on one platform (usually Windows) but not another (usually Linux).
Suggestions?
PS. I know about mock objects, PowerMock, etc. but really just want to get Java's as-is File class to fail to create the directory/file.