Skip to content

Commit 3245db7

Browse files
authored
Updating SuppressUndeliverableRule to have a named inner class instead of an anonymous inner class. (ReactiveX#7006)
1 parent 043dbaa commit 3245db7

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

src/test/java/io/reactivex/rxjava3/testsupport/SuppressUndeliverableRule.java

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,35 @@
3030
*/
3131
public class SuppressUndeliverableRule implements TestRule {
3232

33+
private static class SuppressUndeliverableRuleStatement extends Statement {
34+
private Statement base;
35+
36+
private SuppressUndeliverableRuleStatement(){}
37+
public SuppressUndeliverableRuleStatement(Statement base) {
38+
this.base = base;
39+
}
40+
41+
@Override
42+
public void evaluate() throws Throwable {
43+
try {
44+
RxJavaPlugins.setErrorHandler(throwable -> {
45+
if (!(throwable instanceof UndeliverableException)) {
46+
throwable.printStackTrace();
47+
Thread currentThread = Thread.currentThread();
48+
currentThread.getUncaughtExceptionHandler().uncaughtException(currentThread, throwable);
49+
}
50+
});
51+
base.evaluate();
52+
} finally {
53+
RxJavaPlugins.setErrorHandler(null);
54+
}
55+
}
56+
}
57+
3358
@Override
3459
public Statement apply(Statement base, Description description) {
35-
if (description.getAnnotation(SuppressUndeliverable.class) != null) {
36-
return new Statement() {
37-
@Override
38-
public void evaluate() throws Throwable {
39-
try {
40-
RxJavaPlugins.setErrorHandler(throwable -> {
41-
if (!(throwable instanceof UndeliverableException)) {
42-
throwable.printStackTrace();
43-
Thread currentThread = Thread.currentThread();
44-
currentThread.getUncaughtExceptionHandler().uncaughtException(currentThread, throwable);
45-
}
46-
});
47-
base.evaluate();
48-
} finally {
49-
RxJavaPlugins.setErrorHandler(null);
50-
}
51-
}
52-
};
60+
if (description != null && description.getAnnotation(SuppressUndeliverable.class) != null) {
61+
return new SuppressUndeliverableRuleStatement(base);
5362
} else {
5463
return base;
5564
}

0 commit comments

Comments
 (0)