1 package org.junit.tests.experimental.theories.runner; 2 3 import static org.junit.Assert.assertEquals; 4 import static org.junit.tests.experimental.theories.TheoryTestUtils.potentialAssignments; 5 import org.junit.Test; 6 import org.junit.experimental.theories.DataPoint; 7 import org.junit.experimental.theories.Theories; 8 import org.junit.runner.RunWith; 9 10 public class WithAutoGeneratedDataPoints { 11 12 private enum ENUM { VALUE, OTHER_VALUE, THIRD_VALUE }; 13 14 @RunWith(Theories.class) 15 public static class TheoryTestClassWithAutogeneratedParameterValues { 16 17 public void theory(ENUM e) { 18 } 19 20 public void theory(boolean b) { 21 } 22 23 } 24 25 @Test 26 public void shouldAutomaticallyGenerateEnumDataPoints() throws Throwable { 27 assertEquals(ENUM.values().length, potentialAssignments( 28 TheoryTestClassWithAutogeneratedParameterValues.class.getMethod("theory", ENUM.class)).size()); 29 } 30 31 @Test 32 public void shouldAutomaticallyGenerateBooleanDataPoints() throws Throwable { 33 assertEquals(2, potentialAssignments( 34 TheoryTestClassWithAutogeneratedParameterValues.class.getMethod("theory", boolean.class)).size()); 35 } 36 37 @RunWith(Theories.class) 38 public static class TheoryTestClassWithSpecificEnumDataPoint { 39 40 @DataPoint 41 public static ENUM value = ENUM.OTHER_VALUE; 42 43 public void theory(ENUM e) { 44 } 45 46 } 47 48 @Test 49 public void shouldNotAutogenerateEnumDataPointsWhenSpecificDataPointGiven() throws Throwable { 50 assertEquals(1, potentialAssignments( 51 TheoryTestClassWithSpecificEnumDataPoint.class.getMethod("theory", ENUM.class)).size()); 52 } 53 54 @RunWith(Theories.class) 55 public static class TheoryTestClassWithSpecificBooleanDataPoint { 56 57 @DataPoint 58 public static boolean value = true; 59 60 public void theory(boolean b) { 61 } 62 63 } 64 65 @Test 66 public void shouldNotAutogenerateBooleanDataPointsWhenSpecificDataPointGiven() throws Throwable { 67 assertEquals(1, potentialAssignments( 68 TheoryTestClassWithSpecificBooleanDataPoint.class.getMethod("theory", boolean.class)).size()); 69 } 70 71 }