|
4 | 4 | import org.hamcrest.Matcher;
|
5 | 5 |
|
6 | 6 | import static java.util.Arrays.asList;
|
| 7 | +import static org.hamcrest.text.StringContainsInOrder.stringContainsInOrder; |
7 | 8 |
|
8 | 9 |
|
9 | 10 | public class StringContainsInOrderTest extends AbstractMatcherTest {
|
10 |
| - StringContainsInOrder m = new StringContainsInOrder(asList("a", "b", "c", "c")); |
| 11 | + final StringContainsInOrder matcher = new StringContainsInOrder(asList("a", "b", "c", "c")); |
11 | 12 |
|
12 | 13 | @Override
|
13 | 14 | protected Matcher<?> createMatcher() {
|
14 |
| - return m; |
| 15 | + return matcher; |
15 | 16 | }
|
16 | 17 |
|
17 | 18 | public void testMatchesOnlyIfStringContainsGivenSubstringsInTheSameOrder() {
|
18 |
| - assertMatches("substrings in order", m, "abcc"); |
19 |
| - assertMatches("substrings separated", m, "1a2b3c4c5"); |
20 |
| - |
21 |
| - assertDoesNotMatch("substrings in order missing a repeated pattern", m, "abc"); |
22 |
| - assertDoesNotMatch("substrings out of order", m, "cab"); |
23 |
| - assertDoesNotMatch("no substrings in string", m, "xyz"); |
24 |
| - assertDoesNotMatch("substring missing", m, "ac"); |
25 |
| - assertDoesNotMatch("empty string", m, ""); |
| 19 | + assertMatches("substrings in order", matcher, "abcc"); |
| 20 | + assertMatches("substrings separated", matcher, "1a2b3c4c5"); |
| 21 | + |
| 22 | + assertDoesNotMatch("can detect repeated strings for matching", stringContainsInOrder("abc", "abc"), "---abc---"); |
| 23 | + assertDoesNotMatch("substrings in order missing a repeated pattern", matcher, "abc"); |
| 24 | + assertDoesNotMatch("substrings out of order", matcher, "cab"); |
| 25 | + assertDoesNotMatch("no substrings in string", matcher, "xyz"); |
| 26 | + assertDoesNotMatch("substring missing", matcher, "ac"); |
| 27 | + assertDoesNotMatch("empty string", matcher, ""); |
26 | 28 | }
|
27 | 29 |
|
28 | 30 | public void testHasAReadableDescription() {
|
29 |
| - assertDescription("a string containing \"a\", \"b\", \"c\", \"c\" in order", m); |
| 31 | + assertDescription("a string containing \"a\", \"b\", \"c\", \"c\" in order", matcher); |
30 | 32 | }
|
31 | 33 | }
|
0 commit comments