From: David ‘Bombe’ Roden Date: Fri, 6 Sep 2024 11:35:49 +0000 (+0200) Subject: ✅ Add tests for getSeedPeers() X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=da3a336d1d01fcd64b502068d3f76c3f9bd79c74;p=jFCPlib.git ✅ Add tests for getSeedPeers() --- diff --git a/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java b/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java index e808c5c..a307c6c 100644 --- a/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java @@ -231,6 +231,31 @@ public class FcpClientTest { sendListPeersAndVerifySentMessagesAndReturnedPeers(FcpClientTest::getOpennetPeers, false, false, anything(), contains(peerWithIdentity(equalTo("1")))); } + @Test + public void getSeedPeersWithMetadataFlagSetSendsCorrectMessage() throws Exception { + sendListPeersAndVerifySentMessagesAndReturnedPeers(FcpClientTest::getSeedPeers, true, false, contains(hasField("WithMetadata", equalTo("true"))), anything()); + } + + @Test + public void getSeedPeersWithMetadataFlagNotSetSendsCorrectMessage() throws Exception { + sendListPeersAndVerifySentMessagesAndReturnedPeers(FcpClientTest::getSeedPeers, false, false, contains(hasField("WithMetadata", equalTo("false"))), anything()); + } + + @Test + public void getSeedPeersWithVolatileFlagSetSendsCorrectMessage() throws Exception { + sendListPeersAndVerifySentMessagesAndReturnedPeers(FcpClientTest::getSeedPeers, false, true, contains(hasField("WithVolatile", equalTo("true"))), anything()); + } + + @Test + public void getSeedPeersWithVolatileFlagNotSetSendsCorrectMessage() throws Exception { + sendListPeersAndVerifySentMessagesAndReturnedPeers(FcpClientTest::getSeedPeers, false, false, contains(hasField("WithVolatile", equalTo("false"))), anything()); + } + + @Test + public void getSeedPeersReturnsPeersWithCorrectIdentifier() throws Exception { + sendListPeersAndVerifySentMessagesAndReturnedPeers(FcpClientTest::getSeedPeers, false, false, anything(), contains(peerWithIdentity(equalTo("2")))); + } + private static BiFunction> getPeers(FcpClient fcpClient) { return (withMetadata, withVolatile) -> { try { @@ -261,6 +286,16 @@ public class FcpClientTest { }; } + private static BiFunction> getSeedPeers(FcpClient fcpClient) { + return (withMetadata, withVolatile) -> { + try { + return fcpClient.getSeedPeers(withMetadata, withVolatile); + } catch (IOException | FcpException e) { + throw new RuntimeException(e); + } + }; + } + private static void sendListPeersAndVerifySentMessagesAndReturnedPeers(Function>> peerRetrieval, boolean withMetadataFlag, boolean withVolatileFlag, Matcher> sentMessagesMatcher, Matcher> peersMatcher) throws IOException, FcpException { List sentMessages = new ArrayList<>(); FcpConnection fcpConnection = createFcpConnection(message -> {