From: David ‘Bombe’ Roden Date: Fri, 10 Feb 2023 08:42:39 +0000 (+0100) Subject: ✅ Add test for “BaseMessage” X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=303efaede0f7ad04cbc2879d9f0b5f8877a93164;p=jFCPlib.git ✅ Add test for “BaseMessage” --- 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); + +}