Add simple unit test and fix event handler ordering
This commit is contained in:
39
src/test/java/dev/kske/eventbus/EventBusTest.java
Normal file
39
src/test/java/dev/kske/eventbus/EventBusTest.java
Normal file
@ -0,0 +1,39 @@
|
||||
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 {
|
||||
|
||||
public EventBus eventBus = new EventBus();
|
||||
int hits;
|
||||
|
||||
@BeforeEach
|
||||
public void registerListener() {
|
||||
eventBus.registerListener(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDispatch() {
|
||||
eventBus.dispatch(new SimpleEvent());
|
||||
}
|
||||
|
||||
@Event(priority = 50)
|
||||
public void onSimpleEventSecond(SimpleEvent event) {
|
||||
++hits;
|
||||
assertEquals(2, hits);
|
||||
}
|
||||
|
||||
@Event(priority = 150)
|
||||
public void onSimpleEventFirst(SimpleEvent event) {
|
||||
++hits;
|
||||
assertEquals(1, hits);
|
||||
}
|
||||
}
|
9
src/test/java/dev/kske/eventbus/SimpleEvent.java
Normal file
9
src/test/java/dev/kske/eventbus/SimpleEvent.java
Normal file
@ -0,0 +1,9 @@
|
||||
package dev.kske.eventbus;
|
||||
|
||||
/**
|
||||
* A simple event for testing purposes.
|
||||
*
|
||||
* @author Kai S. K. Engelbart
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public class SimpleEvent implements IEvent {}
|
Reference in New Issue
Block a user