From: David ‘Bombe’ Roden Date: Fri, 22 Nov 2024 22:13:24 +0000 (+0100) Subject: 🚧 Add matchers for high-level requests X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=f52046391012dc818613fb97de38519aa00c2669;p=jFCPlib.git 🚧 Add matchers for high-level requests --- 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"); + } + }; + } + +}