Add DeadEvent

A dead events wraps an event that was dispatched but not delivered to
any handler. The dead event is than dispatched to dedicated handlers.
This commit is contained in:
2021-02-19 16:04:49 +01:00
parent 4a5b94a9b7
commit 0036dc4829
4 changed files with 90 additions and 15 deletions

View File

@ -0,0 +1,37 @@
package dev.kske.eventbus.core;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.*;
/**
* Tests the dispatching of a dead event if an event could not be delivered.
*
* @author Kai S. K. Engelbart
* @since 1.1.0
*/
class DeadTest {
EventBus bus;
String event = "This event has no handler";
boolean deadEventHandled;
@BeforeEach
void registerListener() {
bus = new EventBus();
bus.registerListener(this);
}
@Test
void testDeadEvent() {
bus.dispatch(event);
assertTrue(deadEventHandled);
}
@Event
void onDeadEvent(DeadEvent deadEvent) {
assertEquals(bus, deadEvent.getEventBus());
assertEquals(event, deadEvent.getEvent());
deadEventHandled = true;
}
}