bbaldino
01/14/2020, 12:27 AMprivate inline fun <reified U> containInstanceOf(crossinline block: (U) -> Unit) = object : Matcher<Collection<*>> {
override fun test(value: Collection<*>): MatcherResult {
var foundInstance = false
value.forEach {
if (it is U) {
block(it)
foundInstance = true
return@forEach
}
}
return MatcherResult(
foundInstance,
{ "No instances of type ${U::class} found " },
{ "Instance of type ${U::class} found " }
)
}
}
private inline fun <reified U> Collection<*>.shouldContainInstanceOf(crossinline block: (U) -> Unit = {}) =
this should containInstanceOf(block)