How to use matchesSafely method of org.hamcrest.TypeSafeDiagnosingMatcher class

Best junit code snippet using org.hamcrest.TypeSafeDiagnosingMatcher.matchesSafely

Run junit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1package org.hamcrest;
2
3import org.hamcrest.Description;
4import org.hamcrest.internal.ReflectiveTypeFinder;
5
6public abstract class TypeSafeDiagnosingMatcher<T> extends BaseMatcher<T> {
7    private static final ReflectiveTypeFinder TYPE_FINDER = new ReflectiveTypeFinder("matchesSafely", 2, 0);
8    private final Class<?> expectedType;
9
10    /* access modifiers changed from: protected */
11    public abstract boolean matchesSafely(T t, Description description);
12
13    protected TypeSafeDiagnosingMatcher(Class<?> expectedType2) {
14        this.expectedType = expectedType2;
15    }
16
17    protected TypeSafeDiagnosingMatcher(ReflectiveTypeFinder typeFinder) {
18        this.expectedType = typeFinder.findExpectedType(getClass());
19    }
20
21    protected TypeSafeDiagnosingMatcher() {
22        this(TYPE_FINDER);
23    }
24
25    @Override // org.hamcrest.Matcher
26    public final boolean matches(Object item) {
27        return item != null && this.expectedType.isInstance(item) && matchesSafely(item, new Description.NullDescription());
28    }
29
30    @Override // org.hamcrest.BaseMatcher, org.hamcrest.Matcher
31    public final void describeMismatch(Object item, Description mismatchDescription) {
32        if (item == null || !this.expectedType.isInstance(item)) {
33            super.describeMismatch(item, mismatchDescription);
34        } else {
35            matchesSafely(item, mismatchDescription);
36        }
37    }
38}
39
Full Screen
copy
1package org.hamcrest.core;
2
3import org.hamcrest.Description;
4import org.hamcrest.Matcher;
5import org.hamcrest.TypeSafeDiagnosingMatcher;
6
7public class Every<T> extends TypeSafeDiagnosingMatcher<Iterable<? extends T>> {
8    private final Matcher<? super T> matcher;
9
10    /* JADX DEBUG: Failed to find minimal casts for resolve overloaded methods, cast all args instead
11     method: MutableMD:(java.lang.Iterable, org.hamcrest.Description):boolean
12     arg types: [java.lang.Iterable<? extends T>, org.hamcrest.Description]
13     candidates:
14      org.hamcrest.core.Every.matchesSafely(java.lang.Object, org.hamcrest.Description):boolean
15      MutableMD:(java.lang.Object, org.hamcrest.Description):boolean
16      MutableMD:(java.lang.Iterable, org.hamcrest.Description):boolean */
17    @Override // org.hamcrest.TypeSafeDiagnosingMatcher
18    public /* bridge */ /* synthetic */ boolean matchesSafely(Object obj, Description description) {
19        return matchesSafely((Iterable) ((Iterable) obj), description);
20    }
21
22    public Every(Matcher<? super T> matcher2) {
23        this.matcher = matcher2;
24    }
25
26    public boolean matchesSafely(Iterable<? extends T> collection, Description mismatchDescription) {
27        for (T t : collection) {
28            if (!this.matcher.matches(t)) {
29                mismatchDescription.appendText("an item ");
30                this.matcher.describeMismatch(t, mismatchDescription);
31                return false;
32            }
33        }
34        return true;
35    }
36
37    @Override // org.hamcrest.SelfDescribing
38    public void describeTo(Description description) {
39        description.appendText("every item is ").appendDescriptionOf(this.matcher);
40    }
41
42    public static <U> Matcher<Iterable<? extends U>> everyItem(Matcher<U> itemMatcher) {
43        return new Every(itemMatcher);
44    }
45}
46
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in TypeSafeDiagnosingMatcher

Trigger matchesSafely code on LambdaTest Cloud Grid

Execute automation tests with matchesSafely on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)