🗑️ Deprecate ListPeers constructor with flags
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Thu, 2 Jan 2025 22:54:39 +0000 (23:54 +0100)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Thu, 2 Jan 2025 22:54:39 +0000 (23:54 +0100)
src/main/java/net/pterodactylus/fcp/ListPeers.java
src/main/java/net/pterodactylus/fcp/highlevel/FcpClient.java
src/test/java/net/pterodactylus/fcp/ListPeersTest.java

index b951cae..82c80e2 100644 (file)
@@ -32,7 +32,8 @@ public class ListPeers extends FcpMessage {
         *            The identifier of the request
         */
        public ListPeers(String identifier) {
-               this(identifier, false, false);
+               super("ListPeers");
+               setField("Identifier", identifier);
        }
 
        /**
@@ -47,11 +48,22 @@ public class ListPeers extends FcpMessage {
         * @param withVolatile
         *            if <code>true</code> volatile data of the peers is included
         *            in the reply
+        * @deprecated Use {@link #ListPeers(String)},
+        * {@link #setWithMetadata(boolean)},
+        * and {@link #setWithVolatile(boolean)} instead.
         */
+       @Deprecated
        public ListPeers(String identifier, boolean withMetadata, boolean withVolatile) {
-               super("ListPeers");
-               setField("Identifier", identifier);
+               this(identifier);
+               setField("WithMetadata", String.valueOf(withMetadata));
+               setField("WithVolatile", String.valueOf(withVolatile));
+       }
+
+       public void setWithMetadata(boolean withMetadata) {
                setField("WithMetadata", String.valueOf(withMetadata));
+       }
+
+       public void setWithVolatile(boolean withVolatile) {
                setField("WithVolatile", String.valueOf(withVolatile));
        }
 
index cf541f4..b659293 100644 (file)
@@ -463,7 +463,10 @@ public class FcpClient implements Closeable {
                        @Override
                        @SuppressWarnings("synthetic-access")
                        public void run() throws IOException {
-                               sendMessage(new ListPeers(identifier, withMetadata, withVolatile));
+                               ListPeers listPeers = new ListPeers(identifier);
+                               listPeers.setWithMetadata(withMetadata);
+                               listPeers.setWithVolatile(withVolatile);
+                               sendMessage(listPeers);
                        }
 
                        /**
index 8c851c1..f2bbd1d 100644 (file)
@@ -2,18 +2,49 @@ package net.pterodactylus.fcp;
 
 import org.junit.Test;
 
+import static net.pterodactylus.fcp.test.MessageTests.verifyFieldValueAfterSettingFlag;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.nullValue;
 
 public class ListPeersTest {
 
        @Test
        public void listPeersWithIdentifierSetsIdentifierField() {
-               ListPeers listPeers = new ListPeers("identifier");
                assertThat(listPeers.getField("Identifier"), equalTo("identifier"));
        }
 
        @Test
+       public void listPeersWithIdentifierDoesNotSetWithMetadataField() {
+               assertThat(listPeers.getField("WithMetadata"), nullValue());
+       }
+
+       @Test
+       public void settingWithMetadataToFalseOnListPeersResultsInWithMetadataFieldBeingSetToFalse() {
+               verifyFieldValueAfterSettingFlag(listPeers, ListPeers::setWithMetadata, "WithMetadata", false);
+       }
+
+       @Test
+       public void settingWithMetadataToTrueOnListPeersResultsInWithMetadataFieldBeingSetToTrue() {
+               verifyFieldValueAfterSettingFlag(listPeers, ListPeers::setWithMetadata, "WithMetadata", true);
+       }
+
+       @Test
+       public void listPeersWithIdentifierDoesNotSetWithVolatileField() {
+               assertThat(listPeers.getField("WithVolatile"), nullValue());
+       }
+
+       @Test
+       public void settingWithVolatileToFalseOnListPeersResultsInWithVolatileFieldBeingSetToFalse() {
+               verifyFieldValueAfterSettingFlag(listPeers, ListPeers::setWithVolatile, "WithVolatile", false);
+       }
+
+       @Test
+       public void settingWithVolatileToTrueOnListPeersResultsInWithVolatileFieldBeingSetToTrue() {
+               verifyFieldValueAfterSettingFlag(listPeers, ListPeers::setWithVolatile, "WithVolatile", true);
+       }
+
+       @Test
        public void listPeersWithIdentifierAndFlagsSetsIdentifierAndFlagFields() {
                ListPeers listPeers = new ListPeers("identifier", false, true);
                assertThat(listPeers.getField("Identifier"), equalTo("identifier"));
@@ -21,4 +52,6 @@ public class ListPeersTest {
                assertThat(listPeers.getField("WithVolatile"), equalTo("true"));
        }
 
+       private final ListPeers listPeers = new ListPeers("identifier");
+
 }