Created
June 11, 2015 20:46
-
-
Save vlad-kasatkin/766685bf276eeb0121d5 to your computer and use it in GitHub Desktop.
Matcher to assert that item is not in the adapter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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