}
@Test
+ public void getIdentityTrustCanHandleMissingTrustValue() throws Exception {
+ TestFcpConnection fcpConnection = 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(), nullValue());
+ assertThat(calculatedTrust.getScore(), equalTo(56));
+ assertThat(calculatedTrust.getRank(), equalTo(1));
+ }
+
+ private TestFcpConnection createConnectionThatDeliversIdentityWithoutTrustButAScore() {
+ return createFcpConnection(message -> (listener, connection) -> {
+ Map<String, String> fields = createWebOfTrustReplyFields("Identity", true,
+ entries("Identities.Amount", "1"), identityNick0,
+ entries("Trusts.0.Value", "Nonexistent"),
+ entries("Scores.Amount", "1"), scoreValue
+ );
+ FcpMessage replyMessage = createPluginReply(message, fields);
+ listener.receivedFCPPluginReply(connection, new FCPPluginReply(replyMessage, null));
+ });
+ }
+
+ @Test
+ public void getIdentityTrustCanHandleMissingScoreAndRank() throws Exception {
+ TestFcpConnection fcpConnection = createConnectionThatDeliversIdentityWithTrustButWithoutScore();
+ 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());
+ }
+
+ private TestFcpConnection createConnectionThatDeliversIdentityWithTrustButWithoutScore() {
+ return createFcpConnection(message -> (listener, connection) -> {
+ Map<String, String> fields = createWebOfTrustReplyFields("Identity", true,
+ entries("Identities.Amount", "1"), identityNick0,
+ entries("Trusts.Amount", "1"), trustValue,
+ entries("Scores.0.Value", "Nonexistent")
+ );
+ FcpMessage replyMessage = createPluginReply(message, fields);
+ listener.receivedFCPPluginReply(connection, new FCPPluginReply(replyMessage, null));
+ });
+ }
+
+ @Test
public void getIdentityTrustFailsWhenDifferentReplyIsSentByPlugin() {
FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);