Add parent project, convert existing project to Maven module
This commit is contained in:
@ -0,0 +1,52 @@
|
||||
package dev.kske.eventbus;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
/**
|
||||
* Tests the event cancellation mechanism of the event bus.
|
||||
*
|
||||
* @author Kai S. K. Engelbart
|
||||
* @author Leon Hofmeister
|
||||
* @since 0.1.0
|
||||
*/
|
||||
class CancelTest implements EventListener {
|
||||
|
||||
EventBus bus;
|
||||
int hits;
|
||||
|
||||
/**
|
||||
* Constructs an event bus and registers this test instance as an event listener.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@BeforeEach
|
||||
void registerListener() {
|
||||
bus = new EventBus();
|
||||
bus.registerListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link EventBus#cancel()} with two event handlers, of which the first cancels the
|
||||
* event.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@Test
|
||||
void testCancellation() {
|
||||
bus.dispatch(new SimpleEvent());
|
||||
assertEquals(1, hits);
|
||||
}
|
||||
|
||||
@Event(eventType = SimpleEvent.class, priority = 100)
|
||||
void onSimpleFirst() {
|
||||
++hits;
|
||||
bus.cancel();
|
||||
}
|
||||
|
||||
@Event(eventType = SimpleEvent.class, priority = 50)
|
||||
void onSimpleSecond() {
|
||||
++hits;
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package dev.kske.eventbus;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -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 {}
|
@ -0,0 +1,9 @@
|
||||
package dev.kske.eventbus;
|
||||
|
||||
/**
|
||||
* Subclass of {@link SimpleEvent} for testing purposes.
|
||||
*
|
||||
* @author Kai S. K. Engelbart
|
||||
* @since 0.0.4
|
||||
*/
|
||||
public class SimpleEventSub extends SimpleEvent {}
|
Reference in New Issue
Block a user