001package org.junit.runners.parameterized;
002
003import static java.util.Collections.unmodifiableList;
004import static org.junit.internal.Checks.notNull;
005
006import java.util.ArrayList;
007import java.util.List;
008
009import org.junit.runners.model.TestClass;
010
011/**
012 * A {@code TestWithParameters} keeps the data together that are needed for
013 * creating a runner for a single data set of a parameterized test. It has a
014 * name, the test class and a list of parameters.
015 * 
016 * @since 4.12
017 */
018public class TestWithParameters {
019    private final String name;
020
021    private final TestClass testClass;
022
023    private final List<Object> parameters;
024
025    public TestWithParameters(String name, TestClass testClass,
026            List<Object> parameters) {
027        notNull(name, "The name is missing.");
028        notNull(testClass, "The test class is missing.");
029        notNull(parameters, "The parameters are missing.");
030        this.name = name;
031        this.testClass = testClass;
032        this.parameters = unmodifiableList(new ArrayList<Object>(parameters));
033    }
034
035    public String getName() {
036        return name;
037    }
038
039    public TestClass getTestClass() {
040        return testClass;
041    }
042
043    public List<Object> getParameters() {
044        return parameters;
045    }
046
047    @Override
048    public int hashCode() {
049        int prime = 14747;
050        int result = prime + name.hashCode();
051        result = prime * result + testClass.hashCode();
052        return prime * result + parameters.hashCode();
053    }
054
055    @Override
056    public boolean equals(Object obj) {
057        if (this == obj) {
058            return true;
059        }
060        if (obj == null) {
061            return false;
062        }
063        if (getClass() != obj.getClass()) {
064            return false;
065        }
066        TestWithParameters other = (TestWithParameters) obj;
067        return name.equals(other.name)
068                && parameters.equals(other.parameters)
069                && testClass.equals(other.testClass);
070    }
071
072    @Override
073    public String toString() {
074        return testClass.getName() + " '" + name + "' with parameters "
075                + parameters;
076    }
077}