xref: /aosp_15_r20/external/hamcrest/hamcrest-core/src/test/java/org/hamcrest/core/IsNullTest.java (revision 13e4719e1a36da4ffe406e4545ee2b1694a8da4f)
1 package org.hamcrest.core;
2 
3 import org.hamcrest.Matcher;
4 import org.junit.Test;
5 
6 import static org.hamcrest.AbstractMatcherTest.*;
7 import static org.hamcrest.core.IsNull.notNullValue;
8 import static org.hamcrest.core.IsNull.nullValue;
9 
10 
11 public final class IsNullTest {
12 
13     private final Matcher<Object> nullMatcher = nullValue();
14     private final Matcher<Object> notNullMatcher = notNullValue();
15 
16     @Test public void
copesWithNullsAndUnknownTypes()17     copesWithNullsAndUnknownTypes() {
18         assertNullSafe(nullMatcher);
19         assertUnknownTypeSafe(nullMatcher);
20 
21         assertNullSafe(notNullMatcher);
22         assertUnknownTypeSafe(notNullMatcher);
23     }
24 
25     @Test public void
evaluatesToTrueIfArgumentIsNull()26     evaluatesToTrueIfArgumentIsNull() {
27         assertMatches(nullMatcher, null);
28         assertDoesNotMatch(nullMatcher, new Object());
29 
30         assertMatches(notNullMatcher, new Object());
31         assertDoesNotMatch(notNullMatcher, null);
32     }
33 
34     @Test public void
supportsStaticTyping()35     supportsStaticTyping() {
36         requiresStringMatcher(nullValue(String.class));
37         requiresStringMatcher(notNullValue(String.class));
38     }
39 
requiresStringMatcher(@uppressWarnings"unused") Matcher<String> arg)40     private void requiresStringMatcher(@SuppressWarnings("unused") Matcher<String> arg) {
41         // no-op
42     }
43 }
44