MessageTarget
The MessageTarget
interface is a small interface implemented by methods that can receive messages. Two examples of message targets are ConsoleCommandSenderMock
and EntityMock
.
Using MessageTarget
Any message that was sent to the target can be read using
java
@Test
void test_receive(){
SimpleEntityMock entity = new SimpleEntityMock();
entity.sendMessage("Hello world!");
String message = entity.nextMessage();
}
kotlin
@Test
fun test_receive() {
val entity = SimpleEntityMock()
entity.sendMessage("Hello world!")
val message = entity.nextMessage()
}
It also contains two assert methods to check if a message was or wasn’t received.
java
@Test
void test_assert(){
SimpleEntityMock entity = new SimpleEntityMock();
entity.sendMessage("Hello world!");
entity.assertSaid("Hello world!");
entity.assertNoMoreSaid();
}
kotlin
@Test
fun test_assert() {
val entity = SimpleEntityMock()
entity.sendMessage("Hello world!")
entity.assertSaid("Hello world!");
entity.assertNoMoreSaid();
}