🗑️ Deprecate WatchFeeds constructor with boolean argument
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 6 Jan 2025 10:56:38 +0000 (11:56 +0100)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 6 Jan 2025 10:56:38 +0000 (11:56 +0100)
src/main/java/net/pterodactylus/fcp/WatchFeeds.java
src/test/java/net/pterodactylus/fcp/WatchFeedsTest.java

index e71df53..7ad0086 100644 (file)
@@ -7,9 +7,22 @@ package net.pterodactylus.fcp;
  */
 public class WatchFeeds extends FcpMessage {
 
+       public WatchFeeds() {
+               super("WatchFeeds");
+       }
+
+       /**
+        * @deprecated Use {@link #WatchFeeds()}
+        *              and {@link #setEnabled(boolean)} instead
+        */
+       @Deprecated
        public WatchFeeds(boolean enabled) {
                super("WatchFeeds");
                setField("Enabled", String.valueOf(enabled));
        }
 
+       public void setEnabled(boolean enabled) {
+               setField("Enabled", String.valueOf(enabled));
+       }
+
 }
index 5482d73..1a5a91f 100644 (file)
@@ -2,8 +2,9 @@ package net.pterodactylus.fcp;
 
 import org.junit.Test;
 
-import static net.pterodactylus.fcp.test.Matchers.isMessage;
+import static net.pterodactylus.fcp.test.MessageTests.verifyFieldValueAfterSettingFlag;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.anEmptyMap;
 import static org.hamcrest.Matchers.equalTo;
 
 /**
@@ -18,15 +19,33 @@ public class WatchFeedsTest {
                assertThat(watchFeeds.getName(), equalTo("WatchFeeds"));
        }
 
-       public void enablingWatchFeedsSendsCorrectOutput() throws Exception {
-               WatchFeeds watchFeeds = new WatchFeeds(true);
-               assertThat(watchFeeds, isMessage("WatchFeeds", "Enabled=true"));
+       @Test
+       public void watchFeedsMessageWithoutArgumentsHasNoFieldsSet() {
+               assertThat(watchFeeds.getFields(), anEmptyMap());
        }
 
        @Test
-       public void disablingWatchFeedsSendsCorrectOutput() throws Exception {
+       public void settingEnabledToFalseSetsEnabledFieldToFalse() {
+               verifyFieldValueAfterSettingFlag(watchFeeds, WatchFeeds::setEnabled, "Enabled", false);
+       }
+
+       @Test
+       public void settingEnabledToTrueSetsEnabledFieldToTrue() {
+               verifyFieldValueAfterSettingFlag(watchFeeds, WatchFeeds::setEnabled, "Enabled", true);
+       }
+
+       @Test
+       public void watchFeedsMessageWithEnabledFalseSetsEnabledFieldToFalse() {
                WatchFeeds watchFeeds = new WatchFeeds(false);
-               assertThat(watchFeeds, isMessage("WatchFeeds", "Enabled=false"));
+               assertThat(watchFeeds.getField("Enabled"), equalTo("false"));
+       }
+
+       @Test
+       public void watchFeedsMessageWithEnabledTrueSetsEnabledFieldToTrue() {
+               WatchFeeds watchFeeds = new WatchFeeds(true);
+               assertThat(watchFeeds.getField("Enabled"), equalTo("true"));
        }
 
+       private final WatchFeeds watchFeeds = new WatchFeeds();
+
 }