event-bus is now a parent project containing the two modules event-bus-core (the previous event-bus) and event-bus-ap (annotation processor). The version of the parent project (and thus that of the modules) has been bumped to 1.0.0, as this change breaks compatibility with previous versions due to the different artifact, module and package names.
59 lines
1.2 KiB
Java
59 lines
1.2 KiB
Java
package dev.kske.eventbus.core;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
import org.junit.jupiter.api.*;
|
|
|
|
/**
|
|
* Tests the dispatching mechanism of the event bus.
|
|
*
|
|
* @author Kai S. K. Engelbart
|
|
* @since 0.0.1
|
|
*/
|
|
class DispatchTest implements EventListener {
|
|
|
|
EventBus bus;
|
|
static int hits;
|
|
|
|
/**
|
|
* Constructs an event bus and registers this test instance as an event listener.
|
|
*
|
|
* @since 0.0.1
|
|
*/
|
|
@BeforeEach
|
|
void registerListener() {
|
|
bus = new EventBus();
|
|
bus.registerListener(this);
|
|
}
|
|
|
|
/**
|
|
* Tests {@link EventBus#dispatch(IEvent)} with multiple handler priorities, a subtype handler
|
|
* and a static handler.
|
|
*
|
|
* @since 0.0.1
|
|
*/
|
|
@Test
|
|
void testDispatch() {
|
|
bus.dispatch(new SimpleEventSub());
|
|
bus.dispatch(new SimpleEvent());
|
|
}
|
|
|
|
@Event(eventType = SimpleEvent.class, includeSubtypes = true, priority = 200)
|
|
void onSimpleEventFirst() {
|
|
++hits;
|
|
assertTrue(hits == 1 || hits == 2);
|
|
}
|
|
|
|
@Event(eventType = SimpleEvent.class, priority = 150)
|
|
static void onSimpleEventSecond() {
|
|
++hits;
|
|
assertEquals(3, hits);
|
|
}
|
|
|
|
@Event(priority = 100)
|
|
void onSimpleEventThird(SimpleEvent event) {
|
|
++hits;
|
|
assertEquals(4, hits);
|
|
}
|
|
}
|