|
1 | 1 | package org.hamcrest.text; |
2 | 2 |
|
3 | | -import static org.hamcrest.MatcherAssert.assertThat; |
4 | | -import static org.hamcrest.core.IsNot.not; |
| 3 | +import static org.hamcrest.AbstractMatcherTest.assertDescription; |
| 4 | +import static org.hamcrest.AbstractMatcherTest.assertDoesNotMatch; |
| 5 | +import static org.hamcrest.AbstractMatcherTest.assertMatches; |
| 6 | +import static org.hamcrest.AbstractMatcherTest.assertMismatchDescription; |
| 7 | +import static org.hamcrest.AbstractMatcherTest.assertNullSafe; |
| 8 | +import static org.hamcrest.AbstractMatcherTest.assertUnknownTypeSafe; |
5 | 9 | import static org.hamcrest.text.IsEmptyString.emptyOrNullString; |
6 | 10 | import static org.hamcrest.text.IsEmptyString.emptyString; |
7 | 11 |
|
8 | | -import org.hamcrest.AbstractMatcherTest; |
9 | 12 | import org.hamcrest.Matcher; |
10 | | - |
11 | | -public class IsEmptyStringTest extends AbstractMatcherTest { |
12 | | - |
13 | | - @Override |
14 | | - protected Matcher<?> createMatcher() { |
15 | | - return emptyOrNullString(); |
16 | | - } |
17 | | - |
18 | | - public void testEmptyOrNullIsNull() { |
19 | | - assertThat(null, emptyOrNullString()); |
20 | | - } |
21 | | - |
22 | | - |
23 | | - public void testEmptyIsNotNull() { |
24 | | - assertThat(null, not(emptyString())); |
25 | | - } |
26 | | - |
27 | | - public void testMatchesEmptyString() { |
28 | | - assertMatches("empty string", emptyString(), ""); |
29 | | - assertMatches("empty string", emptyOrNullString(), ""); |
30 | | - } |
31 | | - |
32 | | - public void testDoesNotMatchNonEmptyString() { |
33 | | - assertDoesNotMatch("non empty string", emptyString(), "a"); |
34 | | - } |
35 | | - |
36 | | - public void testHasAReadableDescription() { |
37 | | - assertDescription("an empty string", emptyString()); |
38 | | - assertDescription("(null or an empty string)", emptyOrNullString()); |
39 | | - } |
| 13 | +import org.junit.Test; |
| 14 | + |
| 15 | +public final class IsEmptyStringTest { |
| 16 | + |
| 17 | + @Test public void |
| 18 | + copesWithNullsAndUnknownTypes() { |
| 19 | + Matcher<String> matcher = emptyOrNullString(); |
| 20 | + |
| 21 | + assertNullSafe(matcher); |
| 22 | + assertUnknownTypeSafe(matcher); |
| 23 | + } |
| 24 | + |
| 25 | + @Test public void |
| 26 | + matchesNullAppropriately() { |
| 27 | + assertMatches("didn't match", emptyOrNullString(), null); |
| 28 | + assertDoesNotMatch("matched unexpectedly", emptyString(), null); |
| 29 | + } |
| 30 | + |
| 31 | + @Test public void |
| 32 | + matchesEmptyString() { |
| 33 | + assertMatches("didn't match", emptyOrNullString(), ""); |
| 34 | + assertMatches("didn't match", emptyString(), ""); |
| 35 | + } |
| 36 | + |
| 37 | + @Test public void |
| 38 | + doesNotmatchFilledString() { |
| 39 | + assertDoesNotMatch("matched unexpectedly", emptyOrNullString(), "a"); |
| 40 | + assertDoesNotMatch("matched unexpectedly", emptyString(), "a"); |
| 41 | + } |
| 42 | + |
| 43 | + @Test public void |
| 44 | + describesItself() { |
| 45 | + assertDescription("an empty string", emptyString()); |
| 46 | + assertDescription("(null or an empty string)", emptyOrNullString()); |
| 47 | + } |
| 48 | + |
| 49 | + @Test public void |
| 50 | + describesAMismatch() { |
| 51 | + assertMismatchDescription("was \"a\"", emptyString(), "a"); |
| 52 | + assertMismatchDescription("was \"a\"", emptyOrNullString(), "a"); |
| 53 | + } |
40 | 54 | } |
0 commit comments