From: David ‘Bombe’ Roden Date: Fri, 1 Nov 2019 17:38:03 +0000 (+0100) Subject: 🚧 Add matcher for simple field sets X-Git-Tag: v81^2~92 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=f1bfb86be7bacf05949c722d80ec8c7a8a996ed9 🚧 Add matcher for simple field sets --- diff --git a/src/test/kotlin/net/pterodactylus/sone/test/Matchers.kt b/src/test/kotlin/net/pterodactylus/sone/test/Matchers.kt index 21d225c..e7588db 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.* @@ -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.