|
| 1 | +package org.junit.experimental.theories; |
| 2 | + |
| 3 | +import java.lang.annotation.ElementType; |
| 4 | +import java.lang.annotation.Retention; |
| 5 | +import java.lang.annotation.RetentionPolicy; |
| 6 | +import java.lang.annotation.Target; |
| 7 | + |
| 8 | +import org.junit.experimental.theories.internal.SpecificDataPointsSupplier; |
| 9 | + |
| 10 | +/** |
| 11 | + * <p> |
| 12 | + * Annotating a parameter of a {@link org.junit.experimental.theories.Theory |
| 13 | + * @Theory} method with <code>@FromDataPoints</code> will limit the |
| 14 | + * datapoints considered as potential values for that parameter to just the |
| 15 | + * {@link org.junit.experimental.theories.DataPoints DataPoints} with the given |
| 16 | + * name. DataPoint names can be given as the value parameter of the |
| 17 | + * @DataPoints annotation. |
| 18 | + * </p> |
| 19 | + * <p> |
| 20 | + * DataPoints without names will not be considered as values for any parameters |
| 21 | + * annotated with @FromDataPoints. |
| 22 | + * </p> |
| 23 | + * |
| 24 | + * <pre> |
| 25 | + * @DataPoints |
| 26 | + * public static String[] unnamed = new String[] { ... }; |
| 27 | + * |
| 28 | + * @DataPoints("regexes") |
| 29 | + * public static String[] regexStrings = new String[] { ... }; |
| 30 | + * |
| 31 | + * @DataPoints({"forMatching", "alphanumeric"}) |
| 32 | + * public static String[] testStrings = new String[] { ... }; |
| 33 | + * |
| 34 | + * @Theory |
| 35 | + * public void stringTheory(String param) { |
| 36 | + * // This will be called with every value in 'regexStrings', |
| 37 | + * // 'testStrings' and 'unnamed'. |
| 38 | + * } |
| 39 | + * |
| 40 | + * @Theory |
| 41 | + * public void regexTheory(@FromDataPoints("regexes") String regex, |
| 42 | + * @FromDataPoints("forMatching") String value) { |
| 43 | + * // This will be called with only the values in 'regexStrings' as |
| 44 | + * // regex, only the values in 'testStrings' as value, and none |
| 45 | + * // of the values in 'unnamed'. |
| 46 | + * } |
| 47 | + * </pre> |
| 48 | + * |
| 49 | + * @see org.junit.experimental.theories.Theory |
| 50 | + * @see org.junit.experimental.theories.DataPoint |
| 51 | + * @see org.junit.experimental.theories.DataPoints |
| 52 | + */ |
| 53 | +@Retention(RetentionPolicy.RUNTIME) |
| 54 | +@Target(ElementType.PARAMETER) |
| 55 | +@ParametersSuppliedBy(SpecificDataPointsSupplier.class) |
| 56 | +public @interface FromDataPoints { |
| 57 | + String value(); |
| 58 | +} |
0 commit comments