timemachine

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/

GroupId

GroupId

br.com.caelum
ArtifactId

ArtifactId

timemachine
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

jar
Description

Description

timemachine
Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/
Project URL

Project URL

http://github.com/caelum/timemachine
Source Code Management

Source Code Management

http://github.com/caelum/timemachine

Download timemachine

How to add to project

<!-- https://jarcasting.com/artifacts/br.com.caelum/timemachine/ -->
<dependency>
    <groupId>br.com.caelum</groupId>
    <artifactId>timemachine</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/br.com.caelum/timemachine/
implementation 'br.com.caelum:timemachine:1.0'
// https://jarcasting.com/artifacts/br.com.caelum/timemachine/
implementation ("br.com.caelum:timemachine:1.0")
'br.com.caelum:timemachine:jar:1.0'
<dependency org="br.com.caelum" name="timemachine" rev="1.0">
  <artifact name="timemachine" type="jar" />
</dependency>
@Grapes(
@Grab(group='br.com.caelum', module='timemachine', version='1.0')
)
libraryDependencies += "br.com.caelum" % "timemachine" % "1.0"
[br.com.caelum/timemachine "1.0"]

Dependencies

compile (1)

Group / Artifact Type Version
joda-time : joda-time jar 2.2

test (1)

Group / Artifact Type Version
junit : junit jar 4.8.2

Project Modules

There are no modules declared in this project.

TimeMachine

TimeMachine is a small library created to enable easy testing of code using JodaTime for date and time representation and has some logic depending upon getting the current date.

Usage

Suppose you have a ticket that should not be valid three days after its creation. You could write two tests for that:

@Test
public void should_be_valid_after_creation() {
    assertTrue(new Ticket().isValid());
}

@Test
public void should_not_be_valid_three_days_after_creation() {
    Ticket t = TimeMachine
                .goTo(new DateTime().minusDays(3))
                .andExecute(new Block<Ticket>() {
                    public Ticket run() {
                        return new Ticket();
                    }
                });
    assertFalse(t.isValid());
}

Inside the Block, a new instance of DateTime will be created pointing to three days ago, instead of pointing to the current date.

br.com.caelum

Caelum

Versions

Version
1.0