✅ Add test for setProperty()
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 19 Jan 2026 20:41:35 +0000 (21:41 +0100)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 19 Jan 2026 20:53:44 +0000 (21:53 +0100)
src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java

index ce3525f..fe92b48 100644 (file)
@@ -668,6 +668,39 @@ public class WebOfTrustPluginTest {
 
        }
 
+       public static class SetPropertyTests extends Common {
+
+               @Test
+               public void setPropertySendsTheCorrectCommand() throws Exception {
+                       TestFcpConnection fcpConnection = createConnectionThatSendsPropertyAdded();
+                       WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+                       webOfTrustPlugin.setProperty(ownIdentity, "SomeProperty", "SomeValue");
+                       assertThat(fcpConnection.sentMessages.get(0), allOf(
+                                       isNamed(equalTo("FCPPluginMessage")),
+                                       hasField("Identifier", notNullValue()),
+                                       hasField("PluginName", equalTo("plugins.WebOfTrust.WebOfTrust")),
+                                       hasField("Param.Message", equalTo("SetProperty")),
+                                       hasField("Param.Identity", equalTo("own-id")),
+                                       hasField("Param.Property", equalTo("SomeProperty")),
+                                       hasField("Param.Value", equalTo("SomeValue"))
+                       ));
+               }
+
+               @Test
+               public void setPropertyThrowsExceptionWhenDifferentReplyIsSentByPlugin() {
+                       FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
+                       WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+                       assertThrows(FcpException.class, () -> webOfTrustPlugin.setProperty(ownIdentity, "SomeProperty", "SomeValue"));
+               }
+
+               private TestFcpConnection createConnectionThatSendsPropertyAdded() {
+                       return createConnection("PropertyAdded");
+               }
+
+               private final OwnIdentity ownIdentity = new OwnIdentity("own-id", "Own ID", "or", "ir", emptyList(), emptyMap());
+
+       }
+
        private static class Common {
 
                @SafeVarargs