metrimer
metrimer

Reputation: 536

Mock java.io.File with an in-memory FileSystem. Maybe JimFs

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

Answers (1)

Duncan Jones
Duncan Jones

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

Related Questions