From: David ‘Bombe’ Roden Date: Tue, 7 Jan 2025 06:52:29 +0000 (+0100) Subject: 🗑️ Deprecate all constructors in WatchGlobal X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=2eccf596e1bc9217334a540992a43bd60fbb2f83;p=jFCPlib.git 🗑️ Deprecate all constructors in WatchGlobal --- diff --git a/src/main/java/net/pterodactylus/fcp/WatchGlobal.java b/src/main/java/net/pterodactylus/fcp/WatchGlobal.java index 683cb69..7605043 100644 --- a/src/main/java/net/pterodactylus/fcp/WatchGlobal.java +++ b/src/main/java/net/pterodactylus/fcp/WatchGlobal.java @@ -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 { * true to watch the global queue and the * client-local queue, false 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()); + } + } diff --git a/src/main/java/net/pterodactylus/fcp/highlevel/FcpClient.java b/src/main/java/net/pterodactylus/fcp/highlevel/FcpClient.java index a3ee4ca..38381ff 100644 --- a/src/main/java/net/pterodactylus/fcp/highlevel/FcpClient.java +++ b/src/main/java/net/pterodactylus/fcp/highlevel/FcpClient.java @@ -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); } diff --git a/src/test/java/net/pterodactylus/fcp/WatchGlobalTest.java b/src/test/java/net/pterodactylus/fcp/WatchGlobalTest.java index 41cdecc..9b270eb 100644 --- a/src/test/java/net/pterodactylus/fcp/WatchGlobalTest.java +++ b/src/test/java/net/pterodactylus/fcp/WatchGlobalTest.java @@ -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(); + }