Created
June 15, 2017 19:31
-
-
Save sczerwinski/ae287be7af74a0728ff067a41f25839d to your computer and use it in GitHub Desktop.
Kotlin functions creating custom Hamcrest matchers for Android
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
import android.view.View | |
import org.hamcrest.Description | |
import org.hamcrest.Matcher | |
import org.hamcrest.TypeSafeMatcher | |
inline fun <reified T : View> withType(): Matcher<View> = object : TypeSafeMatcher<View>() { | |
override fun describeTo(description: Description?) { | |
description?.appendText("with type: ${T::class.java.name}") | |
} | |
override fun matchesSafely(item: View?): Boolean = | |
item.let { it is T } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
onView(withType<Button>())