1 package com.atlassian.webdriver.matchers;
2
3 import org.hamcrest.Description;
4 import org.hamcrest.Matcher;
5 import org.hamcrest.Matchers;
6 import org.hamcrest.TypeSafeMatcher;
7
8
9
10
11
12
13 public final class LangMatchers
14 {
15
16 private LangMatchers()
17 {
18 throw new AssertionError("Don't instantiate me");
19 }
20
21 @SuppressWarnings("unchecked")
22 public static <T> Matcher<T> isInstance(Class<? extends T> type)
23 {
24 return (Matcher<T>) Matchers.instanceOf(type);
25 }
26
27 public static Matcher<String> containsInOrder(final CharSequence... substrings)
28 {
29 return new TypeSafeMatcher<String>()
30 {
31 @Override
32 public boolean matchesSafely(String item)
33 {
34 int index = -1;
35 for (CharSequence substring : substrings)
36 {
37 index = item.indexOf(substring.toString(), index);
38 if (index < 0)
39 {
40 return false;
41 }
42 }
43 return true;
44 }
45
46 @Override
47 public void describeTo(Description description)
48 {
49 description.appendText("a string that contains (in order): ").appendValueList("(", ",", ")", substrings);
50 }
51 };
52 }
53 }