aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/junitparams/internal/InstanceFrameworkMethod.java
blob: ad704544d7e3b25fe1d571c4506092fc2a3ef7a2 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package junitparams.internal;

import java.lang.reflect.Method;

import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runner.Runner;
import org.junit.runner.notification.RunListener;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;

/**
 * A {@link FrameworkMethod} that represents an instance of an 
 * {@link ParameterisedFrameworkMethod}, that is the combination of the test method with the
 * parameter set that it will be passed.
 */
public class InstanceFrameworkMethod extends InvokableFrameworkMethod {

    private final Description instanceDescription;

    private final Object parametersSet;

    /**
     * Create an {@link InstanceFrameworkMethod}.
     *
     * <p>It has two {@link Description} instances because it has to provide different
     * {@link Description} to {@link TestRule} instances than other usages in order to maintain
     * backwards compatibility.
     *
     * @param method the test method
     * @param description the description that is supplied to {@link TestRule} instances.
     * @param instanceDescription the description used for all other purposes, e.g. filtering,
     *         {@link Runner#getDescription()} and {@link RunListener}.
     * @param parametersSet the set of parameters to pass to the method.
     */
    InstanceFrameworkMethod(Method method, Description description,
            Description instanceDescription, Object parametersSet) {
        super(method, description);
        this.instanceDescription = instanceDescription;
        this.parametersSet = parametersSet;
    }

    @Override
    public Statement getInvokeStatement(Object test) {
        return new InvokeParameterisedMethod(this, test, parametersSet);
    }

    Description getInstanceDescription() {
        return instanceDescription;
    }

    @Override
    public void run(MethodBlockSupplier supplier, RunNotifier notifier) {
        runMethodInvoker(notifier, supplier.getMethodBlock(this), getInstanceDescription());
    }
}