1 package org.junit.tests.experimental.theories.runner; 2 3 import static org.hamcrest.CoreMatchers.containsString; 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertThat; 6 import static org.junit.tests.experimental.theories.TheoryTestUtils.potentialAssignments; 7 8 import java.util.List; 9 10 import org.junit.Test; 11 import org.junit.experimental.theories.DataPoint; 12 import org.junit.experimental.theories.DataPoints; 13 import org.junit.experimental.theories.FromDataPoints; 14 import org.junit.experimental.theories.PotentialAssignment; 15 import org.junit.experimental.theories.Theories; 16 import org.junit.experimental.theories.Theory; 17 import org.junit.runner.RunWith; 18 19 public class WithNamedDataPoints { 20 21 @RunWith(Theories.class) 22 public static class HasSpecificDatapointsParameters { 23 24 @DataPoints 25 public static String[] badStrings = new String[] { "bad" }; 26 27 @DataPoint 28 public static String badString = "also bad"; 29 30 @DataPoints("named") 31 public static String[] goodStrings = new String[] { "expected", "also expected" }; 32 33 @DataPoint("named") 34 public static String goodString = "expected single value"; 35 36 @DataPoints("named") 37 public static String[] methodStrings() { 38 return new String[] { "expected method value" }; 39 } 40 41 @DataPoint("named") 42 public static String methodString() { 43 return "expected single method string"; 44 } 45 46 @DataPoints 47 public static String[] otherMethod() { 48 return new String[] { "other method value" }; 49 } 50 51 @DataPoint 52 public static String otherSingleValueMethod() { 53 return "other single value string"; 54 } 55 56 @Theory 57 public void theory(@FromDataPoints("named") String param) { 58 } 59 60 } 61 62 @Test 63 public void onlyUseSpecificDataPointsIfSpecified() throws Throwable { 64 List<PotentialAssignment> assignments = potentialAssignments(HasSpecificDatapointsParameters.class 65 .getMethod("theory", String.class)); 66 67 assertEquals(5, assignments.size()); 68 for (PotentialAssignment assignment : assignments) { 69 assertThat((String) assignment.getValue(), containsString("expected")); 70 } 71 } 72 73 }