✅ Add test for “BaseMessage”
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 10 Feb 2023 08:42:39 +0000 (09:42 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 10 Feb 2023 08:42:39 +0000 (09:42 +0100)
src/test/java/net/pterodactylus/fcp/BaseMessageTest.java [new file with mode: 0644]

diff --git a/src/test/java/net/pterodactylus/fcp/BaseMessageTest.java b/src/test/java/net/pterodactylus/fcp/BaseMessageTest.java
new file mode 100644 (file)
index 0000000..94503df
--- /dev/null
@@ -0,0 +1,40 @@
+package net.pterodactylus.fcp;
+
+import org.junit.Test;
+
+import static java.lang.String.format;
+import static java.util.stream.Collectors.toList;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.equalTo;
+
+/**
+ * Unit test for {@link BaseMessage}.
+ */
+public class BaseMessageTest {
+
+       @Test
+       public void baseMessageForwardsNameFromReceivedMessage() {
+               assertThat(baseMessage.getName(), equalTo("TestMessage"));
+       }
+
+       @Test
+       public void fieldFromReceivedMessageCanBeAccessed() {
+               receivedMessage.setField("TestField", "TestValue");
+               assertThat(baseMessage.getField("TestField"), equalTo("TestValue"));
+       }
+
+       @Test
+       public void allFieldsFromReceivedMessageCanBeAccessed() {
+               receivedMessage.setField("TestField1", "TestValue1");
+               receivedMessage.setField("TestField2", "TestValue2");
+               assertThat(baseMessage.getFields().entrySet().stream()
+                                               .map(e -> format("%s: %s", e.getKey(), e.getValue())).collect(toList()),
+                               containsInAnyOrder("TestField1: TestValue1", "TestField2: TestValue2")
+               );
+       }
+
+       private final FcpMessage receivedMessage = new FcpMessage("TestMessage");
+       private final BaseMessage baseMessage = new BaseMessage(receivedMessage);
+
+}