Reputation: 536
I'm using a third party library that works with java.io.File
instances. I'd like to use this library in my unit tests but I don't want it to create files on disk.
My first idea was to use JimFs to mock the file system but it does not support java.io.File.
My second idea was to mock File with some mocking framework and delegate calls to JimFs but don't know if that will work.
Is there some solution out there to use virtual java.io.File?
Upvotes: 7
Views: 1377
Reputation: 69339
You could use a JUnit TemporaryFolder
rule to easily create temporary files that are deleted after the test method is complete.
Upvotes: 2