time-test is a framework for testing time-based functionality.
Sometimes you have code with similar logic: "wait for 30 seconds and then do something if no changes are detected".
If you want to test such logic you should write something like this:
But what if you want to test logic which should be executed once per month? Or only on specific days?
time-test provides easy way to test such logic. For example, the code above can be written else:
This interface provides implementation of time-based methods. The default implementation forwards all calls to standard system methods.
XXXTimeProvider.start() to start using it. Don't forget to reset TimeProvider to default. Use
XXXTimeProvider.reset() for this.
UnsupportedOperationException on all method calls. It should be used for testing functionality which does not depend on time.
TestTimeProvider provides full access on time. Use
TestTimeProvider.inscreaseTime(millis) to change current time. Use
TestTimeProvider.waitUntilThreadsAreFrozen to wait until all threads complete their work.
You can pass your own configuration in
timetest.properties properties file. This file should be in classpath. Also you can pass properties to command line.
Configuration has 2 properties: *include - list of patterns in glob format, if any of this pattern applies processed class name then this class is transformed. * exclude - list of patterns in glob format, if any of this pattern not applies processed class name then this class is transformed. Overrides include** property.
Timetest is implemented as java agent and you should copy it to build directory and configure maven-surefire-plugin to use it for tests.