From: David ‘Bombe’ Roden Date: Thu, 18 Dec 2025 20:51:41 +0000 (+0100) Subject: ♻️ Extend set of matchers and use them in the WoT plugin test X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=b1624b87697a4e77851ea82decc4f2240c190f89;p=jFCPlib.git ♻️ Extend set of matchers and use them in the WoT plugin test --- diff --git a/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java b/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java index 82918eb..e19510f 100644 --- a/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java +++ b/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java @@ -1,5 +1,16 @@ package net.pterodactylus.fcp.plugin; +import java.io.IOException; +import java.util.AbstractMap.SimpleEntry; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.function.BiConsumer; +import java.util.function.Function; import net.pterodactylus.fcp.FCPPluginReply; import net.pterodactylus.fcp.FcpConnection; import net.pterodactylus.fcp.FcpListener; @@ -13,26 +24,22 @@ import org.junit.experimental.runners.Enclosed; import org.junit.rules.Timeout; import org.junit.runner.RunWith; -import java.io.IOException; -import java.util.AbstractMap.SimpleEntry; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.function.BiConsumer; -import java.util.function.Function; - import static java.util.Collections.emptyMap; import static java.util.Collections.emptySet; import static net.pterodactylus.fcp.test.IdentityMatchers.hasContexts; +import static net.pterodactylus.fcp.test.IdentityMatchers.hasId; +import static net.pterodactylus.fcp.test.IdentityMatchers.hasInsertUri; +import static net.pterodactylus.fcp.test.IdentityMatchers.hasNickname; import static net.pterodactylus.fcp.test.IdentityMatchers.hasProperties; -import static net.pterodactylus.fcp.test.IdentityMatchers.isIdentity; -import static net.pterodactylus.fcp.test.IdentityMatchers.isOwnIdentity; +import static net.pterodactylus.fcp.test.IdentityMatchers.hasRequestUri; import static net.pterodactylus.fcp.test.Matchers.hasField; import static net.pterodactylus.fcp.test.Matchers.isNamed; +import static net.pterodactylus.fcp.test.TrustMatchers.hasNoRank; +import static net.pterodactylus.fcp.test.TrustMatchers.hasNoScore; +import static net.pterodactylus.fcp.test.TrustMatchers.hasNoTrust; +import static net.pterodactylus.fcp.test.TrustMatchers.hasRank; +import static net.pterodactylus.fcp.test.TrustMatchers.hasScore; +import static net.pterodactylus.fcp.test.TrustMatchers.hasTrust; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.aMapWithSize; import static org.hamcrest.Matchers.allOf; @@ -70,7 +77,7 @@ public class WebOfTrustPluginTest { TestFcpConnection fcpConnection = createConnectionThatCreatesOwnIdentity(); WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection); OwnIdentity ownIdentity = webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true); - assertThat(ownIdentity, isOwnIdentity(equalTo("identity"), equalTo("Test Nickname"), equalTo("request-uri"), equalTo("insert-uri"))); + assertThat(ownIdentity, allOf(hasId("identity"), hasNickname("Test Nickname"), hasRequestUri("request-uri"), hasInsertUri("insert-uri"))); } @Test @@ -95,7 +102,7 @@ public class WebOfTrustPluginTest { TestFcpConnection fcpConnection = createConnectionThatCreatesOwnIdentity(); WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection); OwnIdentity ownIdentity = webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true, "insert-uri"); - assertThat(ownIdentity, isOwnIdentity(equalTo("identity"), equalTo("Test Nickname"), equalTo("request-uri"), equalTo("insert-uri"))); + assertThat(ownIdentity, allOf(hasId("identity"), hasNickname("Test Nickname"), hasRequestUri("request-uri"), hasInsertUri("insert-uri"))); } @Test @@ -120,7 +127,7 @@ public class WebOfTrustPluginTest { TestFcpConnection fcpConnection = createConnectionThatCreatesOwnIdentity(); WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection); OwnIdentity ownIdentity = webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true, "some-request-uri", "insert-uri"); - assertThat(ownIdentity, isOwnIdentity(equalTo("identity"), equalTo("Test Nickname"), equalTo("request-uri"), equalTo("insert-uri"))); + assertThat(ownIdentity, allOf(hasId("identity"), hasNickname("Test Nickname"), hasRequestUri("request-uri"), hasInsertUri("insert-uri"))); } private TestFcpConnection createConnectionThatCreatesOwnIdentity() { @@ -173,12 +180,16 @@ public class WebOfTrustPluginTest { WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection); Set ownIdentities = webOfTrustPlugin.getOwnIdentities(); assertThat(ownIdentities, containsInAnyOrder( - allOf(isOwnIdentity(equalTo("identity-0"), equalTo("Nick 0"), equalTo("request-uri-0"), equalTo("insert-uri-0")), + allOf( + hasId("identity-0"), hasNickname("Nick 0"), hasRequestUri("request-uri-0"), hasInsertUri("insert-uri-0"), hasContexts(containsInAnyOrder("test-context-1", "test-context-2")), - hasProperties(allOf(aMapWithSize(2), hasEntry("prop1", "value1"), hasEntry("prop2", "value2")))), - allOf(isOwnIdentity(equalTo("identity-1"), equalTo("Nick 1"), equalTo("request-uri-1"), equalTo("insert-uri-1")), + hasProperties(allOf(aMapWithSize(2), hasEntry("prop1", "value1"), hasEntry("prop2", "value2"))) + ), + allOf( + hasId("identity-1"), hasNickname("Nick 1"), hasRequestUri("request-uri-1"), hasInsertUri("insert-uri-1"), hasContexts(containsInAnyOrder("test-context-2", "test-context-3")), - hasProperties(allOf(aMapWithSize(2), hasEntry("prop3", "value3"), hasEntry("prop4", "value4")))) + hasProperties(allOf(aMapWithSize(2), hasEntry("prop3", "value3"), hasEntry("prop4", "value4"))) + ) )); } @@ -203,12 +214,16 @@ public class WebOfTrustPluginTest { WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection); Set ownIdentities = webOfTrustPlugin.getOwnIdentites(); assertThat(ownIdentities, containsInAnyOrder( - allOf(isOwnIdentity(equalTo("identity-0"), equalTo("Nick 0"), equalTo("request-uri-0"), equalTo("insert-uri-0")), + allOf( + hasId("identity-0"), hasNickname("Nick 0"), hasRequestUri("request-uri-0"), hasInsertUri("insert-uri-0"), hasContexts(containsInAnyOrder("test-context-1", "test-context-2")), - hasProperties(allOf(aMapWithSize(2), hasEntry("prop1", "value1"), hasEntry("prop2", "value2")))), - allOf(isOwnIdentity(equalTo("identity-1"), equalTo("Nick 1"), equalTo("request-uri-1"), equalTo("insert-uri-1")), + hasProperties(allOf(aMapWithSize(2), hasEntry("prop1", "value1"), hasEntry("prop2", "value2"))) + ), + allOf( + hasId("identity-1"), hasNickname("Nick 1"), hasRequestUri("request-uri-1"), hasInsertUri("insert-uri-1"), hasContexts(containsInAnyOrder("test-context-2", "test-context-3")), - hasProperties(allOf(aMapWithSize(2), hasEntry("prop3", "value3"), hasEntry("prop4", "value4")))) + hasProperties(allOf(aMapWithSize(2), hasEntry("prop3", "value3"), hasEntry("prop4", "value4"))) + ) )); } @@ -261,9 +276,7 @@ public class WebOfTrustPluginTest { WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection); OwnIdentity ownIdentity = new OwnIdentity("own-id", "Own ID", "own-pub", "own-priv", emptySet(), emptyMap()); CalculatedTrust calculatedTrust = webOfTrustPlugin.getIdentityTrust(ownIdentity, "other-id"); - assertThat(calculatedTrust.getTrust(), equalTo((byte) 56)); - assertThat(calculatedTrust.getScore(), equalTo(56)); - assertThat(calculatedTrust.getRank(), equalTo(1)); + assertThat(calculatedTrust, allOf(hasTrust(56), hasScore(56), hasRank(1))); } private TestFcpConnection createConnectionThatDeliversIdentityTrustAndScore() { @@ -280,9 +293,7 @@ public class WebOfTrustPluginTest { WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection); OwnIdentity ownIdentity = new OwnIdentity("own-id", "Own ID", "own-pub", "own-priv", emptySet(), emptyMap()); CalculatedTrust calculatedTrust = webOfTrustPlugin.getIdentityTrust(ownIdentity, "other-id"); - assertThat(calculatedTrust.getTrust(), nullValue()); - assertThat(calculatedTrust.getScore(), equalTo(56)); - assertThat(calculatedTrust.getRank(), equalTo(1)); + assertThat(calculatedTrust, allOf(hasNoTrust(), hasScore(56), hasRank(1))); } private TestFcpConnection createConnectionThatDeliversIdentityWithoutTrustButAScore() { @@ -299,9 +310,7 @@ public class WebOfTrustPluginTest { WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection); OwnIdentity ownIdentity = new OwnIdentity("own-id", "Own ID", "own-pub", "own-priv", emptySet(), emptyMap()); CalculatedTrust calculatedTrust = webOfTrustPlugin.getIdentityTrust(ownIdentity, "other-id"); - assertThat(calculatedTrust.getTrust(), equalTo((byte) 56)); - assertThat(calculatedTrust.getScore(), nullValue()); - assertThat(calculatedTrust.getRank(), nullValue()); + assertThat(calculatedTrust, allOf(hasTrust(56), hasNoScore(), hasNoRank())); } private TestFcpConnection createConnectionThatDeliversIdentityWithTrustButWithoutScore() { @@ -348,7 +357,7 @@ public class WebOfTrustPluginTest { TestFcpConnection fcpConnection = createConnectionThatConfirmsAddedIdentityWithNickname(); WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection); Identity addedIdentity = webOfTrustPlugin.addIdentity("USK@foo,bar/baz/123"); - assertThat(addedIdentity, isIdentity(equalTo("new-id"), equalTo("new-nick"), equalTo("USK@foo,bar/baz/123"))); + assertThat(addedIdentity, allOf(hasId("new-id"), hasNickname("new-nick"), hasRequestUri(nullValue()))); } @Test @@ -356,7 +365,7 @@ public class WebOfTrustPluginTest { TestFcpConnection fcpConnection = createConnectionThatConfirmsAddedIdentityWithoutNickname(); WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection); Identity addedIdentity = webOfTrustPlugin.addIdentity("USK@foo,bar/baz/123"); - assertThat(addedIdentity, isIdentity(equalTo("new-id"), nullValue(), equalTo("USK@foo,bar/baz/123"))); + assertThat(addedIdentity, allOf(hasId("new-id"), hasNickname(nullValue()), hasRequestUri(nullValue()))); } @Test @@ -425,7 +434,7 @@ public class WebOfTrustPluginTest { Collection identities = webOfTrustPlugin.getIdentitesByScore(ownIdentity, "test", true); assertThat(identities, containsInAnyOrder( allOf( - isIdentity(equalTo("id1"), equalTo("ID 1"), equalTo("request-1")), + hasId("id1"), hasNickname("ID 1"), hasRequestUri("request-1"), hasContexts(containsInAnyOrder("test1", "test2")), hasProperties(allOf( aMapWithSize(2), @@ -434,7 +443,7 @@ public class WebOfTrustPluginTest { )) ), allOf( - isIdentity(equalTo("id2"), equalTo("ID 2"), equalTo("request-2")), + hasId("id2"), hasNickname("ID 2"), hasRequestUri("request-2"), hasContexts(containsInAnyOrder("test2", "test3")), hasProperties(allOf( aMapWithSize(2), diff --git a/src/test/java/net/pterodactylus/fcp/test/IdentityMatchers.java b/src/test/java/net/pterodactylus/fcp/test/IdentityMatchers.java index f4d39b2..997893e 100644 --- a/src/test/java/net/pterodactylus/fcp/test/IdentityMatchers.java +++ b/src/test/java/net/pterodactylus/fcp/test/IdentityMatchers.java @@ -12,38 +12,6 @@ import static org.hamcrest.Matchers.equalTo; public class IdentityMatchers { - public static Matcher isOwnIdentity(Matcher identifier, Matcher nickname, Matcher requestUri, Matcher insertUri) { - return new TypeSafeDiagnosingMatcher(OwnIdentity.class) { - @Override - protected boolean matchesSafely(OwnIdentity ownIdentity, Description mismatchDescription) { - if (!identifier.matches(ownIdentity.getIdentifier())) { - mismatchDescription.appendText("identifier is ").appendValue(ownIdentity.getIdentifier()); - return false; - } - if (!nickname.matches(ownIdentity.getNickname())) { - mismatchDescription.appendText("nickname is ").appendValue(ownIdentity.getNickname()); - return false; - } - if (!requestUri.matches(ownIdentity.getRequestUri())) { - mismatchDescription.appendText("public uri is ").appendValue(ownIdentity.getRequestUri()); - return false; - } - if (!insertUri.matches(ownIdentity.getInsertUri())) { - mismatchDescription.appendText("private uri is ").appendValue(ownIdentity.getInsertUri()); - return false; - } - return true; - } - - @Override - public void describeTo(Description description) { - description.appendText("is identity (").appendValue(identifier).appendText(", nicknamed ").appendValue(nickname) - .appendText(", public uri ").appendValue(requestUri).appendText(", private uri ").appendValue(insertUri).appendText(")"); - } - - }; - } - /** * Creates a {@link Matcher} for {@link Identity}s that verifies * their {@link Identity#getContexts() contexts} against the given @@ -89,34 +57,6 @@ public class IdentityMatchers { }; } - public static Matcher isIdentity(Matcher identifier, Matcher nickname, Matcher requestUri) { - return new TypeSafeDiagnosingMatcher(Identity.class) { - @Override - protected boolean matchesSafely(Identity identity, Description mismatchDescription) { - if (!identifier.matches(identity.getIdentifier())) { - identifier.describeMismatch(identity.getIdentifier(), mismatchDescription); - return false; - } - if (!nickname.matches(identity.getNickname())) { - nickname.describeMismatch(identity.getNickname(), mismatchDescription); - return false; - } - if (!requestUri.matches(identity.getRequestUri())) { - requestUri.describeMismatch(identity.getRequestUri(), mismatchDescription); - return false; - } - return true; - } - - @Override - public void describeTo(Description description) { - description.appendText("is identity (").appendValue(identifier).appendText(", nicknamed ").appendValue(nickname) - .appendText(", public uri ").appendValue(requestUri).appendText(")"); - } - - }; - } - /** * Creates a {@link Matcher} for {@link Identity Identities} which * verifies that the {@link Identity#getIdentifier() ID} of the diff --git a/src/test/java/net/pterodactylus/fcp/test/TrustMatchers.java b/src/test/java/net/pterodactylus/fcp/test/TrustMatchers.java new file mode 100644 index 0000000..dcd0f24 --- /dev/null +++ b/src/test/java/net/pterodactylus/fcp/test/TrustMatchers.java @@ -0,0 +1,157 @@ +package net.pterodactylus.fcp.test; + +import java.util.Objects; +import net.pterodactylus.fcp.plugin.CalculatedTrust; +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeDiagnosingMatcher; + +/** + * Assorted {@link Matcher}s for {@link CalculatedTrust} objects. + */ +public class TrustMatchers { + + /** + * Creates a {@link Matcher} for {@link CalculatedTrust} objects which + * verifies its {@link CalculatedTrust#getTrust()} against the given + * trust value. + * + * @param trust The trust value to match. The given value will be cast + * to a byte before comparison, so unexpected results are possible + * when specifying out-of-range values. + * @return A {@link Matcher} for {@link CalculatedTrust} objects + */ + public static Matcher hasTrust(int trust) { + return new TypeSafeDiagnosingMatcher() { + @Override + protected boolean matchesSafely(CalculatedTrust calculatedTrust, Description mismatchDescription) { + mismatchDescription.appendText("trust was ").appendValue(calculatedTrust.getTrust()); + return Objects.equals(calculatedTrust.getTrust(), (byte) trust); + } + + @Override + public void describeTo(Description description) { + description.appendText("has trust ").appendValue(trust); + } + }; + } + + /** + * Creates a {@link Matcher} for {@link CalculatedTrust} objects that + * verifies that no {@link CalculatedTrust#getTrust() trust} is present. + * + * @return A {@link Matcher} for {@link CalculatedTrust} objects + */ + public static Matcher hasNoTrust() { + return new TypeSafeDiagnosingMatcher() { + @Override + protected boolean matchesSafely(CalculatedTrust calculatedTrust, Description mismatchDescription) { + if (calculatedTrust.getTrust() != null) { + mismatchDescription.appendText("trust was ").appendValue(calculatedTrust.getTrust()); + return false; + } + return true; + } + + @Override + public void describeTo(Description description) { + description.appendText("has no trust"); + } + }; + } + + /** + * Creates a {@link Matcher} for {@link CalculatedTrust} objects which + * verifies its {@link CalculatedTrust#getScore()} against the given + * score value. + * + * @param score The score value to match. + * @return A {@link Matcher} for {@link CalculatedTrust} objects + */ + public static Matcher hasScore(int score) { + return new TypeSafeDiagnosingMatcher() { + @Override + protected boolean matchesSafely(CalculatedTrust calculatedTrust, Description mismatchDescription) { + mismatchDescription.appendText("score was ").appendValue(calculatedTrust.getScore()); + return Objects.equals(calculatedTrust.getScore(), score); + } + + @Override + public void describeTo(Description description) { + description.appendText("has score ").appendValue(score); + } + }; + } + + /** + * Creates a {@link Matcher} for {@link CalculatedTrust} objects that + * verifies that no {@link CalculatedTrust#getScore() score} is present. + * + * @return A {@link Matcher} for {@link CalculatedTrust} objects + */ + public static Matcher hasNoScore() { + return new TypeSafeDiagnosingMatcher() { + @Override + protected boolean matchesSafely(CalculatedTrust calculatedTrust, Description mismatchDescription) { + if (calculatedTrust.getScore() != null) { + mismatchDescription.appendText("score was ").appendValue(calculatedTrust.getScore()); + return false; + } + return true; + } + + @Override + public void describeTo(Description description) { + description.appendText("has no score"); + } + }; + } + + /** + * Creates a {@link Matcher} for {@link CalculatedTrust} objects which + * verifies its {@link CalculatedTrust#getRank() rank} against the given + * rank value. + * + * @param rank The rank value to match. + * @return A {@link Matcher} for {@link CalculatedTrust} objects + */ + public static Matcher hasRank(int rank) { + return new TypeSafeDiagnosingMatcher() { + @Override + protected boolean matchesSafely(CalculatedTrust calculatedTrust, Description mismatchDescription) { + mismatchDescription.appendText("rank was ").appendValue(calculatedTrust.getRank()); + return Objects.equals(calculatedTrust.getRank(), rank); + } + + @Override + public void describeTo(Description description) { + description.appendText("has rank ").appendValue(rank); + } + }; + } + + /** + * Creates a {@link Matcher} for {@link CalculatedTrust} objects that + * verifies that no {@link CalculatedTrust#getRank() rank} is present. + * + * @return A {@link Matcher} for {@link CalculatedTrust} objects + */ + public static Matcher hasNoRank() { + return new TypeSafeDiagnosingMatcher() { + @Override + protected boolean matchesSafely(CalculatedTrust calculatedTrust, Description mismatchDescription) { + if (calculatedTrust.getRank() != null) { + mismatchDescription.appendText("rank was ").appendValue(calculatedTrust.getRank()); + return false; + } + return true; + } + + @Override + public void describeTo(Description description) { + description.appendText("has no rank"); + } + }; + } + +} diff --git a/src/test/java/net/pterodactylus/fcp/test/TrustMatchersTest.java b/src/test/java/net/pterodactylus/fcp/test/TrustMatchersTest.java new file mode 100644 index 0000000..63f9f59 --- /dev/null +++ b/src/test/java/net/pterodactylus/fcp/test/TrustMatchersTest.java @@ -0,0 +1,186 @@ +package net.pterodactylus.fcp.test; + +import net.pterodactylus.fcp.plugin.CalculatedTrust; +import org.hamcrest.Description; +import org.hamcrest.StringDescription; +import org.junit.Test; + +import static net.pterodactylus.fcp.test.TrustMatchers.hasNoRank; +import static net.pterodactylus.fcp.test.TrustMatchers.hasNoScore; +import static net.pterodactylus.fcp.test.TrustMatchers.hasNoTrust; +import static net.pterodactylus.fcp.test.TrustMatchers.hasRank; +import static net.pterodactylus.fcp.test.TrustMatchers.hasScore; +import static net.pterodactylus.fcp.test.TrustMatchers.hasTrust; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +public class TrustMatchersTest { + + @Test + public void hasTrustMatcherDoesNotMatchIfTrustIsDifferent() { + assertThat(hasTrust(123).matches(new CalculatedTrust((byte) 99, null, null)), equalTo(false)); + } + + @Test + public void hasTrustMatcherDoesNotMatchIfTrustIsNull() { + assertThat(hasTrust(123).matches(new CalculatedTrust(null, null, null)), equalTo(false)); + } + + @Test + public void hasTrustMatcherDescribesMismatchCorrectly() { + hasTrust(123).describeMismatch(new CalculatedTrust((byte) 99, null, null), description); + assertThat(description.toString(), equalTo("trust was <99b>")); + } + + @Test + public void hasTrustMatcherDescribesMismatchWithNullCorrectly() { + hasTrust(123).describeMismatch(new CalculatedTrust(null, null, null), description); + assertThat(description.toString(), equalTo("trust was null")); + } + + @Test + public void hasTrustMatcherMatchesIfTrustIsTheSame() { + assertThat(hasTrust(123).matches(new CalculatedTrust((byte) 123, null, null)), equalTo(true)); + } + + @Test + public void hasTrustMatcherDescribesItselfCorrectly() { + hasTrust(123).describeTo(description); + assertThat(description.toString(), equalTo("has trust <123>")); + } + + @Test + public void hasNoTrustMatcherDoesNotMatchIfTrustIsPresent() { + assertThat(hasNoTrust().matches(new CalculatedTrust((byte) 123, null, null)), equalTo(false)); + } + + @Test + public void hasNoTrustMatcherDescribesMismatchCorrectly() { + hasNoTrust().describeMismatch(new CalculatedTrust((byte) 123, null, null), description); + assertThat(description.toString(), equalTo("trust was <123b>")); + } + + @Test + public void hasNoTrustMatcherMatchesIfNoTrustIsPresent() { + assertThat(hasNoTrust().matches(new CalculatedTrust(null, null, null)), equalTo(true)); + } + + @Test + public void hasNoTrustMatcherDescribesItselfCorrectly() { + hasNoTrust().describeTo(description); + assertThat(description.toString(), equalTo("has no trust")); + } + + @Test + public void hasScoreMatcherDoesNotMatchIfScoreIsDifferent() { + assertThat(hasScore(123).matches(new CalculatedTrust(null, 99, null)), equalTo(false)); + } + + @Test + public void hasScoreMatcherDescribesMismatchCorrectly() { + hasScore(123).describeMismatch(new CalculatedTrust(null, 99, null), description); + assertThat(description.toString(), equalTo("score was <99>")); + } + + @Test + public void hasScoreMatcherDoesNotMatchIfScoreIsNull() { + assertThat(hasScore(123).matches(new CalculatedTrust(null, null, null)), equalTo(false)); + } + + @Test + public void hasScoreMatcherDescribesMismatchWithNullCorrectly() { + hasScore(123).describeMismatch(new CalculatedTrust(null, null, null), description); + assertThat(description.toString(), equalTo("score was null")); + } + + @Test + public void hasScoreMatcherMatchesIfScoreIsTheSame() { + assertThat(hasScore(99).matches(new CalculatedTrust(null, 99, null)), equalTo(true)); + } + + @Test + public void hasScoreMatcherDescribesItselfCorrectly() { + hasScore(123).describeTo(description); + assertThat(description.toString(), equalTo("has score <123>")); + } + + @Test + public void hasNoScoreMatcherDoesNotMatchIfScoreIsPresent() { + assertThat(hasNoScore().matches(new CalculatedTrust(null, 123, null)), equalTo(false)); + } + + @Test + public void hasNoScoreMatcherDescribesMismatchCorrectly() { + hasNoScore().describeMismatch(new CalculatedTrust(null, 123, null), description); + assertThat(description.toString(), equalTo("score was <123>")); + } + + @Test + public void hasNoScoreMatcherMatchesIfNoScoreIsPresent() { + assertThat(hasNoScore().matches(new CalculatedTrust(null, null, null)), equalTo(true)); + } + + @Test + public void hasNoScoreMatcherDescribesItselfCorrectly() { + hasNoScore().describeTo(description); + assertThat(description.toString(), equalTo("has no score")); + } + + @Test + public void hasRankMatcherDoesNotMatchIfRankIsDifferent() { + assertThat(hasRank(123).matches(new CalculatedTrust(null, null, 99)), equalTo(false)); + } + + @Test + public void hasRankMatcherDescribesMismatchCorrectly() { + hasRank(123).describeMismatch(new CalculatedTrust(null, null, 99), description); + assertThat(description.toString(), equalTo("rank was <99>")); + } + + @Test + public void hasRankMatcherDoesNotMatchIfRankIsNull() { + assertThat(hasRank(123).matches(new CalculatedTrust(null, null, null)), equalTo(false)); + } + + @Test + public void hasRankMatcherDescribesMismatchWithNullCorrectly() { + hasRank(123).describeMismatch(new CalculatedTrust(null, null, null), description); + assertThat(description.toString(), equalTo("rank was null")); + } + + @Test + public void hasRankMatcherMatchesIfRankIsTheSame() { + assertThat(hasRank(99).matches(new CalculatedTrust(null, null, 99)), equalTo(true)); + } + + @Test + public void hasRankMatcherDescribesItselfCorrectly() { + hasRank(123).describeTo(description); + assertThat(description.toString(), equalTo("has rank <123>")); + } + + @Test + public void hasNoRankMatcherDoesNotMatchIfRankIsPresent() { + assertThat(hasNoRank().matches(new CalculatedTrust(null, null, 123)), equalTo(false)); + } + + @Test + public void hasNoRankMatcherDescribesMismatchCorrectly() { + hasNoRank().describeMismatch(new CalculatedTrust(null, null, 123), description); + assertThat(description.toString(), equalTo("rank was <123>")); + } + + @Test + public void hasNoRankMatcherMatchesIfNoRankIsPresent() { + assertThat(hasNoRank().matches(new CalculatedTrust(null, null, null)), equalTo(true)); + } + + @Test + public void hasNoRankMatcherDescribesItselfCorrectly() { + hasNoRank().describeTo(description); + assertThat(description.toString(), equalTo("has no rank")); + } + + private final Description description = new StringDescription(); + +}