From 303efaede0f7ad04cbc2879d9f0b5f8877a93164 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 10 Feb 2023 09:42:39 +0100 Subject: [PATCH] =?utf8?q?=E2=9C=85=20Add=20test=20for=20=E2=80=9CBaseMess?= =?utf8?q?age=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../net/pterodactylus/fcp/BaseMessageTest.java | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/test/java/net/pterodactylus/fcp/BaseMessageTest.java diff --git a/src/test/java/net/pterodactylus/fcp/BaseMessageTest.java b/src/test/java/net/pterodactylus/fcp/BaseMessageTest.java new file mode 100644 index 0000000..94503df --- /dev/null +++ b/src/test/java/net/pterodactylus/fcp/BaseMessageTest.java @@ -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); + +} -- 2.7.4