Skip to content

Commit 1ee2cd8

Browse files
committed
Rename HasConsecutiveItems to HasSubsequence
1 parent c84bbf0 commit 1ee2cd8

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

hamcrest-library/matchers.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<factory class="org.hamcrest.core.StringEndsWith"/>
2020

2121
<!-- Collection -->
22-
<factory class="org.hamcrest.collection.HasConsecutiveItems"/>
22+
<factory class="org.hamcrest.collection.HasSubsequence"/>
2323
<factory class="org.hamcrest.collection.IsArray"/>
2424
<factory class="org.hamcrest.collection.IsArrayContaining"/>
2525
<factory class="org.hamcrest.collection.IsArrayContainingInOrder"/>
@@ -63,4 +63,4 @@
6363
<!-- XML -->
6464
<factory class="org.hamcrest.xml.HasXPath"/>
6565

66-
</matchers>
66+
</matchers>

hamcrest-library/src/main/java/org/hamcrest/collection/HasConsecutiveItems.java renamed to hamcrest-library/src/main/java/org/hamcrest/collection/HasSubsequence.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@
1515
* Matches if a collection contains another collection's items in
1616
* consecutive order anywhere inside it.
1717
*/
18-
public class HasConsecutiveItems<T>
18+
public class HasSubsequence<T>
1919
extends TypeSafeDiagnosingMatcher<Collection<? extends T>> {
2020
private final List<Matcher<? super T>> matchers;
2121

22-
public HasConsecutiveItems(List<Matcher<? super T>> matchers) {
22+
public HasSubsequence(List<Matcher<? super T>> matchers) {
2323
this.matchers = matchers;
2424
}
2525

2626
@Override
2727
public boolean matchesSafely(
28-
Collection<? extends T> itemsToMatch,
28+
Collection<? extends T> subsequenceToMatch,
2929
Description mismatchDescription) {
30-
List<? extends T> itemsToMatchList = new ArrayList<T>(itemsToMatch);
30+
List<? extends T> subsequenceToMatchList = new ArrayList<T>(subsequenceToMatch);
3131

32-
for (int i = 0; i <= itemsToMatchList.size() - matchers.size(); i++) {
32+
for (int i = 0; i <= subsequenceToMatchList.size() - matchers.size(); i++) {
3333
boolean allMatchersMatched = true;
3434
for (int j = 0; j < matchers.size(); j++) {
3535
Matcher<? super T> matcher = matchers.get(j);
36-
if (!matcher.matches(itemsToMatchList.get(i + j))) {
36+
if (!matcher.matches(subsequenceToMatchList.get(i + j))) {
3737
allMatchersMatched = false;
3838
break;
3939
}
@@ -44,42 +44,42 @@ public boolean matchesSafely(
4444
}
4545

4646
mismatchDescription
47-
.appendText("could not find items inside collection ")
48-
.appendValueList("[", ", ", "]", itemsToMatch);
47+
.appendText("could not find subsequence inside collection ")
48+
.appendValueList("[", ", ", "]", subsequenceToMatch);
4949
return false;
5050
}
5151

5252
@Override
5353
public void describeTo(Description description) {
5454
description
55-
.appendText("collection contains consecutive items matching ")
55+
.appendText("collection contains subsequence matching ")
5656
.appendList("[", ", ", "]", matchers);
5757
}
5858

5959
@Factory
60-
public static <T> Matcher<Collection<? extends T>> hasConsecutiveItems(
60+
public static <T> Matcher<Collection<? extends T>> hasSubsequence(
6161
List<Matcher<? super T>> matchers) {
62-
return new HasConsecutiveItems<T>(matchers);
62+
return new HasSubsequence<T>(matchers);
6363
}
6464

6565
@Factory
66-
public static <T> Matcher<Collection<? extends T>> hasConsecutiveItems(
66+
public static <T> Matcher<Collection<? extends T>> hasSubsequence(
6767
Matcher<? super T>... matchers) {
68-
return hasConsecutiveItems(Arrays.asList(matchers));
68+
return hasSubsequence(Arrays.asList(matchers));
6969
}
7070

7171
@Factory
72-
public static <T> Matcher<Collection<? extends T>> hasConsecutiveItems(
72+
public static <T> Matcher<Collection<? extends T>> hasSubsequence(
7373
Iterable<? extends T> items) {
7474
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
7575
for (Object item : items) {
7676
matchers.add(equalTo(item));
7777
}
78-
return new HasConsecutiveItems<T>(matchers);
78+
return new HasSubsequence<T>(matchers);
7979
}
8080

8181
@Factory
82-
public static <T> Matcher<Collection<? extends T>> hasConsecutiveItems(T... elements) {
83-
return hasConsecutiveItems(Arrays.asList(elements));
82+
public static <T> Matcher<Collection<? extends T>> hasSubsequence(T... elements) {
83+
return hasSubsequence(Arrays.asList(elements));
8484
}
8585
}

hamcrest-library/src/test/java/org/hamcrest/collection/HasConsecutiveItemsTest.java renamed to hamcrest-library/src/test/java/org/hamcrest/collection/HasSubsequenceTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,61 +9,61 @@
99
import org.hamcrest.Matcher;
1010

1111
import static java.util.Arrays.asList;
12-
import static org.hamcrest.collection.HasConsecutiveItems.hasConsecutiveItems;
12+
import static org.hamcrest.collection.HasSubsequence.hasSubsequence;
1313
import static org.hamcrest.core.IsEqual.equalTo;
1414

1515
@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));
1818

1919
@Override
2020
protected Matcher<?> createMatcher() {
21-
return hasConsecutiveItems(1, 2);
21+
return hasSubsequence(1, 2);
2222
}
2323

2424
public void testMatchingSingleItemCollection() throws Exception {
25-
assertMatches("Single item iterable", hasConsecutiveItems(1), asList(1));
25+
assertMatches("Single item iterable", hasSubsequence(1), asList(1));
2626
}
2727

2828
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));
3030
}
3131

3232
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));
3434
}
3535

3636
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));
3838
}
3939

4040
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));
4242
}
4343

4444
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));
4646
}
4747

4848
public void testDoesNotMatchWithFewerElementsThanExpected() throws Exception {
4949
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);
5151
}
5252

5353
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)));
5555
}
5656

5757
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)));
5959
}
6060

6161
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>());
6363
}
6464

6565
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));
6767
}
6868

6969
public static class WithValue {

0 commit comments

Comments
 (0)