--- /dev/null
+package net.pterodactylus.fcp;
+
+/**
+ * Implementation of the “WatchFeeds” command.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class WatchFeeds extends FcpMessage {
+
+ public WatchFeeds(boolean enabled) {
+ super("WatchFeeds");
+ setField("Enabled", String.valueOf(enabled));
+ }
+
+}
--- /dev/null
+package net.pterodactylus.fcp;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Base test for all tests that verify a message’s appearance.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class AbstractFcpMessageTest {
+
+ protected List<String> encodeMessage(FcpMessage fcpMessage) throws Exception {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ fcpMessage.write(outputStream);
+ return Arrays.asList(outputStream.toString().split("\r?\n"));
+ }
+
+}
import static org.hamcrest.Matchers.contains;
import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.util.Arrays;
import java.util.List;
import org.junit.Test;
*
* @author <a href="mailto:david.roden@bietr.de">David Roden</a>
*/
-public class FcpMessageTest {
+public class FcpMessageTest extends AbstractFcpMessageTest {
private final FcpMessage fcpMessage = new FcpMessage("TestMessage");
@Test
public void fcpMessageWithPayloadIsTerminatedByData() throws Exception {
fcpMessage.setPayloadInputStream(new ByteArrayInputStream("Test".getBytes()));
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- fcpMessage.write(outputStream);
- List<String> lines = Arrays.asList(outputStream.toString().split("\r?\n"));
+ List<String> lines = encodeMessage(fcpMessage);
assertThat(lines, contains(
"TestMessage",
"Data",
--- /dev/null
+package net.pterodactylus.fcp;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+
+import org.junit.Test;
+
+/**
+ * Unit test for {@link WatchFeeds}.
+ *
+ * @author <a href="mailto:david.roden@bietr.de">David Roden</a>
+ */
+public class WatchFeedsTest extends AbstractFcpMessageTest {
+
+ @Test
+ public void enablingWatchFeedsSendsCorrectOutput() throws Exception {
+ WatchFeeds watchFeeds = new WatchFeeds(true);
+ assertThat(encodeMessage(watchFeeds), contains(
+ "WatchFeeds",
+ "Enabled=true",
+ "EndMessage"
+ ));
+ }
+
+ @Test
+ public void disablingWatchFeedsSendsCorrectOutput() throws Exception {
+ WatchFeeds watchFeeds = new WatchFeeds(false);
+ assertThat(encodeMessage(watchFeeds), contains(
+ "WatchFeeds",
+ "Enabled=false",
+ "EndMessage"
+ ));
+ }
+
+}