Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eventually matcher. #2

Open
tobyclemson opened this issue Sep 11, 2012 · 0 comments
Open

Add eventually matcher. #2

tobyclemson opened this issue Sep 11, 2012 · 0 comments

Comments

@tobyclemson
Copy link
Member

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(...);
       }
   }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant