org.http4k.hamkrest.LensMatcher.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of http4k-testing-hamkrest Show documentation
Show all versions of http4k-testing-hamkrest Show documentation
A set of Hamkrest matchers for common http4k types
package org.http4k.hamkrest
import com.natpryce.hamkrest.MatchResult
import com.natpryce.hamkrest.Matcher
import org.http4k.lens.LensFailure
internal class LensMatcher(private val matcher: Matcher) : Matcher {
override val description = matcher.description
override fun invoke(actual: R): MatchResult = try {
matcher(actual)
} catch (e: LensFailure) {
MatchResult.Mismatch("lens could not extract valid value from: $actual")
}
}