🚧 Add matchers for ARKs, Versions, and DSAGroups
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 6 Sep 2024 10:33:39 +0000 (12:33 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 6 Sep 2024 10:33:39 +0000 (12:33 +0200)
src/test/java/net/pterodactylus/fcp/test/ArkMatchers.java [new file with mode: 0644]
src/test/java/net/pterodactylus/fcp/test/DsaGroupMatchers.java [new file with mode: 0644]
src/test/java/net/pterodactylus/fcp/test/VersionMatchers.java [new file with mode: 0644]

diff --git a/src/test/java/net/pterodactylus/fcp/test/ArkMatchers.java b/src/test/java/net/pterodactylus/fcp/test/ArkMatchers.java
new file mode 100644 (file)
index 0000000..6f71fa1
--- /dev/null
@@ -0,0 +1,38 @@
+package net.pterodactylus.fcp.test;
+
+import net.pterodactylus.fcp.ARK;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+
+public class ArkMatchers {
+
+       public static Matcher<ARK> isArk(Matcher<? super String> publicUri, Matcher<? super String> privateUri, Matcher<? super Integer> number) {
+               return new TypeSafeDiagnosingMatcher<ARK>() {
+                       @Override
+                       protected boolean matchesSafely(ARK ark, Description mismatchDescription) {
+                               if (!publicUri.matches(ark.getPublicURI())) {
+                                       mismatchDescription.appendText("public URI is ").appendValue(ark.getPublicURI());
+                                       return false;
+                               }
+                               if (!privateUri.matches(ark.getPrivateURI())) {
+                                       mismatchDescription.appendText("private URI is ").appendValue(ark.getPrivateURI());
+                                       return false;
+                               }
+                               if (!number.matches(ark.getNumber())) {
+                                       mismatchDescription.appendText("number is ").appendValue(ark.getNumber());
+                                       return false;
+                               }
+                               return true;
+                       }
+
+                       @Override
+                       public void describeTo(Description description) {
+                               description.appendText("is ARK with public URI ").appendDescriptionOf(publicUri);
+                               description.appendText(", private URI ").appendDescriptionOf(privateUri);
+                               description.appendText(", and number ").appendDescriptionOf(number);
+                       }
+               };
+       }
+
+}
diff --git a/src/test/java/net/pterodactylus/fcp/test/DsaGroupMatchers.java b/src/test/java/net/pterodactylus/fcp/test/DsaGroupMatchers.java
new file mode 100644 (file)
index 0000000..fd21eb8
--- /dev/null
@@ -0,0 +1,38 @@
+package net.pterodactylus.fcp.test;
+
+import net.pterodactylus.fcp.DSAGroup;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+
+public class DsaGroupMatchers {
+
+       public static Matcher<DSAGroup> isDsaGroup(Matcher<? super String> base, Matcher<? super String> prime, Matcher<? super String> subprime) {
+               return new TypeSafeDiagnosingMatcher<DSAGroup>() {
+                       @Override
+                       protected boolean matchesSafely(DSAGroup dsaGroup, Description mismatchDescription) {
+                               if (!base.matches(dsaGroup.getBase())) {
+                                       mismatchDescription.appendText("base is ").appendValue(dsaGroup.getBase());
+                                       return false;
+                               }
+                               if (!prime.matches(dsaGroup.getPrime())) {
+                                       mismatchDescription.appendText("prime is ").appendValue(dsaGroup.getPrime());
+                                       return false;
+                               }
+                               if (!subprime.matches(dsaGroup.getSubprime())) {
+                                       mismatchDescription.appendText("subprime is ").appendValue(dsaGroup.getSubprime());
+                                       return false;
+                               }
+                               return true;
+                       }
+
+                       @Override
+                       public void describeTo(Description description) {
+                               description.appendText("is dsa group with base ").appendDescriptionOf(base);
+                               description.appendText(", prime ").appendDescriptionOf(prime);
+                               description.appendText(", and subprime ").appendDescriptionOf(subprime);
+                       }
+               };
+       }
+
+}
diff --git a/src/test/java/net/pterodactylus/fcp/test/VersionMatchers.java b/src/test/java/net/pterodactylus/fcp/test/VersionMatchers.java
new file mode 100644 (file)
index 0000000..bb56a5e
--- /dev/null
@@ -0,0 +1,43 @@
+package net.pterodactylus.fcp.test;
+
+import net.pterodactylus.fcp.Version;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+
+public class VersionMatchers {
+
+       public static Matcher<Version> isVersion(Matcher<? super String> nodeName, Matcher<? super String> treeVersion, Matcher<? super String> protocolVersion, Matcher<? super Integer> buildNumber) {
+               return new TypeSafeDiagnosingMatcher<Version>() {
+                       @Override
+                       protected boolean matchesSafely(Version version, Description mismatchDescription) {
+                               if (!nodeName.matches(version.getNodeName())) {
+                                       mismatchDescription.appendText("node name is ").appendValue(version.getNodeName());
+                                       return false;
+                               }
+                               if (!treeVersion.matches(version.getTreeVersion())) {
+                                       mismatchDescription.appendText("tree version is ").appendValue(version.getTreeVersion());
+                                       return false;
+                               }
+                               if (!protocolVersion.matches(version.getProtocolVersion())) {
+                                       mismatchDescription.appendText("protocol version is ").appendValue(version.getProtocolVersion());
+                                       return false;
+                               }
+                               if (!buildNumber.matches(version.getBuildNumber())) {
+                                       mismatchDescription.appendText("build number is ").appendValue(version.getBuildNumber());
+                                       return false;
+                               }
+                               return true;
+                       }
+
+                       @Override
+                       public void describeTo(Description description) {
+                               description.appendText("is version with node name ").appendDescriptionOf(nodeName);
+                               description.appendText(", tree version ").appendDescriptionOf(treeVersion);
+                               description.appendText(", protocol version ").appendDescriptionOf(protocolVersion);
+                               description.appendText(", and build number ").appendDescriptionOf(buildNumber);
+                       }
+               };
+       }
+
+}