🚧 Add matchers for high-level requests
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 22 Nov 2024 22:13:24 +0000 (23:13 +0100)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 22 Nov 2024 22:13:24 +0000 (23:13 +0100)
src/test/java/net/pterodactylus/fcp/test/Requests.java [new file with mode: 0644]

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 (file)
index 0000000..09b9057
--- /dev/null
@@ -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<Request> isGetRequest() {
+               return isGetRequest(Matchers.anything());
+       }
+
+       public static Matcher<Request> isGetRequest(Matcher<? super String> identifier) {
+               return new TypeSafeDiagnosingMatcher<Request>() {
+                       @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");
+                       }
+               };
+       }
+
+}