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