|
1 | 1 | package org.hamcrest.object; |
2 | 2 |
|
| 3 | +import static org.hamcrest.AbstractMatcherTest.assertDescription; |
| 4 | +import static org.hamcrest.AbstractMatcherTest.assertDoesNotMatch; |
| 5 | +import static org.hamcrest.AbstractMatcherTest.assertMismatchDescription; |
| 6 | +import static org.hamcrest.AbstractMatcherTest.assertNullSafe; |
| 7 | +import static org.hamcrest.AbstractMatcherTest.assertUnknownTypeSafe; |
3 | 8 | import static org.junit.Assert.assertThat; |
4 | 9 |
|
5 | 10 | import java.util.regex.Pattern; |
6 | 11 |
|
7 | | -import org.hamcrest.AbstractMatcherTest; |
8 | 12 | import org.hamcrest.Matcher; |
9 | 13 | import org.hamcrest.text.MatchesPattern; |
| 14 | +import org.junit.Test; |
10 | 15 |
|
11 | | -public class MatchesPatternTest extends AbstractMatcherTest { |
| 16 | +public class MatchesPatternTest { |
| 17 | + @Test |
| 18 | + public void copesWithNullsAndUnknownTypes() { |
| 19 | + Matcher<String> matcher = new MatchesPattern(Pattern.compile(".")); |
12 | 20 |
|
13 | | - @Override |
14 | | - protected Matcher<?> createMatcher() { |
15 | | - return new MatchesPattern(Pattern.compile(".")); |
| 21 | + assertNullSafe(matcher); |
| 22 | + assertUnknownTypeSafe(matcher); |
16 | 23 | } |
17 | 24 |
|
18 | | - public void testMatchesExactMatch() { |
| 25 | + @Test |
| 26 | + public void matchesExactString() { |
19 | 27 | assertThat("a", new MatchesPattern(Pattern.compile("a"))); |
20 | 28 | } |
21 | 29 |
|
22 | | - public void testDoesNotMatchesDifferentString() { |
| 30 | + @Test |
| 31 | + public void doesNotMatchesDifferentString() { |
23 | 32 | assertDoesNotMatch("A different string does not match", new MatchesPattern(Pattern.compile("a")), "b"); |
24 | 33 | } |
25 | 34 |
|
26 | | - public void testDoesNotMatchSubstring() { |
| 35 | + @Test |
| 36 | + public void doesNotMatchSubstring() { |
27 | 37 | assertDoesNotMatch("A substring does not match", new MatchesPattern(Pattern.compile("a")), "ab"); |
28 | 38 | } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void hasAReadableDescription() { |
| 42 | + Matcher<?> m = new MatchesPattern(Pattern.compile("a[bc](d|e)")); |
| 43 | + assertDescription("a string matching the pattern 'a[bc](d|e)'", m ); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void describesAMismatch() { |
| 48 | + final Matcher<String> matcher = new MatchesPattern(Pattern.compile("a")); |
| 49 | + assertMismatchDescription("was \"Cheese\"", matcher, "Cheese"); |
| 50 | + } |
29 | 51 | } |
0 commit comments