From 30d8b2de5c042d9e9758911235c950f66468a491 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 6 Sep 2024 12:33:39 +0200 Subject: [PATCH] =?utf8?q?=F0=9F=9A=A7=20Add=20matchers=20for=20ARKs,=20Ve?= =?utf8?q?rsions,=20and=20DSAGroups?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../net/pterodactylus/fcp/test/ArkMatchers.java | 38 +++++++++++++++++++ .../pterodactylus/fcp/test/DsaGroupMatchers.java | 38 +++++++++++++++++++ .../pterodactylus/fcp/test/VersionMatchers.java | 43 ++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 src/test/java/net/pterodactylus/fcp/test/ArkMatchers.java create mode 100644 src/test/java/net/pterodactylus/fcp/test/DsaGroupMatchers.java create mode 100644 src/test/java/net/pterodactylus/fcp/test/VersionMatchers.java 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); + } + }; + } + +} -- 2.7.4