Log unhandled dead events

This commit is contained in:
2021-02-20 21:40:48 +01:00
parent 0036dc4829
commit b2fe3a9d6c
4 changed files with 34 additions and 11 deletions

View File

@ -2,7 +2,7 @@ package dev.kske.eventbus.core;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.Test;
/**
* Tests the dispatching of a dead event if an event could not be delivered.
@ -12,20 +12,32 @@ import org.junit.jupiter.api.*;
*/
class DeadTest {
EventBus bus;
EventBus bus = new EventBus();
String event = "This event has no handler";
boolean deadEventHandled;
@BeforeEach
void registerListener() {
bus = new EventBus();
bus.registerListener(this);
}
/**
* Tests dead event delivery.
*
* @since 1.1.0
*/
@Test
void testDeadEvent() {
bus.registerListener(this);
bus.dispatch(event);
assertTrue(deadEventHandled);
bus.removeListener(this);
}
/**
* Tests how the event bus reacts to an unhandled dead event. This should not lead to an
* exception or endless recursion and instead be logged.
*
* @since 1.1.0
*/
@Test
void testUnhandledDeadEvent() {
bus.dispatch(event);
}
@Event

View File

@ -27,8 +27,8 @@ class DispatchTest {
}
/**
* Tests {@link EventBus#dispatch(Object)} with multiple handler priorities, a subtype handler
* and a static handler.
* Tests {@link EventBus#dispatch(Object)} with multiple handler priorities, a polymorphic
* handler and a static handler.
*
* @since 0.0.1
*/