🚧 Add matcher for simple field sets
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 1 Nov 2019 17:38:03 +0000 (18:38 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 1 Nov 2019 17:38:03 +0000 (18:38 +0100)
src/test/kotlin/net/pterodactylus/sone/test/Matchers.kt

index 21d225c..e7588db 100644 (file)
@@ -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<String>) = object : TypeSafeDiagnosingMatcher<SimpleFieldSet>() {
+       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.