ncredinburgh / JavaForSmallTeams

Guidance on writing "good" server side java
https://www.gitbook.com/book/ncrcoe/java-for-small-teams
Other
69 stars 31 forks source link

Existing date/time dependency - Java 8 Clock #4

Closed arend-von-reinersdorff closed 8 years ago

arend-von-reinersdorff commented 8 years ago

Regarding unit testing and date/time https://ncrcoe.gitbooks.io/java-for-small-teams/content/tests/2300_testing_FAQS.html

There's a new class java.time.Clock available for this in Java 8. With static methods systemDefaultZone() for production and fixed() to get a fixed() time for unit tests.

Joda Time has MillisProvider. Unfortunately it's only an interface so one has to implement a production implementation for the current time oneself.

hcoles commented 8 years ago

Thanks - Clock is definitely worth mentioning.

As the purpose of MillisProvider seems to be update some static state within joda time I think it is probably better not to point people towards it. An explicit dependency on a strategy that provides the current time would be better.

hcoles commented 8 years ago

@arend-von-reinersdorff Is there anything you'd like to add on this or should I close the issue?

arend-von-reinersdorff commented 8 years ago

Very nice - thanks for the update :-)