--- /dev/null
+package net.pterodactylus.fcp;
+
+import java.io.ByteArrayInputStream;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+public class SendBookmark extends FcpMessage {
+
+ public SendBookmark(String identifier, String nodeIdentifier, String uri, String name) {
+ super("SendBookmark");
+ setField("Identifier", identifier);
+ setField("NodeIdentifier", nodeIdentifier);
+ setField("URI", uri);
+ setField("Name", name);
+ }
+
+ public void setDescription(String description) {
+ byte[] encodedDescription = description.getBytes(UTF_8);
+ setField("DataLength", String.valueOf(encodedDescription.length));
+ setPayloadInputStream(new ByteArrayInputStream(encodedDescription));
+ }
+
+}
--- /dev/null
+package net.pterodactylus.fcp;
+
+import org.junit.Test;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static net.pterodactylus.fcp.test.InputStreamMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.nullValue;
+
+public class SendBookmarkTest {
+
+ @Test
+ public void sendBookmarkMessageHasCorrectName() {
+ assertThat(sendBookmark.getName(), equalTo("SendBookmark"));
+ }
+
+ @Test
+ public void sendBookmarkMessageSetsCorrectIdentifierField() {
+ assertThat(sendBookmark.getField("Identifier"), equalTo("identifier"));
+ }
+
+ @Test
+ public void sendBookmarkMessageSetCorrectNodeIdentifierField() {
+ assertThat(sendBookmark.getField("NodeIdentifier"), equalTo("node-identifier"));
+ }
+
+ @Test
+ public void sendBookmarkMessageSetsCorrectUriField() {
+ assertThat(sendBookmark.getField("URI"), equalTo("uri"));
+ }
+
+ @Test
+ public void sendBookmarkMessageSetsCorrectNameField() {
+ assertThat(sendBookmark.getField("Name"), equalTo("name"));
+ }
+
+ @Test
+ public void sendBookmarkMessageWithoutDescriptionDoesNotHaveDataLengthField() {
+ assertThat(sendBookmark.getField("DataLength"), nullValue());
+ }
+
+ @Test
+ public void sendBookmarkMessageWithoutDescriptionDoesNotHavePayload() {
+ assertThat(sendBookmark.getPayloadInputStream(), nullValue());
+ }
+
+ @Test
+ public void sendBookmarkMessageWithDescriptionSetsDataLengthFieldCorrectly() {
+ sendBookmark.setDescription("Hällo Wőrld");
+ assertThat(sendBookmark.getField("DataLength"), equalTo("13"));
+ }
+
+ @Test
+ public void sendBookmarkMessageWithDescriptionHasCorrectPayload() {
+ sendBookmark.setDescription("Hällo Wőrld");
+ assertThat(sendBookmark.getPayloadInputStream(), equalTo("Hällo Wőrld".getBytes(UTF_8)));
+ }
+
+ private final SendBookmark sendBookmark = new SendBookmark("identifier", "node-identifier", "uri", "name");
+
+}