Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public boolean matchesSafely(String s) {

for (String substring : substrings) {
fromIndex = s.indexOf(substring, fromIndex);
if (fromIndex == -1) {
if (fromIndex++ == -1) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,26 @@


public class StringContainsInOrderTest extends AbstractMatcherTest {
StringContainsInOrder m = new StringContainsInOrder(asList("a", "b", "c"));
StringContainsInOrder m = new StringContainsInOrder(asList("a", "b", "c", "c"));

@Override
protected Matcher<?> createMatcher() {
return m;
}

public void testMatchesOnlyIfStringContainsGivenSubstringsInTheSameOrder() {
assertMatches("substrings in order", m, "abc");
assertMatches("substrings separated", m, "1a2b3c4");
assertMatches("all substrings adjacent in order", m, "abcc");
assertMatches("all substrings separated in order", m, "1a2b3c4c5");

assertDoesNotMatch("substrings out of order", m, "cab");
assertDoesNotMatch("no substrings in string", m, "xyz");
assertDoesNotMatch("substring missing", m, "ac");
assertDoesNotMatch("cumulative substring length longer than string", m, "abc");
assertDoesNotMatch("substrings out of order", m, "cabc");
assertDoesNotMatch("no substrings in string", m, "wxyz");
assertDoesNotMatch("substring not occurring", m, "axcc");
assertDoesNotMatch("substring missing", m, "acc");
assertDoesNotMatch("empty string", m, "");
}

public void testHasAReadableDescription() {
assertDescription("a string containing \"a\", \"b\", \"c\" in order", m);
assertDescription("a string containing \"a\", \"b\", \"c\", \"c\" in order", m);
}
}