diff options
author | Paul Duffin <paulduffin@google.com> | 2017-05-26 21:08:25 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-05-26 21:08:25 +0000 |
commit | f58521195eaa905758f0b8889f1d030c7d66d6e1 (patch) | |
tree | b4227f625f29e2426693f940545b2883b51fbe5d /src/main/java/junitparams/internal/InvokableFrameworkMethod.java | |
parent | 5a47920cc4e1fe32e9d4ebc6bfdd76c788808c47 (diff) | |
parent | 2f41cd20c0d23275511c6622c6aa61ff0c477f68 (diff) | |
download | platform_external_junit-params-f58521195eaa905758f0b8889f1d030c7d66d6e1.tar.gz platform_external_junit-params-f58521195eaa905758f0b8889f1d030c7d66d6e1.tar.bz2 platform_external_junit-params-f58521195eaa905758f0b8889f1d030c7d66d6e1.zip |
Fix JUnitParamsRunner so it works with CTS sharding am: b03560c325
am: 2f41cd20c0
Change-Id: Idcf24600dea537fa1cfe3eb925d3ff82a586453f
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); +} |