|
9 | 9 | import org.hamcrest.Matcher;
|
10 | 10 |
|
11 | 11 | import static java.util.Arrays.asList;
|
12 |
| -import static org.hamcrest.collection.HasConsecutiveItems.hasConsecutiveItems; |
| 12 | +import static org.hamcrest.collection.HasSubsequence.hasSubsequence; |
13 | 13 | import static org.hamcrest.core.IsEqual.equalTo;
|
14 | 14 |
|
15 | 15 | @SuppressWarnings("unchecked")
|
16 |
| -public class HasConsecutiveItemsTest extends AbstractMatcherTest { |
17 |
| - private final Matcher<Collection<? extends WithValue>> contains123 = hasConsecutiveItems(value(1), value(2), value(3)); |
| 16 | +public class HasSubsequenceTest extends AbstractMatcherTest { |
| 17 | + private final Matcher<Collection<? extends WithValue>> contains123 = hasSubsequence(value(1), value(2), value(3)); |
18 | 18 |
|
19 | 19 | @Override
|
20 | 20 | protected Matcher<?> createMatcher() {
|
21 |
| - return hasConsecutiveItems(1, 2); |
| 21 | + return hasSubsequence(1, 2); |
22 | 22 | }
|
23 | 23 |
|
24 | 24 | public void testMatchingSingleItemCollection() throws Exception {
|
25 |
| - assertMatches("Single item iterable", hasConsecutiveItems(1), asList(1)); |
| 25 | + assertMatches("Single item iterable", hasSubsequence(1), asList(1)); |
26 | 26 | }
|
27 | 27 |
|
28 | 28 | public void testMatchingMultipleItemCollection() throws Exception {
|
29 |
| - assertMatches("Multiple item iterable", hasConsecutiveItems(1, 2, 3), asList(1, 2, 3)); |
| 29 | + assertMatches("Multiple item iterable", hasSubsequence(1, 2, 3), asList(1, 2, 3)); |
30 | 30 | }
|
31 | 31 |
|
32 | 32 | public void testMatchesWithMoreElementsThanExpectedAtBeginning() throws Exception {
|
33 |
| - assertMatches("More elements at beginning", hasConsecutiveItems(2, 3, 4), asList(1, 2, 3, 4)); |
| 33 | + assertMatches("More elements at beginning", hasSubsequence(2, 3, 4), asList(1, 2, 3, 4)); |
34 | 34 | }
|
35 | 35 |
|
36 | 36 | public void testMatchesWithMoreElementsThanExpectedAtEnd() throws Exception {
|
37 |
| - assertMatches("More elements at end", hasConsecutiveItems(1, 2, 3), asList(1, 2, 3, 4)); |
| 37 | + assertMatches("More elements at end", hasSubsequence(1, 2, 3), asList(1, 2, 3, 4)); |
38 | 38 | }
|
39 | 39 |
|
40 | 40 | public void testDoesNotMatchWithMoreElementsThanExpectedInBetween() throws Exception {
|
41 |
| - assertMismatchDescription("could not find items inside collection [<1>, <2>, <3>]", hasConsecutiveItems(1, 3), asList(1, 2, 3)); |
| 41 | + assertMismatchDescription("could not find subsequence inside collection [<1>, <2>, <3>]", hasSubsequence(1, 3), asList(1, 2, 3)); |
42 | 42 | }
|
43 | 43 |
|
44 | 44 | public void testMatchesSubSection() throws Exception {
|
45 |
| - assertMatches("Sub section of iterable", hasConsecutiveItems(2, 3), asList(1, 2, 3, 4)); |
| 45 | + assertMatches("Sub section of iterable", hasSubsequence(2, 3), asList(1, 2, 3, 4)); |
46 | 46 | }
|
47 | 47 |
|
48 | 48 | public void testDoesNotMatchWithFewerElementsThanExpected() throws Exception {
|
49 | 49 | List<WithValue> valueList = asList(make(1), make(2));
|
50 |
| - assertMismatchDescription("could not find items inside collection [<WithValue 1>, <WithValue 2>]", contains123, valueList); |
| 50 | + assertMismatchDescription("could not find subsequence inside collection [<WithValue 1>, <WithValue 2>]", contains123, valueList); |
51 | 51 | }
|
52 | 52 |
|
53 | 53 | public void testDoesNotMatchIfSingleItemNotFound() throws Exception {
|
54 |
| - assertMismatchDescription("could not find items inside collection [<WithValue 3>]", hasConsecutiveItems(value(4)), asList(make(3))); |
| 54 | + assertMismatchDescription("could not find subsequence inside collection [<WithValue 3>]", hasSubsequence(value(4)), asList(make(3))); |
55 | 55 | }
|
56 | 56 |
|
57 | 57 | public void testDoesNotMatchIfOneOfMultipleItemsNotFound() throws Exception {
|
58 |
| - assertMismatchDescription("could not find items inside collection [<WithValue 1>, <WithValue 2>, <WithValue 4>]", contains123, asList(make(1), make(2), make(4))); |
| 58 | + assertMismatchDescription("could not find subsequence inside collection [<WithValue 1>, <WithValue 2>, <WithValue 4>]", contains123, asList(make(1), make(2), make(4))); |
59 | 59 | }
|
60 | 60 |
|
61 | 61 | public void testDoesNotMatchEmptyCollection() throws Exception {
|
62 |
| - assertMismatchDescription("could not find items inside collection []", hasConsecutiveItems(value(4)), new ArrayList<WithValue>()); |
| 62 | + assertMismatchDescription("could not find subsequence inside collection []", hasSubsequence(value(4)), new ArrayList<WithValue>()); |
63 | 63 | }
|
64 | 64 |
|
65 | 65 | public void testHasAReadableDescription() {
|
66 |
| - assertDescription("collection contains consecutive items matching [<1>, <2>]", hasConsecutiveItems(1, 2)); |
| 66 | + assertDescription("collection contains subsequence matching [<1>, <2>]", hasSubsequence(1, 2)); |
67 | 67 | }
|
68 | 68 |
|
69 | 69 | public static class WithValue {
|
|
0 commit comments