aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/junitparams/internal/DeferredErrorFrameworkMethod.java
blob: b6e843e6b9bf2b50162eca9249fc0e569e961fd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package junitparams.internal;

import java.lang.reflect.Method;

import org.junit.runner.Description;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.model.Statement;

/**
 * Encapsulates a {@link Throwable} that was caught during initialization so that it can be
 * thrown during execution in order to preserve previous behavior.
 */
public class DeferredErrorFrameworkMethod extends InvokableFrameworkMethod {

    private final Throwable throwable;

    DeferredErrorFrameworkMethod(Method method, Description description,
            Throwable throwable) {
        super(method, description);
        this.throwable = throwable;
    }

    @Override
    public Statement getInvokeStatement(Object test) {
        return new Statement() {
            @Override
            public void evaluate() throws Throwable {
                throw throwable;
            }
        };
    }

    @Override
    public void run(MethodBlockSupplier supplier, RunNotifier notifier) {
        // Do not call the MethodBlockSupplier as that could introduce additional errors, simply
        // throw the encapsulated Throwable immediately.
        runMethodInvoker(notifier, getInvokeStatement(notifier), getDescription());
    }
}