tea-time

A small library to help you control time in your application, so you can test it

License

License

Categories

Categories

Net
GroupId

GroupId

net.time4tea
ArtifactId

ArtifactId

tea-time
Last Version

Last Version

0.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

tea-time
A small library to help you control time in your application, so you can test it
Project URL

Project URL

https://github.com/time4tea-net/tea-time
Source Code Management

Source Code Management

https://github.com/time4tea-net/tea-time.git

Download tea-time

How to add to project

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

Dependencies

test (2)

Group / Artifact Type Version
junit : junit jar 4.11
org.hamcrest : hamcrest-all jar 1.3

Project Modules

There are no modules declared in this project.

tea-time

Codeship Status for time4tea-net/tea-time

Download

What is it

A collection of test friendly implementations of time for Java 8

  • Executor

  • ScheduledExecutorService

  • Clock as an interface

This allows the developer to test code that uses ScheduledExecutorService without starting up threads, and control the passage of time properly.

It doesn't just execute the Runnables synchronously, as this gives a false impression of the ordering of events in the system - if you do this, a get() right after a submit() will always work in tests, but never under a real ScheduledExecutorService

Clock

How to use

Don't use the java 8 clock in your code, you cannot control the passage of time properly

Use a tea-time Clock.

How to use in tests

Clock clock = TickingClock.atUTC("2017/10/02 10:23:44.000")

MyClass myClass = new MyClass(clock);

myClass.recordTimestamp();

clock.timePasses(Duration.ofSeconds(23));

myClass.recordTimestamp();

SimpleExecutorServices

You can pretty much replace any usage of ScheduledExecutorService with a SimpleScheduledExecutorService, then use a ControllableSimpleScheduledExecutorService in your code like this

How to use in tests

ControllableSimpleScheduledExecutorService service = new ControllableSimpleScheduledExecutorService();
MyClass myClass = new MyClass(service);

myClass.doSomething(); // schedules a task...

// assert nothing happened yet

service.timePasses(Duration.ofHours(1));

// assert what should have happened.

How to use for real

ScheduledExecutorService service = Executors....();
MyClass myClass = new MyClass(SimpleExecutorServices.wrapping(service));
net.time4tea

time4tea technology ltd

Versions

Version
0.0.1