package org.hamcrest.text;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsNot.not;
import static org.hamcrest.text.IsEmptyString.emptyOrNullString;
import static org.hamcrest.text.IsEmptyString.emptyString;

import org.hamcrest.AbstractMatcherTest;
import org.hamcrest.Matcher;

public class IsEmptyStringTest extends AbstractMatcherTest {

  @Override
  protected Matcher<?> createMatcher() {
    return emptyOrNullString();
  }

  public void testEmptyOrNullIsNull() {
    assertThat(null, emptyOrNullString());
  }


  public void testEmptyIsNotNull() {
    assertThat(null, not(emptyString()));
  }

  public void testMatchesEmptyString() {
    assertMatches("empty string", emptyString(), "");
    assertMatches("empty string", emptyOrNullString(), "");
  }

  public void testDoesNotMatchNonEmptyString() {
    assertDoesNotMatch("non empty string", emptyString(), "a");
  }

  public void testHasAReadableDescription() {
    assertDescription("an empty string", emptyString());
    assertDescription("(null or an empty string)", emptyOrNullString());
  }
}

package org.hamcrest.text;

import static org.hamcrest.AbstractMatcherTest.assertDescription;
import static org.hamcrest.AbstractMatcherTest.assertDoesNotMatch;
import static org.hamcrest.AbstractMatcherTest.assertMatches;
import static org.hamcrest.AbstractMatcherTest.assertMismatchDescription;
import static org.hamcrest.AbstractMatcherTest.assertNullSafe;
import static org.hamcrest.AbstractMatcherTest.assertUnknownTypeSafe;
import static org.hamcrest.text.IsEmptyString.emptyOrNullString;
import static org.hamcrest.text.IsEmptyString.emptyString;

import org.hamcrest.Matcher;
import org.junit.Test;

public final class IsEmptyStringTest {

    @Test public void
    copesWithNullsAndUnknownTypes() {
        Matcher<String> matcher = emptyOrNullString();
        
        assertNullSafe(matcher);
        assertUnknownTypeSafe(matcher);
    }

    @Test public void
    matchesNullAppropriately() {
        assertMatches("didn't match", emptyOrNullString(), null);
        assertDoesNotMatch("matched unexpectedly", emptyString(), null);
    }

    @Test public void
    matchesEmptyString() {
        assertMatches("didn't match", emptyOrNullString(), "");
        assertMatches("didn't match", emptyString(), "");
    }

    @Test public void
    doesNotmatchFilledString() {
        assertDoesNotMatch("matched unexpectedly", emptyOrNullString(), "a");
        assertDoesNotMatch("matched unexpectedly", emptyString(), "a");
    }

    @Test public void
    describesItself() {
        assertDescription("an empty string", emptyString());
        assertDescription("(null or an empty string)", emptyOrNullString());
    }

    @Test public void
    describesAMismatch() {
        assertMismatchDescription("was \"a\"", emptyString(), "a");
        assertMismatchDescription("was \"a\"", emptyOrNullString(), "a");
    }
}

Convert test to JUnit4 (and add mismatch description tests) in preparation for enhancement.
Convert test to JUnit4 (and add mismatch description tests) in preparation for enhancement.
