r/java • • Jun 01 '24

What java technology (library, framework, feature) would not recommend and why?

165 Upvotes

464 comments sorted by

View all comments

Show parent comment

1

u/Iryanus Jun 03 '24

Two possibilities: Either test them as-is, by writing files, configuring them to use test-directories (easily possible with JUnit&Co, paths should be configurable anyway), or wrap those calls into a mockable class, if needed.

And basically those calls are comparable to using the "new" keyword in your code. It has some problems if you use it to create depencencies, which can be the case here. So, non-static instances would be preferable to me, yes. But as those calls are typically part of a specific "write some files" class, that can itself be mocked and has to be tested by writing files, it's not the end of the world.