From: David ‘Bombe’ Roden Date: Mon, 19 Jan 2026 19:43:45 +0000 (+0100) Subject: ✅ Add test for setTrust() X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=53508d7c83df154ff1247c5916d123696616f7a1;p=jFCPlib.git ✅ Add test for setTrust() --- diff --git a/src/main/java/net/pterodactylus/fcp/plugin/WebOfTrustPlugin.java b/src/main/java/net/pterodactylus/fcp/plugin/WebOfTrustPlugin.java index ceebf75..76606d2 100644 --- a/src/main/java/net/pterodactylus/fcp/plugin/WebOfTrustPlugin.java +++ b/src/main/java/net/pterodactylus/fcp/plugin/WebOfTrustPlugin.java @@ -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 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!"); diff --git a/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java b/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java index 4bd1c2c..befab5e 100644 --- a/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java +++ b/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java @@ -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