Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ClockMock #3

Open
ashleyfrieze opened this issue Nov 14, 2020 · 2 comments
Open

Add ClockMock #3

ashleyfrieze opened this issue Nov 14, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@ashleyfrieze
Copy link
Member

No description provided.

@ashleyfrieze
Copy link
Member Author

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.

  • Mockito 3 - has mockStatic but cannot mock System
  • Powermockito - depends on Mockito2 so isn't compatible with the mockito3 used natively here
  • EasyMock - dead
  • AspectJ - perhaps an option though may require some work for users of the library
  • JMockit - requires the app to be run with an agent flag
  • Instrument - java provides instrumentation options, but none of them fit here

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
Copy link
Member Author

My original idea for this was to provide a ClockStub - see 2c91fa6 - 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:

  • fixed time
  • fixed but with an auto increment by a given tick every time the clock is read

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

@ashleyfrieze ashleyfrieze added the enhancement New feature or request label Nov 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant