--- /dev/null
+package net.pterodactylus.fcp.test;
+
+import java.util.Objects;
+import net.pterodactylus.fcp.plugin.IdentityTrust;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+
+public class IdentityTrustMatchers {
+
+ /**
+ * Creates a {@link Matcher} for {@link IdentityTrust} objects which
+ * verifies its {@link IdentityTrust#getTrust() trust} value against the
+ * given trust value.
+ *
+ * @param trust The value to verify the trust against
+ * @return A {@link Matcher} for {@link IdentityTrust} objects
+ */
+ public static Matcher<IdentityTrust> hasTrust(int trust) {
+ return new TypeSafeDiagnosingMatcher<IdentityTrust>() {
+ @Override
+ protected boolean matchesSafely(IdentityTrust identityTrust, Description mismatchDescription) {
+ if (identityTrust.getTrust() != trust) {
+ mismatchDescription.appendText("trust was ").appendValue(identityTrust.getTrust());
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("has trust ").appendValue(trust);
+ }
+ };
+ }
+
+ /**
+ * Creates a {@link Matcher} for {@link IdentityTrust} objects which
+ * verifies its {@link IdentityTrust#getComment() comment} against the
+ * given comment.
+ *
+ * @param comment The value to verify the comment against
+ * @return A {@link Matcher} for {@link IdentityTrust} objects
+ */
+ public static Matcher<IdentityTrust> hasComment(String comment) {
+ return new TypeSafeDiagnosingMatcher<IdentityTrust>() {
+ @Override
+ protected boolean matchesSafely(IdentityTrust identityTrust, Description mismatchDescription) {
+ if (!Objects.equals(identityTrust.getComment(), comment)) {
+ mismatchDescription.appendText("comment was ").appendValue(identityTrust.getComment());
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("has comment ").appendValue(comment);
+ }
+ };
+ }
+
+}
--- /dev/null
+package net.pterodactylus.fcp.test;
+
+import net.pterodactylus.fcp.plugin.IdentityTrust;
+import org.hamcrest.Description;
+import org.hamcrest.StringDescription;
+import org.junit.Test;
+
+import static net.pterodactylus.fcp.test.IdentityTrustMatchers.hasComment;
+import static net.pterodactylus.fcp.test.IdentityTrustMatchers.hasTrust;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+
+public class IdentityTrustMatchersTest {
+
+ @Test
+ public void hasTrustMatcherDoesNotMatchIfTrustIsDifferent() {
+ assertThat(hasTrust(123).matches(new IdentityTrust((byte) 99, "")), equalTo(false));
+ }
+
+ @Test
+ public void hasTrustMatcherDescribesMismatchCorrectly() {
+ hasTrust(123).describeMismatch(new IdentityTrust((byte) 99, ""), description);
+ assertThat(description.toString(), equalTo("trust was <99b>"));
+ }
+
+ @Test
+ public void hasTrustMatcherMatchesIfTrustIsTheSame() {
+ assertThat(hasTrust(123).matches(new IdentityTrust((byte) 123, "")), equalTo(true));
+ }
+
+ @Test
+ public void hasTrustMatcherDescribesItselfCorrectly() {
+ hasTrust(123).describeTo(description);
+ assertThat(description.toString(), equalTo("has trust <123>"));
+ }
+
+ @Test
+ public void hasCommentMatcherDoesNotMatchIfCommentIsDifferent() {
+ assertThat(hasComment("bar").matches(new IdentityTrust((byte) 123, "foo")), equalTo(false));
+ }
+
+ @Test
+ public void hasCommentMatcherDescribesMismatchCorrectly() {
+ hasComment("bar").describeMismatch(new IdentityTrust((byte) 123, "foo"), description);
+ assertThat(description.toString(), equalTo("comment was \"foo\""));
+ }
+
+ @Test
+ public void hasCommentMatcherMatchesIfCommentIsTheSame() {
+ assertThat(hasComment("foo").matches(new IdentityTrust((byte) 123, "foo")), equalTo(true));
+ }
+
+ @Test
+ public void hasCommentMatcherDescribesItselfCorrectly() {
+ hasComment("foo").describeTo(description);
+ assertThat(description.toString(), equalTo("has comment \"foo\""));
+ }
+
+ private final Description description = new StringDescription();
+
+}