Created
March 1, 2018 13:57
-
-
Save gautier-levert/11cafd088c28d943d0ebb16e60f5f50b to your computer and use it in GitHub Desktop.
Guava EventBus implementation for unit tests, found on https://stackoverflow.com/questions/37130746/bring-up-exceptions-in-google-guava-eventbus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.google.common.eventbus; | |
import com.google.common.base.Throwables; | |
import java.lang.reflect.InvocationTargetException; | |
public class TestEventBus extends EventBus { | |
//If version 18 or bellow | |
@Override | |
void dispatch(Object event, EventSubscriber wrapper) { | |
try { | |
wrapper.handleEvent(event); | |
} catch (InvocationTargetException cause) { | |
Throwables.propagate(Throwables.getRootCause(cause)); | |
} | |
} | |
//If version 19 | |
@Override | |
public void handleSubscriberException(Throwable e, SubscriberExceptionContext context) { | |
Throwables.propagate(Throwables.getRootCause(e)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment