Skip to content

Commit

Permalink
Updating SuppressUndeliverableRule to have a named inner class instea…
Browse files Browse the repository at this point in the history
…d of an anonymous inner class. (ReactiveX#7006)
  • Loading branch information
sh-abhi authored Jun 8, 2020
1 parent 043dbaa commit 3245db7
Showing 1 changed file with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,35 @@
*/
public class SuppressUndeliverableRule implements TestRule {

private static class SuppressUndeliverableRuleStatement extends Statement {
private Statement base;

private SuppressUndeliverableRuleStatement(){}
public SuppressUndeliverableRuleStatement(Statement base) {
this.base = base;
}

@Override
public void evaluate() throws Throwable {
try {
RxJavaPlugins.setErrorHandler(throwable -> {
if (!(throwable instanceof UndeliverableException)) {
throwable.printStackTrace();
Thread currentThread = Thread.currentThread();
currentThread.getUncaughtExceptionHandler().uncaughtException(currentThread, throwable);
}
});
base.evaluate();
} finally {
RxJavaPlugins.setErrorHandler(null);
}
}
}

@Override
public Statement apply(Statement base, Description description) {
if (description.getAnnotation(SuppressUndeliverable.class) != null) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
RxJavaPlugins.setErrorHandler(throwable -> {
if (!(throwable instanceof UndeliverableException)) {
throwable.printStackTrace();
Thread currentThread = Thread.currentThread();
currentThread.getUncaughtExceptionHandler().uncaughtException(currentThread, throwable);
}
});
base.evaluate();
} finally {
RxJavaPlugins.setErrorHandler(null);
}
}
};
if (description != null && description.getAnnotation(SuppressUndeliverable.class) != null) {
return new SuppressUndeliverableRuleStatement(base);
} else {
return base;
}
Expand Down

0 comments on commit 3245db7

Please sign in to comment.