2020-09-03 09:52:00 +02:00
|
|
|
package dev.kske.eventbus;
|
|
|
|
|
2020-09-20 12:20:29 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
2020-09-03 09:52:00 +02:00
|
|
|
|
|
|
|
import org.junit.jupiter.api.*;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests the of the event bus library.
|
|
|
|
*
|
|
|
|
* @author Kai S. K. Engelbart
|
|
|
|
* @since 0.0.1
|
|
|
|
*/
|
|
|
|
class EventBusTest implements EventListener {
|
|
|
|
|
2020-09-25 16:22:27 +02:00
|
|
|
static int hits;
|
2020-09-03 09:52:00 +02:00
|
|
|
|
|
|
|
@BeforeEach
|
|
|
|
public void registerListener() {
|
2020-09-08 09:38:46 +02:00
|
|
|
EventBus.getInstance().registerListener(this);
|
2020-09-03 09:52:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testDispatch() {
|
2020-09-20 12:20:29 +02:00
|
|
|
EventBus.getInstance().dispatch(new SimpleEventSub());
|
2020-09-08 09:38:46 +02:00
|
|
|
EventBus.getInstance().dispatch(new SimpleEvent());
|
2020-09-03 09:52:00 +02:00
|
|
|
}
|
|
|
|
|
2020-09-20 12:20:29 +02:00
|
|
|
@Event(
|
|
|
|
eventType = SimpleEvent.class,
|
|
|
|
includeSubtypes = true,
|
|
|
|
priority = 200
|
|
|
|
)
|
|
|
|
private void onSimpleEventFirst() {
|
2020-09-03 09:52:00 +02:00
|
|
|
++hits;
|
2020-09-20 12:20:29 +02:00
|
|
|
assertTrue(hits == 1 || hits == 2);
|
2020-09-03 09:52:00 +02:00
|
|
|
}
|
|
|
|
|
2020-09-08 19:47:21 +02:00
|
|
|
@Event(eventType = SimpleEvent.class, priority = 150)
|
2020-09-25 16:22:27 +02:00
|
|
|
private static void onSimpleEventSecond() {
|
2020-09-20 12:20:29 +02:00
|
|
|
++hits;
|
|
|
|
assertEquals(3, hits);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Event(priority = 50)
|
|
|
|
private void onSimpleEventThird(SimpleEvent event) {
|
2020-09-03 09:52:00 +02:00
|
|
|
++hits;
|
2020-09-20 12:20:29 +02:00
|
|
|
assertEquals(4, hits);
|
2020-09-03 09:52:00 +02:00
|
|
|
}
|
|
|
|
}
|