From 9ca04a65290ac61ec8c960bff194e5340718111a Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 11 Sep 2016 17:00:59 +0200 Subject: [PATCH] =?utf8?q?Add=20=E2=80=9CWatchFeeds=E2=80=9D=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/net/pterodactylus/fcp/WatchFeeds.java | 15 ++++++++++ .../pterodactylus/fcp/AbstractFcpMessageTest.java | 21 +++++++++++++ .../java/net/pterodactylus/fcp/FcpMessageTest.java | 8 ++--- .../java/net/pterodactylus/fcp/WatchFeedsTest.java | 35 ++++++++++++++++++++++ 4 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 src/main/java/net/pterodactylus/fcp/WatchFeeds.java create mode 100644 src/test/java/net/pterodactylus/fcp/AbstractFcpMessageTest.java create mode 100644 src/test/java/net/pterodactylus/fcp/WatchFeedsTest.java diff --git a/src/main/java/net/pterodactylus/fcp/WatchFeeds.java b/src/main/java/net/pterodactylus/fcp/WatchFeeds.java new file mode 100644 index 0000000..e71df53 --- /dev/null +++ b/src/main/java/net/pterodactylus/fcp/WatchFeeds.java @@ -0,0 +1,15 @@ +package net.pterodactylus.fcp; + +/** + * Implementation of the “WatchFeeds” command. + * + * @author David ‘Bombe’ Roden + */ +public class WatchFeeds extends FcpMessage { + + public WatchFeeds(boolean enabled) { + super("WatchFeeds"); + setField("Enabled", String.valueOf(enabled)); + } + +} diff --git a/src/test/java/net/pterodactylus/fcp/AbstractFcpMessageTest.java b/src/test/java/net/pterodactylus/fcp/AbstractFcpMessageTest.java new file mode 100644 index 0000000..d5c9d24 --- /dev/null +++ b/src/test/java/net/pterodactylus/fcp/AbstractFcpMessageTest.java @@ -0,0 +1,21 @@ +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 David ‘Bombe’ Roden + */ +public class AbstractFcpMessageTest { + + protected List encodeMessage(FcpMessage fcpMessage) throws Exception { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + fcpMessage.write(outputStream); + return Arrays.asList(outputStream.toString().split("\r?\n")); + } + +} diff --git a/src/test/java/net/pterodactylus/fcp/FcpMessageTest.java b/src/test/java/net/pterodactylus/fcp/FcpMessageTest.java index bc0dbd1..e2b9fcf 100644 --- a/src/test/java/net/pterodactylus/fcp/FcpMessageTest.java +++ b/src/test/java/net/pterodactylus/fcp/FcpMessageTest.java @@ -4,8 +4,6 @@ import static org.hamcrest.MatcherAssert.assertThat; 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; @@ -15,16 +13,14 @@ import org.junit.Test; * * @author David Roden */ -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 lines = Arrays.asList(outputStream.toString().split("\r?\n")); + List lines = encodeMessage(fcpMessage); assertThat(lines, contains( "TestMessage", "Data", diff --git a/src/test/java/net/pterodactylus/fcp/WatchFeedsTest.java b/src/test/java/net/pterodactylus/fcp/WatchFeedsTest.java new file mode 100644 index 0000000..e4bedfe --- /dev/null +++ b/src/test/java/net/pterodactylus/fcp/WatchFeedsTest.java @@ -0,0 +1,35 @@ +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 David Roden + */ +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" + )); + } + +} -- 2.7.4