From 2786e8969153981d679f0d603d8fb2d1e3b626a3 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:35:45 +0100 Subject: [PATCH] =?utf8?q?=F0=9F=9A=A7=20Add=20matcher=20for=20empty=20map?= =?utf8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/net/pterodactylus/sone/test/Matchers.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/kotlin/net/pterodactylus/sone/test/Matchers.kt b/src/test/kotlin/net/pterodactylus/sone/test/Matchers.kt index c084d35..83da2ae 100644 --- a/src/test/kotlin/net/pterodactylus/sone/test/Matchers.kt +++ b/src/test/kotlin/net/pterodactylus/sone/test/Matchers.kt @@ -1,7 +1,9 @@ package net.pterodactylus.sone.test +import net.pterodactylus.sone.utils.* import net.pterodactylus.util.web.* import org.hamcrest.* +import org.hamcrest.Matchers.* fun hasHeader(name: String, value: String) = object : TypeSafeDiagnosingMatcher
() { override fun matchesSafely(item: Header, mismatchDescription: Description) = @@ -19,3 +21,14 @@ fun compare(value: T, comparison: (T) -> Boolean, onError: (T) -> Unit false.takeUnless { comparison(value) } ?.also { onError(value) } +fun isEmptyMap() = object : TypeSafeDiagnosingMatcher>() { + override fun describeTo(description: Description) { + description.appendText("empty map") + } + + override fun matchesSafely(item: Map, mismatchDescription: Description) = + item.isEmpty().onFalse { + mismatchDescription.appendText("was ").appendValue(item) + } +} + -- 2.7.4