Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

grantwest/eventually-matchers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Asynchronous matchers for Hamcrest & JUnit

Resources

License

Stars

Watchers

Forks

Packages

No packages published