Skip to content

Commit fe36747

Browse files
committed
Merge pull request #22 from bodiam/master
Fixes #21
2 parents 82b6c09 + f0182ca commit fe36747

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

‎hamcrest-library/src/main/java/org/hamcrest/text/StringContainsInOrder.java‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
import org.hamcrest.Matcher;
66
import org.hamcrest.TypeSafeMatcher;
77

8+
import java.util.Arrays;
9+
810
public class StringContainsInOrder extends TypeSafeMatcher<String> {
911
private final Iterable<String> substrings;
1012

1113
public StringContainsInOrder(Iterable<String> substrings) {
1214
this.substrings = substrings;
1315
}
14-
16+
1517
@Override
1618
public boolean matchesSafely(String s) {
1719
int fromIndex = 0;
@@ -52,4 +54,19 @@ public void describeTo(Description description) {
5254
public static Matcher<String> stringContainsInOrder(Iterable<String> substrings) {
5355
return new StringContainsInOrder(substrings);
5456
}
57+
58+
/**
59+
* Creates a matcher of {@link String} that matches when the examined string contains all of
60+
* the specified substrings, regardless of the order of their appearance.
61+
* <p/>
62+
* For example:
63+
* <pre>assertThat("myfoobarbaz", stringContainsInOrder("bar", "foo"))</pre>
64+
*
65+
* @param substrings
66+
* the substrings that must be contained within matching strings
67+
*/
68+
@Factory
69+
public static Matcher<String> stringContainsInOrder(String... substrings) {
70+
return new StringContainsInOrder(Arrays.asList(substrings));
71+
}
5572
}

0 commit comments

Comments
 (0)