Home | History | Annotate | Download | only in core
      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
     17     copesWithNullsAndUnknownTypes() {
     18         assertNullSafe(nullMatcher);
     19         assertUnknownTypeSafe(nullMatcher);
     20 
     21         assertNullSafe(notNullMatcher);
     22         assertUnknownTypeSafe(notNullMatcher);
     23     }
     24 
     25     @Test public void
     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
     35     supportsStaticTyping() {
     36         requiresStringMatcher(nullValue(String.class));
     37         requiresStringMatcher(notNullValue(String.class));
     38     }
     39 
     40     private void requiresStringMatcher(@SuppressWarnings("unused") Matcher<String> arg) {
     41         // no-op
     42     }
     43 }
     44