I\'m writing some code that does date and time calculations against the current time. In Joda time, this is accessed through a (Java) constructor, as it is an immutable obje
We ended up creating dateService
with now()
method. In unit tests we mock it with
domainInstance.dateService = [ now: { currentTime } ] as DateService
where currentTime
is a unit test class field. This imposes everybody's dependency on dateService
(our only nearly-global dependency), and for src
classes one has to pass it by hand.
Unit tests, OTOH, look pretty clear with it.