From: David ‘Bombe’ Roden Date: Mon, 19 Jan 2026 19:57:51 +0000 (+0100) Subject: ✅ Add test for addContext() X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=4d59963a54592ab92f34c9007b23652d8e79395a;p=jFCPlib.git ✅ Add test for addContext() --- diff --git a/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java b/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java index befab5e..dc47706 100644 --- a/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java +++ b/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java @@ -604,6 +604,38 @@ public class WebOfTrustPluginTest { } + public static class AddContextTests extends Common { + + @Test + public void addContextSendsTheCorrectCommand() throws IOException, FcpException { + TestFcpConnection fcpConnection = createConnectionThatSendsContextAdded(); + WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection); + webOfTrustPlugin.addContext(ownIdentity, "TestContext"); + assertThat(fcpConnection.sentMessages.get(0), allOf( + isNamed(equalTo("FCPPluginMessage")), + hasField("Identifier", notNullValue()), + hasField("PluginName", equalTo("plugins.WebOfTrust.WebOfTrust")), + hasField("Param.Message", equalTo("AddContext")), + hasField("Param.Identity", equalTo("own-id")), + hasField("Param.Context", equalTo("TestContext")) + )); + } + + @Test + public void addContextThrowsExceptionWhenDifferentReplyIsSentByPlugin() { + FcpConnection fcpConnection = createConnectionThatSendsOtherMessage(); + WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection); + assertThrows(FcpException.class, () -> webOfTrustPlugin.addContext(ownIdentity, "TestContext")); + } + + private TestFcpConnection createConnectionThatSendsContextAdded() { + return createConnection("ContextAdded"); + } + + private final OwnIdentity ownIdentity = new OwnIdentity("own-id", "Own ID", "or", "ir", emptyList(), emptyMap()); + + } + private static class Common { @SafeVarargs