tea-time

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

Лицензия

Лицензия

Категории

Категории

Сеть
Группа

Группа

net.time4tea
Идентификатор

Идентификатор

tea-time
Последняя версия

Последняя версия

0.0.1
Дата

Дата

Тип

Тип

jar
Описание

Описание

tea-time
A small library to help you control time in your application, so you can test it
Ссылка на сайт

Ссылка на сайт

https://github.com/time4tea-net/tea-time
Система контроля версий

Система контроля версий

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

Скачать tea-time

Имя Файла Размер
tea-time-0.0.1.pom
tea-time-0.0.1.jar 5 KB
Обзор

Как подключить последнюю версию

<!-- 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"]

Зависимости

test (2)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.11
org.hamcrest : hamcrest-all jar 1.3

Модули Проекта

Данный проект не имеет модулей.

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

Версии библиотеки

Версия
0.0.1