|
6 | 6 |
|
7 | 7 | import org.hamcrest.AbstractMatcherTest; |
8 | 8 | import org.hamcrest.Matcher; |
| 9 | +import org.junit.Test; |
9 | 10 |
|
10 | 11 |
|
11 | 12 | public class StringContainsTest extends AbstractMatcherTest { |
12 | 13 | static final String EXCERPT = "EXCERPT"; |
13 | | - Matcher<String> stringContains = containsString(EXCERPT); |
| 14 | + final Matcher<String> stringContains = containsString(EXCERPT); |
14 | 15 |
|
15 | 16 | @Override |
16 | 17 | protected Matcher<?> createMatcher() { |
17 | 18 | return stringContains; |
18 | 19 | } |
19 | 20 |
|
20 | | - public void testEvaluatesToTrueIfArgumentContainsSpecifiedSubstring() { |
21 | | - assertTrue("should be true if excerpt at beginning", |
22 | | - stringContains.matches(EXCERPT + "END")); |
23 | | - assertTrue("should be true if excerpt at end", |
24 | | - stringContains.matches("START" + EXCERPT)); |
25 | | - assertTrue("should be true if excerpt in middle", |
26 | | - stringContains.matches("START" + EXCERPT + "END")); |
27 | | - assertTrue("should be true if excerpt is repeated", |
28 | | - stringContains.matches(EXCERPT + EXCERPT)); |
29 | | - |
30 | | - assertFalse("should not be true if excerpt is not in string", |
31 | | - stringContains.matches("Something else")); |
32 | | - assertFalse("should not be true if part of excerpt is in string", |
33 | | - stringContains.matches(EXCERPT.substring(1))); |
| 21 | + public void testMatchesSubstrings() { |
| 22 | + assertMatches(stringContains, EXCERPT + "END"); |
| 23 | + assertMatches(stringContains, "START" + EXCERPT); |
| 24 | + assertMatches(stringContains, "START" + EXCERPT + "END"); |
| 25 | + assertMatches(stringContains, EXCERPT + EXCERPT); |
| 26 | + assertMismatchDescription("was \"Something else\"", stringContains, "Something else"); |
| 27 | + assertMismatchDescription("was \"XC\"", stringContains, "XC"); |
34 | 28 | } |
35 | 29 |
|
36 | | - public void testEvaluatesToTrueIfArgumentIsEqualToSubstring() { |
37 | | - assertTrue("should be true if excerpt is entire string", |
38 | | - stringContains.matches(EXCERPT)); |
39 | | - } |
40 | 30 |
|
41 | 31 | public void testHasAReadableDescription() { |
42 | 32 | assertDescription("a string containing \"EXCERPT\"", stringContains); |
|
0 commit comments