Home | History | Annotate | Download | only in internal
      1 package junitparams.internal;
      2 
      3 import java.lang.reflect.Method;
      4 
      5 import org.junit.rules.TestRule;
      6 import org.junit.runner.Description;
      7 import org.junit.runner.Runner;
      8 import org.junit.runner.notification.RunListener;
      9 import org.junit.runner.notification.RunNotifier;
     10 import org.junit.runners.model.FrameworkMethod;
     11 import org.junit.runners.model.Statement;
     12 
     13 /**
     14  * A {@link FrameworkMethod} that represents an instance of an
     15  * {@link ParameterisedFrameworkMethod}, that is the combination of the test method with the
     16  * parameter set that it will be passed.
     17  */
     18 public class InstanceFrameworkMethod extends InvokableFrameworkMethod {
     19 
     20     private final Description instanceDescription;
     21 
     22     private final Object parametersSet;
     23 
     24     /**
     25      * Create an {@link InstanceFrameworkMethod}.
     26      *
     27      * <p>It has two {@link Description} instances because it has to provide different
     28      * {@link Description} to {@link TestRule} instances than other usages in order to maintain
     29      * backwards compatibility.
     30      *
     31      * @param method the test method
     32      * @param description the description that is supplied to {@link TestRule} instances.
     33      * @param instanceDescription the description used for all other purposes, e.g. filtering,
     34      *         {@link Runner#getDescription()} and {@link RunListener}.
     35      * @param parametersSet the set of parameters to pass to the method.
     36      */
     37     InstanceFrameworkMethod(Method method, Description description,
     38             Description instanceDescription, Object parametersSet) {
     39         super(method, description);
     40         this.instanceDescription = instanceDescription;
     41         this.parametersSet = parametersSet;
     42     }
     43 
     44     @Override
     45     public Statement getInvokeStatement(Object test) {
     46         return new InvokeParameterisedMethod(this, test, parametersSet);
     47     }
     48 
     49     Description getInstanceDescription() {
     50         return instanceDescription;
     51     }
     52 
     53     @Override
     54     public void run(MethodBlockSupplier supplier, RunNotifier notifier) {
     55         runMethodInvoker(notifier, supplier.getMethodBlock(this), getInstanceDescription());
     56     }
     57 }
     58