Skip to content

Instantly share code, notes, and snippets.

@plnice
Created February 18, 2018 09:06
Show Gist options
  • Save plnice/01f9c1a022c72ac72b6fd66bd6289d79 to your computer and use it in GitHub Desktop.
Save plnice/01f9c1a022c72ac72b6fd66bd6289d79 to your computer and use it in GitHub Desktop.
fun withDrawable(@DrawableRes id: Int) = object : TypeSafeMatcher<View>() {
override fun describeTo(description: Description) {
description.appendText("ImageView with drawable same as drawable with id $id")
}
override fun matchesSafely(view: View): Boolean {
val context = view.context
val expectedBitmap = context.getDrawable(id).toBitmap()
return view is ImageView && view.drawable.toBitmap().sameAs(expectedBitmap)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment