From: David ‘Bombe’ Roden Date: Fri, 6 Sep 2024 10:33:39 +0000 (+0200) Subject: 🚧 Add matchers for ARKs, Versions, and DSAGroups X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=30d8b2de5c042d9e9758911235c950f66468a491;p=jFCPlib.git 🚧 Add matchers for ARKs, Versions, and DSAGroups --- 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 index 0000000..6f71fa1 --- /dev/null +++ b/src/test/java/net/pterodactylus/fcp/test/ArkMatchers.java @@ -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 isArk(Matcher publicUri, Matcher privateUri, Matcher number) { + return new TypeSafeDiagnosingMatcher() { + @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 index 0000000..fd21eb8 --- /dev/null +++ b/src/test/java/net/pterodactylus/fcp/test/DsaGroupMatchers.java @@ -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 isDsaGroup(Matcher base, Matcher prime, Matcher subprime) { + return new TypeSafeDiagnosingMatcher() { + @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 index 0000000..bb56a5e --- /dev/null +++ b/src/test/java/net/pterodactylus/fcp/test/VersionMatchers.java @@ -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 isVersion(Matcher nodeName, Matcher treeVersion, Matcher protocolVersion, Matcher buildNumber) { + return new TypeSafeDiagnosingMatcher() { + @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); + } + }; + } + +}