✅ Add test for setTrust()
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 19 Jan 2026 19:43:45 +0000 (20:43 +0100)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 19 Jan 2026 19:43:45 +0000 (20:43 +0100)
src/main/java/net/pterodactylus/fcp/plugin/WebOfTrustPlugin.java
src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java

index ceebf75..76606d2 100644 (file)
@@ -302,7 +302,7 @@ public class WebOfTrustPlugin {
         * @throws FcpException
         *             if an FCP error occurs
         */
-       public void setTrust(OwnIdentity ownIdentity, Identity identity, byte trust, String comment) throws IOException, FcpException {
+       public void setTrust(OwnIdentity ownIdentity, Identity identity, int trust, String comment) throws IOException, FcpException {
                Map<String, String> replies = fcpClient.sendPluginMessage(webOfTrustPluginName, createParameters("Message", "SetTrust", "Truster", ownIdentity.getIdentifier(), "Trustee", identity.getIdentifier(), "Value", String.valueOf(trust), "Comment", comment));
                if (!replies.get("Message").equals("TrustSet")) {
                        throw new FcpException("WebOfTrust Plugin did not reply with “TrustSet” message!");
index 4bd1c2c..befab5e 100644 (file)
@@ -25,6 +25,7 @@ import org.junit.experimental.runners.Enclosed;
 import org.junit.rules.Timeout;
 import org.junit.runner.RunWith;
 
+import static java.util.Collections.emptyList;
 import static java.util.Collections.emptyMap;
 import static java.util.Collections.emptySet;
 import static net.pterodactylus.fcp.test.IdentityMatchers.hasContexts;
@@ -568,6 +569,41 @@ public class WebOfTrustPluginTest {
 
        }
 
+       public static class SetTrustTests extends Common {
+
+               @Test
+               public void setTrustSendsCorrectCommand() throws Exception {
+                       TestFcpConnection fcpConnection = createConnectionThatSendsTrustSet();
+                       WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+                       webOfTrustPlugin.setTrust(ownIdentity, identity, 123, "Test Trust");
+                       assertThat(fcpConnection.sentMessages.get(0), allOf(
+                                       isNamed(equalTo("FCPPluginMessage")),
+                                       hasField("Identifier", notNullValue()),
+                                       hasField("PluginName", equalTo("plugins.WebOfTrust.WebOfTrust")),
+                                       hasField("Param.Message", equalTo("SetTrust")),
+                                       hasField("Param.Truster", equalTo("own-id")),
+                                       hasField("Param.Trustee", equalTo("ext-id")),
+                                       hasField("Param.Value", equalTo("123")),
+                                       hasField("Param.Comment", equalTo("Test Trust"))
+                       ));
+               }
+
+               @Test
+               public void setTrustThrowsExceptionWhenDifferentReplyIsSentByPlugin() {
+                       FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
+                       WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+                       assertThrows(FcpException.class, () -> webOfTrustPlugin.setTrust(ownIdentity, identity, 123, "Test Trust"));
+               }
+
+               private TestFcpConnection createConnectionThatSendsTrustSet() {
+                       return createConnection("TrustSet");
+               }
+
+               private final OwnIdentity ownIdentity = new OwnIdentity("own-id", "Own ID", "or", "ir", emptyList(), emptyMap());
+               private final Identity identity = new Identity("ext-id", "Ext ID", "er", emptyList(), emptyMap());
+
+       }
+
        private static class Common {
 
                @SafeVarargs