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.Is.is;
      8 import static org.hamcrest.core.Is.isA;
      9 import static org.hamcrest.core.IsEqual.equalTo;
     10 
     11 public final class IsTest {
     12 
     13     @Test public void
     14     copesWithNullsAndUnknownTypes() {
     15         Matcher<String> matcher = is("something");
     16 
     17         assertNullSafe(matcher);
     18         assertUnknownTypeSafe(matcher);
     19     }
     20 
     21     @Test public void
     22     matchesTheSameWayTheUnderlyingMatcherDoes() {
     23         final Matcher<Boolean> matcher = is(equalTo(true));
     24 
     25         assertMatches(matcher, true);
     26         assertDoesNotMatch(matcher, false);
     27     }
     28 
     29     @Test public void
     30     generatesIsPrefixInDescription() {
     31         assertDescription("is <true>", is(equalTo(true)));
     32         assertDescription("is \"A\"", is("A"));
     33     }
     34 
     35     @Test public void
     36     providesConvenientShortcutForIsEqualTo() {
     37         final Matcher<String> matcher = is("A");
     38 
     39         assertMatches(matcher, "A");
     40         assertDoesNotMatch(is("A"), "B");
     41     }
     42 
     43     @SuppressWarnings({ "unchecked", "rawtypes" })
     44     @Test public void
     45     providesConvenientShortcutForIsInstanceOf() {
     46         final Matcher matcher = isA(Integer.class);
     47         assertMatches(matcher, 1);
     48         assertDoesNotMatch(matcher, new Object());
     49         assertDoesNotMatch(matcher, null);
     50     }
     51 }
     52