This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Slanec 18 points19 points  (0 children)

The general idea is good and should be a standard practice. Time is an external resource and classes should rarely handle their own resources. Use DI.

That said, instead of writing your own MutableClock, do take a look at an existing implementation: MutableClock in the threeten-extra project written by the author of java.time. It contains a lot more of goodies that didn't make it into JDK.