eventualj

Eventual assertions, for Java. Making asynchronous assertions elegant.

Categories

Categories

Ant Build Tools
GroupId

GroupId

no.antares
ArtifactId

ArtifactId

eventualj
Last Version

Last Version

0.5
Release Date

Release Date

Type

Type

jar
Description

Description

eventualj
Eventual assertions, for Java. Making asynchronous assertions elegant.
Project URL

Project URL

https://github.com/AntaTom/eventualj
Source Code Management

Source Code Management

https://github.com/AntaTom/eventualj

Download eventualj

How to add to project

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

Dependencies

compile (2)

Group / Artifact Type Version
com.googlecode.lambdaj : lambdaj jar 2.3.1
com.google.code.tempus-fugit : tempus-fugit jar 1.0

test (2)

Group / Artifact Type Version
junit : junit-dep jar 4.10
org.hamcrest : hamcrest-core jar 1.2

Project Modules

There are no modules declared in this project.

eventualj

Eventual assertions, for Java.
Making asynchronous assertions elegant.

What is eventualj

eventualj is an extension for hamcrest's Matchers that allows support for matching temporal values. Often you will come across such scenarios when testing multi-threaded applications.

Imagine the scenario where your application consumes messages from queues asynchronously. You want to test that when you put a message on the inbound queue it gets consumed. Because the message is consumed asynchronous you can't write an immediate assertion. Wouldn't it be nice if you could just write:

whenIPutAMessageOnThe(inboundQueue);
assertThat(eventually(inboundQueue).isEmpty(), willBe(true));

How it works

eventualj's eventually method returns a type safe proxy allowing you write a test asserting against the return value of one of its methods. Or more specifically, its eventual value.

Because the eventually proxy is type safe, you get all your usual IDE refactoring and autocompletion features for free.

Examples

assertThat(eventually(ten()).getValue(), willBe(10)); // passes
assertThat(ten().getValue(), is(10)); // fails, ten()'s value hasn't been set yet
assertThat(eventually(messageQueue).isEmpty(), willBe(true).within(millis(100))); // passes eventually

For a more complete example see the Queue producer and consumer example test here

Maven projects

eventualj isn't currently released in a public maven repository. If you want it, stop by and add a plus 1 to the issue

Versions

Version
0.5