Unitils Jodatime Module

This module freezes the current time, but be careful this only works with Jodatime.

Jodatime Module load artifact (maven)

    <dependency>
        <groupId>org.unitils.jodatime</groupId>
        <artifactId>unitils-jodatime</artifactId>
        <version>1.0.1</version>
    </dependency>

Jodatime Module project config

unitils.modules= database, easymock, datetime

unitils.module.datetime.className = org.unitils.jodatime.JodaTimeModule
unitils.module.datetime.runAfter = 
unitils.module.datetime.enabled = true

How does it work?
There are 2 annotations:

  • FixedDateTime: It freezes the date from a specific date.
  • OffsetDateTime: It freezes the date from a specific amount of days/months/years from now (positive = future, negative = past).

Example

@RunWith(UnitilsJUnit4TestClassRunner.class)
public class TestClass1 {

    @FixedDateTime(datetime="02/02/2005")
    @Test
    public void testFixedDateTime() {
       //the current date should be 2 february 2005
    }


    @OffsetDateTime(days=1)
    @Test
    public void testOffsetDateTime() throws Exception {
        //the current date should be the date from tomorrow.
    }
}
 

Last edit: Willemijn Wouters 2014-01-07