2020-09-03 09:52:00 +02:00
|
|
|
package dev.kske.eventbus;
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
|
|
|
int hits;
|
|
|
|
|
|
|
|
@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-08 09:38:46 +02:00
|
|
|
EventBus.getInstance().dispatch(new SimpleEvent());
|
2020-09-03 09:52:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Event(priority = 50)
|
2020-09-07 10:38:38 +02:00
|
|
|
private void onSimpleEventSecond(SimpleEvent event) {
|
2020-09-03 09:52:00 +02:00
|
|
|
++hits;
|
|
|
|
assertEquals(2, hits);
|
|
|
|
}
|
|
|
|
|
2020-09-08 19:47:21 +02:00
|
|
|
@Event(eventType = SimpleEvent.class, priority = 150)
|
|
|
|
private void onSimpleEventFirst() {
|
2020-09-03 09:52:00 +02:00
|
|
|
++hits;
|
|
|
|
assertEquals(1, hits);
|
|
|
|
}
|
|
|
|
}
|