V
Veerle
Hi,
I am writing unit tests that have to be able to run anywhere.
(developers pc's are Win XP ; the server is Linux). In order to get
the coverage to 100%, I want to test a piece of code where the
creation of a temporary file fails.
What I want to do is create a subfolder in the temporary folder (=
System.getProperty("java.io.tmpdir")) in the setup part of the unit
test. Then I want to change the permissions of the subfolder so that
the creation of a temporary file in it fails by throwing an
IOException or some other Exception. This way I can garantee that the
unit test will work on other developers pcs and on the server as well.
In the tearDown part, I clean up the folder that I've created.
I have to do this in Java 5, but when looking at the File api for java
5, I only see the possibility to set the folder to readonly (method
setReadOnly()). But appearantly, in Win XP, when a folder is readonly,
it is still possible to create a file in it (tried it in the Windows
Explorer and it works there as well). So this doesn't give me my
IOException that I want. So I need to find a way to actually change
the folder permissions so that for the current user the folder is not
accessible. In Java 6, I see in the api that File has a lot more
methods: setReadable, setWriteable which probably would of help, if I
had Java 6.
Is there a way in Java 5 to modify the folder permissions in such a
way that is OS independent?
Veerle
I am writing unit tests that have to be able to run anywhere.
(developers pc's are Win XP ; the server is Linux). In order to get
the coverage to 100%, I want to test a piece of code where the
creation of a temporary file fails.
What I want to do is create a subfolder in the temporary folder (=
System.getProperty("java.io.tmpdir")) in the setup part of the unit
test. Then I want to change the permissions of the subfolder so that
the creation of a temporary file in it fails by throwing an
IOException or some other Exception. This way I can garantee that the
unit test will work on other developers pcs and on the server as well.
In the tearDown part, I clean up the folder that I've created.
I have to do this in Java 5, but when looking at the File api for java
5, I only see the possibility to set the folder to readonly (method
setReadOnly()). But appearantly, in Win XP, when a folder is readonly,
it is still possible to create a file in it (tried it in the Windows
Explorer and it works there as well). So this doesn't give me my
IOException that I want. So I need to find a way to actually change
the folder permissions so that for the current user the folder is not
accessible. In Java 6, I see in the api that File has a lot more
methods: setReadable, setWriteable which probably would of help, if I
had Java 6.
Is there a way in Java 5 to modify the folder permissions in such a
way that is OS independent?
Veerle