I’m writing a test for a piece of code that has an IOException catch in it that I’m trying to cover. The try/catch looks something like this:
try { oos = new ObjectOutputStream(new FileOutputStream(cacheFileName)); } catch (IOException e) { LOGGER.error('Bad news!', e); } finally {
The easiest way seems to make FileOutputStream throw a FileNotFoundException, but perhaps I’m going about this all the wrong way.
Anyone out there have any tips?
From your comment:
Look at java.io.File.createTempFile. Use it to create the file and then delete it.
Probably pass it something like:
That should give you a unique name in a platform indendent manner that you can safely use without (much) fear of it existing.