From 53508d7c83df154ff1247c5916d123696616f7a1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 19 Jan 2026 20:43:45 +0100 Subject: [PATCH] =?utf8?q?=E2=9C=85=20Add=20test=20for=20setTrust()?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../pterodactylus/fcp/plugin/WebOfTrustPlugin.java | 2 +- .../fcp/plugin/WebOfTrustPluginTest.java | 36 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) 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 -- 2.7.4