From: David ‘Bombe’ Roden Date: Mon, 19 Jan 2026 20:16:42 +0000 (+0100) Subject: ✅ Add test for removeContext() X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=a3fa480e571fd316215570c9471f7b7a00a43298;p=jFCPlib.git ✅ Add test for removeContext() --- diff --git a/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java b/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java index dc47706..ce3525f 100644 --- a/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java +++ b/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java @@ -636,6 +636,38 @@ public class WebOfTrustPluginTest { } + public static class RemoveContextTests extends Common { + + @Test + public void removeContextSendsTheCorrectCommand() throws Exception { + TestFcpConnection fcpConnection = createConnectionThatSendsContextRemoved(); + WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection); + webOfTrustPlugin.removeContext(ownIdentity, "TestContext"); + assertThat(fcpConnection.sentMessages.get(0), allOf( + isNamed(equalTo("FCPPluginMessage")), + hasField("Identifier", notNullValue()), + hasField("PluginName", equalTo("plugins.WebOfTrust.WebOfTrust")), + hasField("Param.Message", equalTo("RemoveContext")), + hasField("Param.Identity", equalTo("own-id")), + hasField("Param.Context", equalTo("TestContext")) + )); + } + + @Test + public void removeContextThrowsExceptionWhenDifferentReplyIsSentByPlugin() { + FcpConnection fcpConnection = createConnectionThatSendsOtherMessage(); + WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection); + assertThrows(FcpException.class, () -> webOfTrustPlugin.removeContext(ownIdentity, "TestContext")); + } + + private TestFcpConnection createConnectionThatSendsContextRemoved() { + return createConnection("ContextRemoved"); + } + + private final OwnIdentity ownIdentity = new OwnIdentity("own-id", "Own ID", "or", "ir", emptyList(), emptyMap()); + + } + private static class Common { @SafeVarargs