diff options
Diffstat (limited to 'src/main/java/junitparams/internal/InvokableFrameworkMethod.java')
-rw-r--r-- | src/main/java/junitparams/internal/InvokableFrameworkMethod.java | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/main/java/junitparams/internal/InvokableFrameworkMethod.java b/src/main/java/junitparams/internal/InvokableFrameworkMethod.java new file mode 100644 index 0000000..0ed0bdb --- /dev/null +++ b/src/main/java/junitparams/internal/InvokableFrameworkMethod.java @@ -0,0 +1,59 @@ +package junitparams.internal; + +import java.lang.reflect.Method; +import junitparams.JUnitParamsRunner; +import org.junit.internal.AssumptionViolatedException; +import org.junit.internal.runners.model.EachTestNotifier; +import org.junit.runner.Description; +import org.junit.runner.notification.RunNotifier; +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.Statement; + +/** + * Base for {@link FrameworkMethod} classes that provide a {@link Statement} for invoking. + */ +public abstract class InvokableFrameworkMethod extends DescribableFrameworkMethod { + + private final Description description; + + InvokableFrameworkMethod(Method method, Description description) { + super(method); + this.description = description; + } + + @Override + public Description getDescription() { + return description; + } + + /** + * Create a {@link Statement} that when called will invoke the method. + * + * <p>This is usually called from the + * {@link JUnitParamsRunner#methodInvoker(FrameworkMethod, Object)} method via the + * {@link MethodBlockSupplier} which is usually called from within the + * {@link #run(MethodBlockSupplier, RunNotifier)} method. + * + * @param test + * the object on which the method will be invoked. + * @return the {@link Statement}. + */ + public abstract Statement getInvokeStatement(Object test); + + void runMethodInvoker(RunNotifier notifier, Statement methodInvoker, + Description methodWithParams) { + EachTestNotifier eachNotifier = new EachTestNotifier(notifier, methodWithParams); + eachNotifier.fireTestStarted(); + try { + methodInvoker.evaluate(); + } catch (AssumptionViolatedException e) { + eachNotifier.addFailedAssumption(e); + } catch (Throwable e) { + eachNotifier.addFailure(e); + } finally { + eachNotifier.fireTestFinished(); + } + } + + public abstract void run(MethodBlockSupplier supplier, RunNotifier notifier); +} |