...4import org.hamcrest.CoreMatchers;5import org.hamcrest.Description;6import org.hamcrest.Matcher;7import org.hamcrest.Matchers;8import org.hamcrest.TypeSafeMatcher;9import java.util.List;10import java.util.Objects;11import static org.hamcrest.Matchers.contains;12import static org.hamcrest.Matchers.isEmptyOrNullString;13public class IndexMatchers {14 public static Matcher<Index> index(String indexName, String tableName, String fieldName) {15 return index(indexName, tableName, ImmutableList.of(fieldName));16 }17 public static Matcher<Index> index(String indexName, String tableName, List<String> fieldNames) {18 return Matchers.allOf(hasName(indexName), hasTable(tableName), hasFieldsInOrder(fieldNames));19 }20 public static Matcher<Index> index(String tableName, String fieldName) {21 return index(tableName, ImmutableList.of(fieldName));22 }23 public static Matcher<Index> index(String tableName, List<String> fieldNames) {24 return Matchers.allOf(hasTable(tableName), hasFieldsInOrder(fieldNames));25 }26 public static Matcher<Index> isNamed() {27 final Matcher<String> notEmptyString = CoreMatchers.not(isEmptyOrNullString());28 return new TypeSafeMatcher<Index>() {29 @Override30 public boolean matchesSafely(Index index) {31 return notEmptyString.matches(index.getIndexName());32 }33 @Override34 public void describeTo(Description description) {35 description.appendText("indexName should be ");36 notEmptyString.describeTo(description);37 }38 @Override39 public void describeMismatchSafely(Index index, Description description) {40 notEmptyString.describeMismatch(index.getIndexName(), description);41 }42 };43 }44 public static Matcher<Index> hasName(final String indexName) {45 return new TypeSafeMatcher<Index>() {46 @Override47 public boolean matchesSafely(Index index) {48 return Objects.equals(indexName, index.getIndexName());49 }50 @Override51 public void describeTo(Description description) {52 description.appendText("indexName should be ").appendValue(indexName);53 }54 @Override55 public void describeMismatchSafely(Index index, Description description) {56 description.appendText("was ").appendValue(index.getIndexName());57 }58 };59 }60 public static Matcher<Index> hasTable(final String tableName) {61 return new TypeSafeMatcher<Index>() {62 @Override63 public boolean matchesSafely(Index index) {64 return Objects.equals(tableName, index.getTableName());65 }66 @Override67 public void describeTo(Description description) {68 description.appendText("tableName should be ").appendValue(tableName);69 }70 @Override71 public void describeMismatchSafely(Index index, Description description) {72 description.appendText("was ").appendValue(index.getTableName());73 }74 };75 }76 public static Matcher<Index> hasFieldsInOrder(final List<String> fieldNames) {77 final Matcher<Iterable<? extends String>> contains = contains(fieldNames.toArray(new String[fieldNames.size()]));78 return new TypeSafeMatcher<Index>() {79 @Override80 public boolean matchesSafely(Index index) {81 return contains.matches(index.getFieldNames());82 }83 @Override84 public void describeTo(Description description) {85 description.appendText("fieldNames should be an ");86 contains.describeTo(description);87 }88 @Override89 public void describeMismatchSafely(Index index, Description description) {90 contains.describeMismatch(index.getFieldNames(), description);91 }92 };...