eventually-matchers

Simple asynchronous hamcrest matchers

License

License

MIT
Categories

Categories

Ant Build Tools
GroupId

GroupId

com.github.grantwest.eventually
ArtifactId

ArtifactId

hamcrest-eventually-matchers
Last Version

Last Version

0.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

eventually-matchers
Simple asynchronous hamcrest matchers
Project URL

Project URL

https://github.com/grantwest/eventually-matchers
Source Code Management

Source Code Management

https://github.com/grantwest/eventually-matchers

Download hamcrest-eventually-matchers

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.grantwest.eventually/hamcrest-eventually-matchers/ -->
<dependency>
    <groupId>com.github.grantwest.eventually</groupId>
    <artifactId>hamcrest-eventually-matchers</artifactId>
    <version>0.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.grantwest.eventually/hamcrest-eventually-matchers/
implementation 'com.github.grantwest.eventually:hamcrest-eventually-matchers:0.0.3'
// https://jarcasting.com/artifacts/com.github.grantwest.eventually/hamcrest-eventually-matchers/
implementation ("com.github.grantwest.eventually:hamcrest-eventually-matchers:0.0.3")
'com.github.grantwest.eventually:hamcrest-eventually-matchers:jar:0.0.3'
<dependency org="com.github.grantwest.eventually" name="hamcrest-eventually-matchers" rev="0.0.3">
  <artifact name="hamcrest-eventually-matchers" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.grantwest.eventually', module='hamcrest-eventually-matchers', version='0.0.3')
)
libraryDependencies += "com.github.grantwest.eventually" % "hamcrest-eventually-matchers" % "0.0.3"
[com.github.grantwest.eventually/hamcrest-eventually-matchers "0.0.3"]

Dependencies

compile (1)

Group / Artifact Type Version
org.hamcrest : java-hamcrest jar 2.0.0.0

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Easy asynchronous asserts with JUnit & Hamcrest

Usage

These matchers are available via Maven Central. Add this to your pom.xml:

<dependency>
  <groupId>com.github.grantwest.eventually</groupId>
   <artifactId>hamcrest-eventually-matchers</artifactId>
   <version>0.0.3</version>
   <scope>test</scope>
</dependency>

Lets say another thread is supposed to add an element to a collection:

Collection<String> listOfNames; //Collection other thread is adding names to
assertThat(listOfNames, eventually(hasItem("Grant")));

To test a value we use a lambda:

boolean b = false; //Some other thread will set b to true
assertThat(() -> b, eventuallyEval(is(true)));

The eventually matchers have a default timeout of 5 seconds. The timeout can be overridden like this:

assertThat(() -> b, eventuallyEval(is(true), Duration.ofSeconds(30)));

To assert that someFunction() eventually returns true:

assertThat(() -> someFunction(), eventuallyEval(is(true)));

The matchers are known to work with:

  • junit 4.12
  • java-hamcrest 2.0.0.0

Versions

Version
0.0.3
0.0.1