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;
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;
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
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
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() {
WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
Set<OwnIdentity> 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")))
+ )
));
}
WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
Set<OwnIdentity> 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")))
+ )
));
}
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() {
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() {
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() {
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
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
Collection<Identity> 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),
))
),
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),
public class IdentityMatchers {
- public static Matcher<OwnIdentity> isOwnIdentity(Matcher<? super String> identifier, Matcher<? super String> nickname, Matcher<? super String> requestUri, Matcher<? super String> insertUri) {
- return new TypeSafeDiagnosingMatcher<OwnIdentity>(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
};
}
- public static Matcher<Identity> isIdentity(Matcher<? super String> identifier, Matcher<? super String> nickname, Matcher<? super String> requestUri) {
- return new TypeSafeDiagnosingMatcher<Identity>(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
--- /dev/null
+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<CalculatedTrust> hasTrust(int trust) {
+ return new TypeSafeDiagnosingMatcher<CalculatedTrust>() {
+ @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<CalculatedTrust> hasNoTrust() {
+ return new TypeSafeDiagnosingMatcher<CalculatedTrust>() {
+ @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<CalculatedTrust> hasScore(int score) {
+ return new TypeSafeDiagnosingMatcher<CalculatedTrust>() {
+ @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<CalculatedTrust> hasNoScore() {
+ return new TypeSafeDiagnosingMatcher<CalculatedTrust>() {
+ @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<CalculatedTrust> hasRank(int rank) {
+ return new TypeSafeDiagnosingMatcher<CalculatedTrust>() {
+ @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<CalculatedTrust> hasNoRank() {
+ return new TypeSafeDiagnosingMatcher<CalculatedTrust>() {
+ @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");
+ }
+ };
+ }
+
+}
--- /dev/null
+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();
+
+}