How can I mock java.time.LocalDate.now()
In your code, replace LocalDate.now() with LocalDate.now(clock);. You can then pass Clock.systemDefaultZone() for production and a fixed clock for testing. This is an example : First, inject the Clock. If you are using spring boot just do a : @Bean public Clock clock() { return Clock.systemDefaultZone(); } Second, call LocalDate.now(clock) in your code : @Component … Read more