diff options
Diffstat (limited to 'src/main/java/junitparams/internal/DeferredErrorFrameworkMethod.java')
-rw-r--r-- | src/main/java/junitparams/internal/DeferredErrorFrameworkMethod.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/main/java/junitparams/internal/DeferredErrorFrameworkMethod.java b/src/main/java/junitparams/internal/DeferredErrorFrameworkMethod.java new file mode 100644 index 0000000..b6e843e --- /dev/null +++ b/src/main/java/junitparams/internal/DeferredErrorFrameworkMethod.java @@ -0,0 +1,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()); + } +} |