Skip to content

Instantly share code, notes, and snippets.

@vlad-kasatkin
Created June 11, 2015 20:46
Show Gist options
  • Select an option

  • Save vlad-kasatkin/766685bf276eeb0121d5 to your computer and use it in GitHub Desktop.

Select an option

Save vlad-kasatkin/766685bf276eeb0121d5 to your computer and use it in GitHub Desktop.
Matcher to assert that item is not in the adapter
public static Matcher<View> withAdaptedData(final Matcher<Object> dataMatcher) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("with class name: ");
dataMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
if (!(view instanceof AdapterView)) {
return false;
}
@SuppressWarnings("rawtypes")
Adapter adapter = ((AdapterView) view).getAdapter();
for (int i = 0; i < adapter.getCount(); i++) {
if (dataMatcher.matches(adapter.getItem(i))) {
return true;
}
}
return false;
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment