Skip to content

Small hamcrest matcher which is waiting (with timeout) for the expected value

License

Notifications You must be signed in to change notification settings

YunaBraska/and-wait-matcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AndWait Matcher

Hamcrest matcher which is waiting (with a timeout) for the expected value

Build Maintainable Coverage Issues Commit Dependencies License Central Tag Javadoc Size Label Label

Usage

    assertThat(this::receiveMessage, andWait(is(equalTo("Howdy"))));
  • this matcher works with the default hamcrest "assertThat"
  • first parameter receives a function that will be called until the expected value is present (Success) or timeout (Exception) is received
  • you can define a custom timeout by using the second optional parameter of the "andWait" matcher
    assertThat(this::receiveMessage, andWait(is(equalTo("Howdy")), 500));

Matcher assertionError example

    Expected:
         but: [Timeout]
    Expected: is "unknown message"
         but: was "other message"

TODO

  • Feature instead of Thread.sleep(XY)
  • Only one AssertionError description instead of having two descriptions - first is a timeout and second is mismatch

andwait