This commit is contained in:
parent
5468bddb35
commit
ee9d08b2b8
@ -457,6 +457,7 @@ public final class EventBus {
|
|||||||
public void clearListeners() {
|
public void clearListeners() {
|
||||||
logger.log(Level.INFO, "Clearing event listeners");
|
logger.log(Level.INFO, "Clearing event listeners");
|
||||||
bindings.clear();
|
bindings.clear();
|
||||||
|
bindingCache.clear();
|
||||||
registeredListeners.clear();
|
registeredListeners.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,8 +14,7 @@ import org.junit.jupiter.api.*;
|
|||||||
@Priority(150)
|
@Priority(150)
|
||||||
class DispatchTest {
|
class DispatchTest {
|
||||||
|
|
||||||
EventBus bus;
|
EventBus bus;
|
||||||
static int hits;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an event bus and registers this test instance as an event listener.
|
* Constructs an event bus and registers this test instance as an event listener.
|
||||||
@ -27,8 +26,8 @@ class DispatchTest {
|
|||||||
bus = new EventBus();
|
bus = new EventBus();
|
||||||
bus.registerListener(this);
|
bus.registerListener(this);
|
||||||
bus.registerListener(SimpleEvent.class, e -> {
|
bus.registerListener(SimpleEvent.class, e -> {
|
||||||
++hits;
|
e.increment();
|
||||||
assertEquals(4, hits);
|
assertEquals(3, e.getCounter());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,24 +55,37 @@ class DispatchTest {
|
|||||||
assertEquals(
|
assertEquals(
|
||||||
"Event handler execution order for class dev.kske.eventbus.core.SimpleEvent (3 handler(s)):\n"
|
"Event handler execution order for class dev.kske.eventbus.core.SimpleEvent (3 handler(s)):\n"
|
||||||
+ "==========================================================================================\n"
|
+ "==========================================================================================\n"
|
||||||
+ "ReflectiveEventHandler[eventType=class dev.kske.eventbus.core.SimpleEvent, polymorphic=true, priority=200, method=void dev.kske.eventbus.core.DispatchTest.onSimpleEventFirst(), useParameter=false]\n"
|
+ "ReflectiveEventHandler[eventType=class dev.kske.eventbus.core.SimpleEvent, polymorphic=true, priority=200, method=void dev.kske.eventbus.core.DispatchTest.onSimpleEventFirst(dev.kske.eventbus.core.SimpleEvent), useParameter=true]\n"
|
||||||
+ "ReflectiveEventHandler[eventType=class dev.kske.eventbus.core.SimpleEvent, polymorphic=false, priority=150, method=static void dev.kske.eventbus.core.DispatchTest.onSimpleEventSecond(), useParameter=false]\n"
|
+ "ReflectiveEventHandler[eventType=class dev.kske.eventbus.core.SimpleEvent, polymorphic=false, priority=150, method=static void dev.kske.eventbus.core.DispatchTest.onSimpleEventSecond(dev.kske.eventbus.core.SimpleEvent), useParameter=true]\n"
|
||||||
+ "CallbackEventHandler[eventType=class dev.kske.eventbus.core.SimpleEvent, polymorphic=false, priority=100]\n"
|
+ "CallbackEventHandler[eventType=class dev.kske.eventbus.core.SimpleEvent, polymorphic=false, priority=100]\n"
|
||||||
+ "==========================================================================================",
|
+ "==========================================================================================",
|
||||||
executionOrder);
|
executionOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Event(SimpleEvent.class)
|
/**
|
||||||
@Priority(200)
|
* Tests whether the handlers bound to an event type are correct when retrieved from the binding
|
||||||
void onSimpleEventFirst() {
|
* cache. On the second call of {@link EventBus#debugExecutionOrder(Class)} the cache is used.
|
||||||
++hits;
|
*
|
||||||
assertTrue(hits == 1 || hits == 2);
|
* @since 1.3.0
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void testBindingCache() {
|
||||||
|
String executionOrder = bus.debugExecutionOrder(SimpleEventSub.class);
|
||||||
|
System.out.println(executionOrder);
|
||||||
|
assertEquals(executionOrder, bus.debugExecutionOrder(SimpleEventSub.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Event(SimpleEvent.class)
|
@Event
|
||||||
|
@Priority(200)
|
||||||
|
void onSimpleEventFirst(SimpleEvent event) {
|
||||||
|
event.increment();
|
||||||
|
assertTrue(event.getCounter() == 1 || event.getCounter() == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Event
|
||||||
@Polymorphic(false)
|
@Polymorphic(false)
|
||||||
static void onSimpleEventSecond() {
|
static void onSimpleEventSecond(SimpleEvent event) {
|
||||||
++hits;
|
event.increment();
|
||||||
assertEquals(3, hits);
|
assertEquals(2, event.getCounter());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ class SimpleEvent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("SimpleEvent[%d]", counter);
|
return String.format("%s[%d]", getClass().getSimpleName(), counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void increment() {
|
void increment() {
|
||||||
|
Loading…
Reference in New Issue
Block a user