Package org.hamcrest.collection
Class IsIterableContainingInRelativeOrder<E>
java.lang.Object
org.hamcrest.BaseMatcher<Iterable<? extends E>>
org.hamcrest.TypeSafeDiagnosingMatcher<Iterable<? extends E>>
org.hamcrest.collection.IsIterableContainingInRelativeOrder<E>
- Type Parameters:
E- the type of items in the iterable.
- All Implemented Interfaces:
Matcher<Iterable<? extends E>>,SelfDescribing
public class IsIterableContainingInRelativeOrder<E>
extends TypeSafeDiagnosingMatcher<Iterable<? extends E>>
Tests if an iterable contains matching elements in relative order.
-
Constructor Summary
ConstructorsConstructorDescriptionIsIterableContainingInRelativeOrder(List<Matcher<? super E>> matchers) Constructor, best called fromcontainsInRelativeOrder(Object[]),containsInRelativeOrder(Matcher[]), orcontainsInRelativeOrder(List). -
Method Summary
Modifier and TypeMethodDescriptioncontainsInRelativeOrder(E... items) containsInRelativeOrder(List<Matcher<? super E>> itemMatchers) containsInRelativeOrder(Matcher<? super E>... itemMatchers) voiddescribeTo(Description description) Generates a description of the object.protected booleanmatchesSafely(Iterable<? extends E> iterable, Description mismatchDescription) Subclasses should implement this.Methods inherited from class org.hamcrest.TypeSafeDiagnosingMatcher
describeMismatch, matchesMethods inherited from class org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
-
Constructor Details
-
IsIterableContainingInRelativeOrder
Constructor, best called fromcontainsInRelativeOrder(Object[]),containsInRelativeOrder(Matcher[]), orcontainsInRelativeOrder(List).- Parameters:
matchers- the matchers
-
-
Method Details
-
matchesSafely
Description copied from class:TypeSafeDiagnosingMatcherSubclasses should implement this. The item will already have been checked for the specific type and will never be null.- Specified by:
matchesSafelyin classTypeSafeDiagnosingMatcher<Iterable<? extends E>>- Parameters:
iterable- the item.mismatchDescription- the mismatch description.- Returns:
- boolean true/false depending if item matches matcher.
-
describeTo
Description copied from interface:SelfDescribingGenerates a description of the object. The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.- Parameters:
description- The description to be built or appended to.
-
containsInRelativeOrder
Creates a matcher forIterables that matches when a single pass over the examinedIterableyields a series of items, that contains items logically equal to the corresponding item in the specified items, in the same relative order For example:assertThat(Arrays.asList("a", "b", "c", "d", "e"), containsInRelativeOrder("b", "d"))- Type Parameters:
E- the matcher type.- Parameters:
items- the items that must be contained within items provided by an examinedIterablein the same relative order- Returns:
- The matcher.
-
containsInRelativeOrder
@SafeVarargs public static <E> Matcher<Iterable<? extends E>> containsInRelativeOrder(Matcher<? super E>... itemMatchers) Creates a matcher forIterables that matches when a single pass over the examinedIterableyields a series of items, that each satisfying the corresponding matcher in the specified matchers, in the same relative order. For example:assertThat(Arrays.asList("a", "b", "c", "d", "e"), containsInRelativeOrder(equalTo("b"), equalTo("d")))- Type Parameters:
E- the matcher type.- Parameters:
itemMatchers- the matchers that must be satisfied by the items provided by an examinedIterablein the same relative order- Returns:
- The matcher.
-
containsInRelativeOrder
public static <E> Matcher<Iterable<? extends E>> containsInRelativeOrder(List<Matcher<? super E>> itemMatchers) Creates a matcher forIterables that matches when a single pass over the examinedIterableyields a series of items, that contains items satisfying the corresponding matcher in the specified list of matchers, in the same relative order. For example:assertThat(Arrays.asList("a", "b", "c", "d", "e"), contains(Arrays.asList(equalTo("b"), equalTo("d"))))- Type Parameters:
E- the matcher type.- Parameters:
itemMatchers- a list of matchers, each of which must be satisfied by the items provided by an examinedIterablein the same relative order- Returns:
- The matcher.
-