Add Test for Cancellation
This commit is contained in:
parent
9d1707de5b
commit
8aefb43823
@ -13,6 +13,7 @@ import org.junit.jupiter.api.*;
|
||||
class EventBusTest implements EventListener {
|
||||
|
||||
int hits;
|
||||
static int canceledHits;
|
||||
|
||||
@BeforeEach
|
||||
public void registerListener() {
|
||||
@ -25,11 +26,15 @@ class EventBusTest implements EventListener {
|
||||
EventBus.getInstance().dispatch(new SimpleEvent());
|
||||
}
|
||||
|
||||
@Event(
|
||||
eventType = SimpleEvent.class,
|
||||
includeSubtypes = true,
|
||||
priority = 200
|
||||
)
|
||||
@Test
|
||||
void testCancellation() {
|
||||
var test2 = new EventBusTest();
|
||||
test2.registerListener();
|
||||
EventBus.getInstance().dispatch(new SimpleCancelEvent());
|
||||
assertTrue(canceledHits == 1);
|
||||
}
|
||||
|
||||
@Event(eventType = SimpleEvent.class, includeSubtypes = true, priority = 200)
|
||||
private void onSimpleEventFirst() {
|
||||
++hits;
|
||||
assertTrue(hits == 1 || hits == 2);
|
||||
@ -46,4 +51,16 @@ class EventBusTest implements EventListener {
|
||||
++hits;
|
||||
assertEquals(4, hits);
|
||||
}
|
||||
|
||||
@Event(eventType = SimpleCancelEvent.class, priority = 500)
|
||||
private void onSimpleCancelFirst() {
|
||||
++canceledHits;
|
||||
assertTrue(canceledHits == 1);
|
||||
EventBus.getInstance().cancel();
|
||||
}
|
||||
|
||||
@Event(eventType = SimpleCancelEvent.class, priority = 200)
|
||||
private void onSimpleCancelSecond() {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
9
src/test/java/dev/kske/eventbus/SimpleCancelEvent.java
Normal file
9
src/test/java/dev/kske/eventbus/SimpleCancelEvent.java
Normal file
@ -0,0 +1,9 @@
|
||||
package dev.kske.eventbus;
|
||||
|
||||
/**
|
||||
* A simple event for testing purposes that will get cancelled during propagation.
|
||||
*
|
||||
* @author Leon Hofmeister
|
||||
* @since 0.1
|
||||
*/
|
||||
public class SimpleCancelEvent implements IEvent {}
|
Loading…
Reference in New Issue
Block a user