From f52046391012dc818613fb97de38519aa00c2669 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 22 Nov 2024 23:13:24 +0100 Subject: [PATCH] =?utf8?q?=F0=9F=9A=A7=20Add=20matchers=20for=20high-level?= =?utf8?q?=20requests?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/net/pterodactylus/fcp/test/Requests.java | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/test/java/net/pterodactylus/fcp/test/Requests.java diff --git a/src/test/java/net/pterodactylus/fcp/test/Requests.java b/src/test/java/net/pterodactylus/fcp/test/Requests.java new file mode 100644 index 0000000..09b9057 --- /dev/null +++ b/src/test/java/net/pterodactylus/fcp/test/Requests.java @@ -0,0 +1,38 @@ +package net.pterodactylus.fcp.test; + +import net.pterodactylus.fcp.highlevel.GetRequest; +import net.pterodactylus.fcp.highlevel.Request; +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.Matchers; +import org.hamcrest.TypeSafeDiagnosingMatcher; + +public class Requests { + + public static Matcher isGetRequest() { + return isGetRequest(Matchers.anything()); + } + + public static Matcher isGetRequest(Matcher identifier) { + return new TypeSafeDiagnosingMatcher() { + @Override + protected boolean matchesSafely(Request item, Description mismatchDescription) { + if (!(item instanceof GetRequest)) { + mismatchDescription.appendText("is a " + item.getClass().getSimpleName()); + return false; + } + if (!identifier.matches(item.getIdentifier())) { + mismatchDescription.appendText("identifier is ").appendValue(item.getIdentifier()); + return false; + } + return true; + } + + @Override + public void describeTo(Description description) { + description.appendText("get request"); + } + }; + } + +} -- 2.7.4