1package org.junit.runners.parameterized; 2 3import static java.util.Collections.unmodifiableList; 4 5import java.util.ArrayList; 6import java.util.List; 7 8import org.junit.runners.model.TestClass; 9 10/** 11 * A {@code TestWithParameters} keeps the data together that are needed for 12 * creating a runner for a single data set of a parameterized test. It has a 13 * name, the test class and a list of parameters. 14 * 15 * @since 4.12 16 */ 17public class TestWithParameters { 18 private final String name; 19 20 private final TestClass testClass; 21 22 private final List<Object> parameters; 23 24 public TestWithParameters(String name, TestClass testClass, 25 List<Object> parameters) { 26 notNull(name, "The name is missing."); 27 notNull(testClass, "The test class is missing."); 28 notNull(parameters, "The parameters are missing."); 29 this.name = name; 30 this.testClass = testClass; 31 this.parameters = unmodifiableList(new ArrayList<Object>(parameters)); 32 } 33 34 public String getName() { 35 return name; 36 } 37 38 public TestClass getTestClass() { 39 return testClass; 40 } 41 42 public List<Object> getParameters() { 43 return parameters; 44 } 45 46 @Override 47 public int hashCode() { 48 int prime = 14747; 49 int result = prime + name.hashCode(); 50 result = prime * result + testClass.hashCode(); 51 return prime * result + parameters.hashCode(); 52 } 53 54 @Override 55 public boolean equals(Object obj) { 56 if (this == obj) { 57 return true; 58 } 59 if (obj == null) { 60 return false; 61 } 62 if (getClass() != obj.getClass()) { 63 return false; 64 } 65 TestWithParameters other = (TestWithParameters) obj; 66 return name.equals(other.name) 67 && parameters.equals(other.parameters) 68 && testClass.equals(other.testClass); 69 } 70 71 @Override 72 public String toString() { 73 return testClass.getName() + " '" + name + "' with parameters " 74 + parameters; 75 } 76 77 private static void notNull(Object value, String message) { 78 if (value == null) { 79 throw new NullPointerException(message); 80 } 81 } 82} 83