How to use appendValue method of org.hamcrest.Description.NullDescription class

Best junit code snippet using org.hamcrest.Description.NullDescription.appendValue

Run junit automation tests on LambdaTest cloud grid

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

copy
1public final class org.hamcrest.Description$NullDescription implements org.hamcrest.Description {
2  public org.hamcrest.Description$NullDescription();
3  public org.hamcrest.Description appendDescriptionOf(org.hamcrest.SelfDescribing);
4  public org.hamcrest.Description appendList(java.lang.String, java.lang.String, java.lang.String, java.lang.Iterable<? extends org.hamcrest.SelfDescribing>);
5  public org.hamcrest.Description appendText(java.lang.String);
6  public org.hamcrest.Description appendValue(java.lang.Object);
7  public <T> org.hamcrest.Description appendValueList(java.lang.String, java.lang.String, java.lang.String, T...);
8  public <T> org.hamcrest.Description appendValueList(java.lang.String, java.lang.String, java.lang.String, java.lang.Iterable<T>);
9  public java.lang.String toString();
10}
11
Full Screen
copy
1package org.hamcrest;
2
3import org.hamcrest.internal.ReflectiveTypeFinder;
4
5
6/**
7 * Convenient base class for Matchers that require a non-null value of a specific type
8 * and that will report why the received value has been rejected.
9 * This implements the null check, checks the type and then casts. 
10 * To use, implement <pre>matchesSafely()</pre>. 
11 *
12 * @param <T>
13 * @author Neil Dunn
14 * @author Nat Pryce
15 * @author Steve Freeman
16 */
17public abstract class TypeSafeDiagnosingMatcher<T> extends BaseMatcher<T> {
18    private static final ReflectiveTypeFinder TYPE_FINDER = new ReflectiveTypeFinder("matchesSafely", 2, 0); 
19    private final Class<?> expectedType;
20
21    /**
22     * Subclasses should implement this. The item will already have been checked
23     * for the specific type and will never be null.
24     */
25    protected abstract boolean matchesSafely(T item, Description mismatchDescription);
26
27    /**
28     * Use this constructor if the subclass that implements <code>matchesSafely</code> 
29     * is <em>not</em> the class that binds &lt;T&gt; to a type. 
30     * @param expectedType The expectedType of the actual value.
31     */
32    protected TypeSafeDiagnosingMatcher(Class<?> expectedType) {
33      this.expectedType = expectedType;
34    }
35
36    /**
37     * Use this constructor if the subclass that implements <code>matchesSafely</code> 
38     * is <em>not</em> the class that binds &lt;T&gt; to a type. 
39     * @param typeFinder A type finder to extract the type
40     */
41    protected TypeSafeDiagnosingMatcher(ReflectiveTypeFinder typeFinder) {
42      this.expectedType = typeFinder.findExpectedType(getClass()); 
43    }
44
45    /**
46     * The default constructor for simple sub types
47     */
48    protected TypeSafeDiagnosingMatcher() {
49      this(TYPE_FINDER); 
50    }
51
52    @Override
53    @SuppressWarnings("unchecked")
54    public final boolean matches(Object item) {
55        return item != null
56            && expectedType.isInstance(item)
57            && matchesSafely((T) item, new Description.NullDescription());
58    }
59
60    @SuppressWarnings("unchecked")
61    @Override
62    public final void describeMismatch(Object item, Description mismatchDescription) {
63      if (item == null) {
64        mismatchDescription.appendText("was null");
65    } else if (!expectedType.isInstance(item)) {
66      mismatchDescription.appendText("was ")
67            .appendText(item.getClass().getSimpleName())
68            .appendText(" ")
69            .appendValue(item);
70    } else {
71        matchesSafely((T) item, mismatchDescription);
72      }
73    }
74}
75
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 Description.NullDescription

Trigger appendValue code on LambdaTest Cloud Grid

Execute automation tests with appendValue 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)