X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Ftest%2FMatchers.kt;fp=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Ftest%2FMatchers.kt;h=644f192c6ad71c3111adf3bb351da2542ac5e2e1;hp=3bbdd23f88f3373bad0b570139e42c5815a0142a;hb=d0a369a783e84292bbac793191a8cbf6827f395c;hpb=11b68b3a9d2437ee951e06779f337b20084f01f0 diff --git a/src/test/kotlin/net/pterodactylus/sone/test/Matchers.kt b/src/test/kotlin/net/pterodactylus/sone/test/Matchers.kt index 3bbdd23..644f192 100644 --- a/src/test/kotlin/net/pterodactylus/sone/test/Matchers.kt +++ b/src/test/kotlin/net/pterodactylus/sone/test/Matchers.kt @@ -39,3 +39,29 @@ fun isTrust(trust: Int?, score: Int?, rank: Int?) = .addAttribute("score", score, Trust::implicit) .addAttribute("rank", rank, Trust::distance) +fun isTrusted(ownIdentity: OwnIdentity, trust: Matcher) = object : TypeSafeDiagnosingMatcher() { + override fun matchesSafely(item: Identity, mismatchDescription: Description) = + item.getTrust(ownIdentity)?.let { foundTrust -> + trust.matches(foundTrust).onFalse { + trust.describeMismatch(foundTrust, mismatchDescription) + } + } ?: { + mismatchDescription.appendText("not trusted") + false + }() + + override fun describeTo(description: Description) { + description + .appendText("trusted by ").appendValue(ownIdentity) + .appendText(" with ").appendValue(trust) + } +} + +fun isIdentity(id: String, nickname: String, requestUri: String, contexts: Matcher>, properties: Matcher>) = + AttributeMatcher("identity") + .addAttribute("id", id, Identity::getId) + .addAttribute("nickname", nickname, Identity::getNickname) + .addAttribute("requestUri", requestUri, Identity::getRequestUri) + .addAttribute("contexts", Identity::getContexts, contexts) + .addAttribute("properties", Identity::getProperties, properties) +