X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Ftest%2FMatchers.kt;h=7fc9428c80a1da9a4af00e3a5aa5b8a9a1fd9a58;hb=ab598a7019581eca9981cf1101b315e13a3bcbaa;hp=21d225c6fcb1eea5fceca9a3e9b5854d6b0ad8a4;hpb=d8b8330c6f0a28a59586970648dd166ca48fe2ee;p=Sone.git diff --git a/src/test/kotlin/net/pterodactylus/sone/test/Matchers.kt b/src/test/kotlin/net/pterodactylus/sone/test/Matchers.kt index 21d225c..7fc9428 100644 --- a/src/test/kotlin/net/pterodactylus/sone/test/Matchers.kt +++ b/src/test/kotlin/net/pterodactylus/sone/test/Matchers.kt @@ -1,5 +1,6 @@ package net.pterodactylus.sone.test +import freenet.support.* import net.pterodactylus.sone.freenet.wot.* import net.pterodactylus.sone.utils.* import net.pterodactylus.util.web.* @@ -57,7 +58,7 @@ fun isTrusted(ownIdentity: OwnIdentity, trust: Matcher) = object : TypeSa } } -fun isIdentity(id: String, nickname: String, requestUri: String, contexts: Matcher>, properties: Matcher>) = +fun isIdentity(id: String, nickname: String?, requestUri: String, contexts: Matcher>, properties: Matcher>) = AttributeMatcher("identity") .addAttribute("id", id, Identity::getId) .addAttribute("nickname", nickname, Identity::getNickname) @@ -74,6 +75,19 @@ fun isOwnIdentity(id: String, nickname: String, requestUri: String, insertUri: S .addAttribute("contexts", OwnIdentity::getContexts, contexts) .addAttribute("properties", OwnIdentity::getProperties, properties) +fun hasField(name: String, valueMatcher: Matcher) = object : TypeSafeDiagnosingMatcher() { + override fun matchesSafely(item: SimpleFieldSet, mismatchDescription: Description) = + valueMatcher.matches(item.get(name)).onFalse { + valueMatcher.describeMismatch(item, mismatchDescription) + } + + override fun describeTo(description: Description) { + description + .appendText("simple field set with key ").appendValue(name) + .appendText(", value ").appendValue(valueMatcher) + } +} + /** * [TypeSafeDiagnosingMatcher] implementation that aims to cut down boilerplate on verifying the attributes * of typical container objects.