Skip to content

Instantly share code, notes, and snippets.

@AaronMT
Created January 14, 2020 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AaronMT/905df26acd694d5724975957a27c60f4 to your computer and use it in GitHub Desktop.
Save AaronMT/905df26acd694d5724975957a27c60f4 to your computer and use it in GitHub Desktop.
fun nthChildOf(
parentMatcher: Matcher<View>,
childPosition: Int
): Matcher<View> {
return object : TypeSafeMatcher<View>() {
override fun describeTo(description: Description) {
description.appendText("Position is $childPosition")
}
public override fun matchesSafely(view: View): Boolean {
if (view.parent !is ViewGroup) {
return parentMatcher.matches(view.parent)
}
val group = view.parent as ViewGroup
return parentMatcher.matches(view.parent) && group.getChildAt(childPosition) == view
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment