I'm torn between using DI and static utility classes on my code.
I currently created a DateUtil static class that is only meant to be accessed statically. This class is responsible for just creating and manipulating dates using a variety of libraries with absolutely no external 3rd party dependency.
Everything looks fine but now unit testing becomes messier since now we have to use PowerMockito to properly stub the behavior of the static class.
On the contrary, if I removed the static-ness of DateUtil and converted it into a Spring @Component, then now unit tests can be a tad bit easier, however, now we have all these dependencies everywhere and I'm not sure that this is the purpose of Spring managed beans.
How should I proceed with this? Is it okay to using Spring beans everywhere and just forget about static code entirely? Is it okay to abuse Spring's DI capabilities? When is it "too much DI"?
[the problem is that] the unit test for the code calling the static method inevitably also tests the static method
-- I don't understand what you meant there. Isn't the whole point to test the static method? – Robert Harvey Feb 08 '18 at 16:13new Date
with no arguments will usually yield two different values. Which is unpredictable and makes unit testing more difficult. – Andy Feb 08 '18 at 17:07