On 26/03/2010 08:12, Claus Ibsen wrote:
Its your stupidity to store files you want to keep in the TEMP folder.
I don't see much point in hurling abuse about it: you accept that your
code shouldn't delete files that it didn't create and I'll accept that I
ought to organise my files better.
Deal?
At least I have a clean slate to work from now :)
The test is supposed to be run manually and the test was disabled. But
unfortunately JUnit is so lame that it fails if a Test class have no
testXXX method and thus a testDummy was added. Which causes it to run
the setup method. I have fixed that so it wont delete the TEMP folder.
Although it is much less likely to affect anyone your fix is still
making assumptions and absolutely deleting a hardcoded path (and then
not deleting the path it creates after its finished).
You've also still got possible permissions problems because of the
hardcoded path (though again, less likely to be affected because default
permissions on Windows will allow you to create C:\Tmp even though they
shouldn't).
I prefer something like this:
private String getUniqueTempDir( ) {
try {
File tempFile = java.io.File.createTempFile(
"FileConsumerAbsoluteRootPathDefaultMoveTest", null );
tempFile.delete();
return tempFile.getAbsolutePath();
} catch( Exception ex ) {
return null;
}
}
@Override
protected void setUp() throws Exception {
base = getUniqueTempDir();
deleteDirectory(base);
super.setUp();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
deleteDirectory(base);
}
Jim