### Question:
Substring { public static Pattern spanningInOrder(String stop1, String stop2, String... moreStops) { List<String> stops = Stream.concat(Stream.of(stop1, stop2), Arrays.stream(moreStops)) .peek(Objects::requireNonNull) .collect(toList()); return new Pattern() { @Override Match match(String input, int fromIndex) { int begin = -1; for (String stop : stops) { int index = input.indexOf(stop, fromIndex); if (index < 0) { return null; } if (begin == -1) { begin = index; } fromIndex = index + stop.length(); } return new Match(input, begin, fromIndex - begin); } @Override public String toString() { return "spanningInOrder(" + stops.stream().map(s -> "'" + s + "'").collect(joining(", ")) + ")"; } }; } private  Substring(); static Prefix prefix(String prefix); static Prefix prefix(char prefix); static Suffix suffix(String suffix); static Suffix suffix(char suffix); static Pattern substring(String str); static Pattern first(String str); static Pattern first(char character); static Pattern first(java.util.regex.Pattern regexPattern); static Pattern first(java.util.regex.Pattern regexPattern, int group); static Pattern spanningInOrder(String stop1, String stop2, String... moreStops); static Pattern last(String str); static Pattern last(char character); static Pattern before(Pattern delimiter); static Pattern after(Pattern delimiter); static Pattern upToIncluding(Pattern pattern); static Pattern between(Pattern open, Pattern close); static final Pattern NONE; static final Pattern BEGINNING; static final Pattern END; }### Answer:
@Test public void spanningInOrder_toString() { assertThat(spanningInOrder("o", "bar").toString()).isEqualTo("spanningInOrder('o', 'bar')"); }
@Test public void spanningInOrder_twoStops_matches() { Substring.Match match = spanningInOrder("o", "bar").in("foo bar car").get(); assertThat(match.index()).isEqualTo(1); assertThat(match.length()).isEqualTo(6); }
@Test public void spanningInOrder_twoStops_firstPatternDoesNotMatch() { assertThat(spanningInOrder("o", "bar").in("far bar car")).isEmpty(); }
@Test public void spanningInOrder_twoStops_secondPatternDoesNotMatch() { assertThat(spanningInOrder("o", "bar").in("foo car")).isEmpty(); }
@Test public void spanningInOrder_twoStops_firstStopIsEmpty() { Substring.Match match = spanningInOrder("", "foo").in("foo bar car").get(); assertThat(match.index()).isEqualTo(0); assertThat(match.length()).isEqualTo(3); }
@Test public void spanningInOrder_twoStops_secondStopIsEmpty() { Substring.Match match = spanningInOrder("foo", "").in("foo bar car").get(); assertThat(match.index()).isEqualTo(0); assertThat(match.length()).isEqualTo(3); }
@Test public void spanningInOrder_twoStops_bothStopsAreEmpty() { Substring.Match match = spanningInOrder("", "").in("foo bar car").get(); assertThat(match.index()).isEqualTo(0); assertThat(match.length()).isEqualTo(0); }
@Test public void spanningInOrder_threeStops_matches() { Substring.Match match = spanningInOrder("o", "bar", "bar").in("foo barcarbar").get(); assertThat(match.toString()).isEqualTo("oo barcarbar"); assertThat(match.index()).isEqualTo(1); assertThat(match.length()).isEqualTo(12); }
@Test public void spanningInOrder_threeStops_firstPatternDoesNotMatch() { assertThat(spanningInOrder("o", "bar", "car").in("far bar car")).isEmpty(); }
@Test public void spanningInOrder_threeStops_secondPatternDoesNotMatch() { assertThat(spanningInOrder("o", "bar", "car").in("foo boo car")).isEmpty(); }
@Test public void spanningInOrder_threeStops_thirdPatternDoesNotMatch() { assertThat(spanningInOrder("o", "bar", "car").in("foo bar cat")).isEmpty(); }