Skip to content

Add eventually matcher. #2

Description

@tobyclemson

See Funk for resultOfSampling, Sampler and CompletableSample.

public static Matcher<? super T> eventually(Matcher<? super T> matcher) {
   return new TypeSafeDiagnosingMatcher<T>() {
       @Override
       public boolean matchesSafely(T item, Description description) {
           boolean matchedSuccessfully = resultOfSampling(new Sampler<Boolean>() {
               @Override
               public Boolean takeSample() {
                   return matcher.matches(item);
               }

               @Override
               public boolean isComplete(Boolean sample) {
                   return sample;
               }
           }
           if(!matchedSuccessfully) {
               description.appendText(...);
               return false;
           }
           return true;
       }

       @Override
       public void describeTo(Description description) {
           description.appendText(...);
       }
   }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions