webcompere / system-stubs

System Stubs - Test Doubles for Java System resources
MIT License
91 stars 11 forks source link

Add ClockMock #3

Open ashleyfrieze opened 3 years ago

ashleyfrieze commented 3 years ago

This is a lot more challenging than it first appears. Part of the challenge is avoiding the user of the library having to do a lot of things or depend on too specific versions of libraries.

Mocking Instant.now might be possible and Mockito3 could achieve that, though directing most of Instant's calls back to the proper implementation may be a minor challenge.

ashleyfrieze commented 3 years ago

My original idea for this was to provide a ClockStub - see https://github.com/webcompere/system-stubs/commit/2c91fa6156763f74ade7e60f87a2f2f309f5db44 - this would replace time as globally as possible (I'd rather hook into System.currentTimeMillis to get every possible time call). I had the idea of two modes:

While active I'd expect to be able to tell the ClockStub to change the time it returns.