
co.spraybot.testutils.FixedClockProvider Maven / Gradle / Ivy
package co.spraybot.testutils;
import java.time.Clock;
import java.time.LocalDateTime;
import java.time.ZoneId;
/**
* A Java 8 "trait" to allow easily providing a fixed moment in time to systems under test to more easily test working
* with date/time manipulation.
*
* @since 0.1.0
*/
public interface FixedClockProvider {
/**
* @return A Clock that uses the referenceTime() and the system's default ZoneId
*/
default Clock fixedClock() {
return Clock.fixed(referenceTime().atZone(ZoneId.systemDefault()).toInstant(), ZoneId.systemDefault());
}
/**
* @return A LocalDateTime that represents a fixed point in time
*/
default LocalDateTime referenceTime() {
return LocalDateTime.of(2015, 3, 2, 9, 0);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy