🗑️ Deprecate all constructors in WatchGlobal
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Tue, 7 Jan 2025 06:52:29 +0000 (07:52 +0100)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Tue, 7 Jan 2025 06:52:29 +0000 (07:52 +0100)
src/main/java/net/pterodactylus/fcp/WatchGlobal.java
src/main/java/net/pterodactylus/fcp/highlevel/FcpClient.java
src/test/java/net/pterodactylus/fcp/WatchGlobalTest.java

index 683cb69..7605043 100644 (file)
@@ -25,6 +25,10 @@ package net.pterodactylus.fcp;
  */
 public class WatchGlobal extends FcpMessage {
 
+       public WatchGlobal() {
+               super("WatchGlobal");
+       }
+
        /**
         * Enables or disables watching the global queue.
         *
@@ -32,9 +36,14 @@ public class WatchGlobal extends FcpMessage {
         *            <code>true</code> to watch the global queue and the
         *            client-local queue, <code>false</code> to watch only the
         *            client-local queue
+        * @deprecated Use {@link #WatchGlobal()} and
+        *        {@link #setEnabled(boolean)} instead
         */
+       @Deprecated
        public WatchGlobal(boolean enabled) {
-               this(enabled, Verbosity.ALL);
+               this();
+               setEnabled(enabled);
+               setVerbosity(Verbosity.ALL);
        }
 
        /**
@@ -47,11 +56,23 @@ public class WatchGlobal extends FcpMessage {
         *            client-local queue
         * @param verbosityMask
         *            A verbosity mask that determines which events are received
+        * @deprecated Use {@link #WatchGlobal()},
+        *        {@link #setEnabled(boolean)}, and
+        *        {@link #setVerbosity(Verbosity)} instead
         */
+       @Deprecated
        public WatchGlobal(boolean enabled, Verbosity verbosityMask) {
-               super("WatchGlobal");
+               this();
                setField("Enabled", String.valueOf(enabled));
                setField("VerbosityMask", String.valueOf(verbosityMask));
        }
 
+       public void setEnabled(boolean enabled) {
+               setField("Enabled", String.valueOf(enabled));
+       }
+
+       public void setVerbosity(Verbosity verbosity) {
+               setField("VerbosityMask", verbosity.toString());
+       }
+
 }
index a3ee4ca..38381ff 100644 (file)
@@ -299,7 +299,7 @@ public class FcpClient implements Closeable {
                                fcpConnection.connect();
                                ClientHello clientHello = new ClientHello(name);
                                sendMessage(clientHello);
-                               WatchGlobal watchGlobal = new WatchGlobal(true);
+                               WatchGlobal watchGlobal = new WatchGlobal();
                                sendMessage(watchGlobal);
                        }
 
index 41cdecc..9b270eb 100644 (file)
@@ -2,8 +2,11 @@ package net.pterodactylus.fcp;
 
 import org.junit.Test;
 
+import static net.pterodactylus.fcp.test.MessageTests.verifyFieldValueAfterSettingFlag;
+import static net.pterodactylus.fcp.test.MessageTests.verifyFieldValueAfterSettingProperty;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.nullValue;
 
 public class WatchGlobalTest {
 
@@ -45,4 +48,36 @@ public class WatchGlobalTest {
                assertThat(watchGlobal.getField("VerbosityMask"), equalTo("512"));
        }
 
+       @Test
+       public void watchGlobalMessageHasCorrectName() {
+               assertThat(watchGlobal.getName(), equalTo("WatchGlobal"));
+       }
+
+       @Test
+       public void watchGlobalMessageHasNoEnabledField() {
+               assertThat(watchGlobal.getField("Enabled"), nullValue());
+       }
+
+       @Test
+       public void settingEnabledToFalseResultsInEnabledFieldBeingSetToFalse() {
+               verifyFieldValueAfterSettingFlag(watchGlobal, WatchGlobal::setEnabled, "Enabled", false);
+       }
+
+       @Test
+       public void settingEnabledToTrueResultsInEnabledFieldBeingSetToTrue() {
+               verifyFieldValueAfterSettingFlag(watchGlobal, WatchGlobal::setEnabled, "Enabled", true);
+       }
+
+       @Test
+       public void watchGlobalMessageHasNoVerbosityMaskField() {
+               assertThat(watchGlobal.getField("VerbosityMask"), nullValue());
+       }
+
+       @Test
+       public void settingVerbosityResultsInVerbosityMaskFieldBeingSet() {
+               verifyFieldValueAfterSettingProperty(watchGlobal, WatchGlobal::setVerbosity, "VerbosityMask", Verbosity.PROGRESS, equalTo("1"));
+       }
+
+       private final WatchGlobal watchGlobal = new WatchGlobal();
+
 }