Test priorities for inheritance
All checks were successful
zdm/event-bus/pipeline/head This commit looks good
All checks were successful
zdm/event-bus/pipeline/head This commit looks good
This commit is contained in:
@ -5,7 +5,8 @@ import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests whether event handlers correctly work in the context of an inheritance hierarchy.
|
||||
* Tests whether event handlers correctly work in the context of an inheritance hierarchy. The
|
||||
* effect of handler priorities is also accounted for.
|
||||
*
|
||||
* @author Kai S. K. Engelbart
|
||||
* @since 1.3.0
|
||||
@ -20,12 +21,12 @@ class InheritanceTest extends SimpleEventListenerBase implements SimpleEventList
|
||||
var event = new SimpleEvent();
|
||||
|
||||
bus.dispatch(event);
|
||||
assertSame(4, event.getCounter());
|
||||
assertSame(3, event.getCounter());
|
||||
}
|
||||
|
||||
@Override
|
||||
void onSimpleEventAbstractHandler(SimpleEvent event) {
|
||||
event.increment();
|
||||
assertSame(1, event.getCounter());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -35,6 +36,7 @@ class InheritanceTest extends SimpleEventListenerBase implements SimpleEventList
|
||||
|
||||
@Event
|
||||
private void onSimpleEventPrivate(SimpleEvent event) {
|
||||
assertSame(0, event.getCounter());
|
||||
event.increment();
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,25 @@
|
||||
package dev.kske.eventbus.core;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* An abstract class defining a package-private and a private handler for {@link SimpleEvent}.
|
||||
*
|
||||
* @author Kai S. K. Engelbart
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@Priority(200)
|
||||
abstract class SimpleEventListenerBase {
|
||||
|
||||
@Event
|
||||
void onSimpleEventAbstractHandler(SimpleEvent event) {
|
||||
event.increment();
|
||||
fail("This handler should not be invoked");
|
||||
}
|
||||
|
||||
@Priority(150)
|
||||
@Event
|
||||
private void onSimpleEventPrivate(SimpleEvent event) {
|
||||
assertSame(1, event.getCounter());
|
||||
event.increment();
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ package dev.kske.eventbus.core;
|
||||
*/
|
||||
interface SimpleEventListenerInterface {
|
||||
|
||||
@Priority(120)
|
||||
@Event
|
||||
void onSimpleEventInterfaceHandler(SimpleEvent event);
|
||||
}
|
||||
|
Reference in New Issue
Block a user