From: David ‘Bombe’ Roden Date: Sun, 11 Sep 2016 15:00:59 +0000 (+0200) Subject: Add “WatchFeeds” command X-Git-Tag: v0.1.5^2~2 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=9ca04a65290ac61ec8c960bff194e5340718111a;p=jFCPlib.git Add “WatchFeeds” command --- 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" + )); + } + +}