0

How to support hard aging of java.time date-time based system in Java 8?

I didn't find a way to inject fixed clock at one place for entire code base. Otherwise i need to change my code to either inject Clock in every place i get instant.

Testers wanted to validate year end,month end scenarios while running their scripts. I need to provide this feature through configuration which should to apply to entire application.

sreddy
  • 49
  • 3
  • 2
    What do you mean by **aging**? Every place you get `instant` you get the current time. – Elliott Frisch Apr 02 '16 at 23:06
  • 1
    Can you please give us a code example so we can help? – Willcodeforfun Apr 02 '16 at 23:09
  • 1
    I believe the OP is asking how to write the code that is testable (ie. "what happens in 30 years?"), where the time might not be exposed on individually testable surfaces. Using 'now' in code is common, but hardly .. fun to test. Related insofar as when pushed through: http://stackoverflow.com/questions/27067049/unit-testing-a-class-with-a-java-8-clock – user2864740 Apr 02 '16 at 23:13
  • (I'm personally a fan of DI/IoC for obtain 'now' in programs: this also ultimately pushes the timing source out as a configuration/mock.) – user2864740 Apr 02 '16 at 23:17
  • 1
    You could probably mock `Clock.systemDefaultZone()` but the standard way would be to use a Clock every time you call `Xxx.now()`... – assylias Apr 02 '16 at 23:29

0 Answers0