From 3245db767d99f62af51a86e4c509b16820030611 Mon Sep 17 00:00:00 2001 From: Abhishek <6554853+sh-abhi@users.noreply.github.com> Date: Mon, 8 Jun 2020 08:21:22 +0000 Subject: [PATCH] Updating SuppressUndeliverableRule to have a named inner class instead of an anonymous inner class. (#7006) --- .../SuppressUndeliverableRule.java | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/test/java/io/reactivex/rxjava3/testsupport/SuppressUndeliverableRule.java b/src/test/java/io/reactivex/rxjava3/testsupport/SuppressUndeliverableRule.java index 392fbdba33..ea013daac5 100644 --- a/src/test/java/io/reactivex/rxjava3/testsupport/SuppressUndeliverableRule.java +++ b/src/test/java/io/reactivex/rxjava3/testsupport/SuppressUndeliverableRule.java @@ -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; }