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

index fe92b48..5e73b73 100644 (file)
@@ -701,6 +701,46 @@ public class WebOfTrustPluginTest {
 
        }
 
+       public static class GetPropertyTests extends Common {
+
+               @Test
+               public void getPropertySendsTheCorrectCommand() throws Exception {
+                       TestFcpConnection fcpConnection = createConnectionThatSendsPropertyValue();
+                       WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+                       webOfTrustPlugin.getProperty(ownIdentity, "SomeProperty");
+                       assertThat(fcpConnection.sentMessages.get(0), allOf(
+                                       isNamed(equalTo("FCPPluginMessage")),
+                                       hasField("Identifier", notNullValue()),
+                                       hasField("PluginName", equalTo("plugins.WebOfTrust.WebOfTrust")),
+                                       hasField("Param.Message", equalTo("GetProperty")),
+                                       hasField("Param.Identity", equalTo("own-id")),
+                                       hasField("Param.Property", equalTo("SomeProperty"))
+                       ));
+               }
+
+               @Test
+               public void getPropertyReturnsTheCorrectValue() throws Exception {
+                       TestFcpConnection fcpConnection = createConnectionThatSendsPropertyValue();
+                       WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+                       String value = webOfTrustPlugin.getProperty(ownIdentity, "SomeProperty");
+                       assertThat(value, equalTo("SomeValue"));
+               }
+
+               @Test
+               public void getPropertyThrowsExceptionWhenDifferentReplyIsSentByPlugin() {
+                       FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
+                       WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+                       assertThrows(FcpException.class, () -> webOfTrustPlugin.getProperty(ownIdentity, "SomeProperty"));
+               }
+
+               private TestFcpConnection createConnectionThatSendsPropertyValue() {
+                       return createConnection("PropertyValue", entries("Property", "SomeValue"));
+               }
+
+               private final OwnIdentity ownIdentity = new OwnIdentity("own-id", "Own ID", "or", "ir", emptyList(), emptyMap());
+
+       }
+
        private static class Common {
 
                @SafeVarargs