From: David ‘Bombe’ Roden Date: Wed, 8 Jan 2025 15:45:41 +0000 (+0100) Subject: ✅ Add tests for missing trust and/or score values X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=5828f390c1f689162eead39fbddb02afabe70f4a;p=jFCPlib.git ✅ Add tests for missing trust and/or score values --- diff --git a/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java b/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java index cec4542..da95d87 100644 --- a/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java +++ b/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java @@ -284,6 +284,52 @@ public class WebOfTrustPluginTest { } @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 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 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);