Add exception wrapper with transparent delivery to the caller
This commit is contained in:
@ -0,0 +1,33 @@
|
||||
package dev.kske.eventbus.core;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests the behavior of the event bus when an {@link ExceptionWrapper} is thrown.
|
||||
*
|
||||
* @author Kai S. K. Engelbart
|
||||
* @since 1.2.1
|
||||
*/
|
||||
public class ExceptionWrapperTest {
|
||||
|
||||
EventBus bus = new EventBus();
|
||||
String event = "This event will cause an exception";
|
||||
|
||||
/**
|
||||
* Tests transparent rethrowing of an exception wrapper by {@link EventBus#dispatch(Object)}.
|
||||
*
|
||||
* @since 1.2.1
|
||||
*/
|
||||
@Test
|
||||
public void testExceptionWrapper() {
|
||||
bus.registerListener(this);
|
||||
assertThrows(ExceptionWrapper.class, () -> bus.dispatch(event));
|
||||
}
|
||||
|
||||
@Event(String.class)
|
||||
void onString() {
|
||||
throw new ExceptionWrapper(new RuntimeException("I failed!"));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user