From d0a369a783e84292bbac793191a8cbf6827f395c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 1 Nov 2019 18:36:49 +0100 Subject: [PATCH] =?utf8?q?=F0=9F=9A=A7=20Add=20matcher=20for=20identities?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../kotlin/net/pterodactylus/sone/test/Matchers.kt | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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) + -- 2.7.4