|
31 | 31 | import org.junit.jupiter.api.extension.ExtensionContext; |
32 | 32 | import org.junit.jupiter.params.provider.Arguments; |
33 | 33 | import org.junit.jupiter.params.provider.ArgumentsProvider; |
| 34 | +import org.junit.jupiter.params.support.AnnotationConsumer; |
34 | 35 | import org.opentest4j.TestAbortedException; |
35 | 36 |
|
36 | 37 | /** |
37 | 38 | * Base for defining a compiler-supplying arguments-provider for JUnit Jupiter parameterised test |
38 | 39 | * support. |
39 | 40 | * |
| 41 | + * <p>Each implementation is expected to provide: |
| 42 | + * |
| 43 | + * <ul> |
| 44 | + * <li>A method {@link #initializeNewCompiler} that returns new instances of a |
| 45 | + * {@link JctCompiler};</li> |
| 46 | + * <li>A minimum acceptable language level for the compiler, as an integer;</li> |
| 47 | + * <li>A maximum acceptable language level for the compiler, as an integer;</li> |
| 48 | + * <li>An implementation of {@link AnnotationConsumer} that consumes the desired |
| 49 | + * annotation. The details of the annotation should be extracted and a call |
| 50 | + * to {@link #configure} should be made.</li> |
| 51 | + * </ul> |
| 52 | + * |
40 | 53 | * <p>An example annotation would look like the following: |
41 | 54 | * |
42 | 55 | * <pre><code> |
43 | 56 | * {@literal @ArgumentsSource(MyCompilersProvider.class)} |
44 | 57 | * {@literal @ParameterizedTest(name = "for {0}")} |
45 | 58 | * {@literal @Retention(RetentionPolicy.RUNTIME)} |
| 59 | + * {@literal @Tag("java-compiler-testing-test")} |
46 | 60 | * {@literal @Target}({ |
47 | 61 | * ElementType.ANNOTATION_TYPE, |
48 | 62 | * ElementType.METHOD, |
49 | | - * ElementType.TYPE, |
50 | 63 | * }) |
| 64 | + * {@literal @TestTemplate} |
51 | 65 | * public {@literal @interface} MyCompilerTest { |
52 | 66 | * int minVersion() default Integer.MIN_VALUE; |
53 | 67 | * int maxVersion() default Integer.MAX_VALUE; |
|
89 | 103 | * } |
90 | 104 | * } |
91 | 105 | * </code></pre> |
92 | | - * <p> |
93 | | - * This would enable you to define your test cases like so: |
| 106 | + * |
| 107 | + * <p>This would enable you to define your test cases like so: |
94 | 108 | * |
95 | 109 | * <pre><code> |
96 | 110 | * {@literal @MyCompilerTest(minVersion=13, maxVersion=17)} |
@@ -151,6 +165,20 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext context) { |
151 | 165 | /** |
152 | 166 | * Configure this provider with parameters from annotations. |
153 | 167 | * |
| 168 | + * <p>This is expected to be called from an implementation of {@link AnnotationConsumer}. |
| 169 | + * |
| 170 | + * <p>The minimum compiler version will be set to the {@code min} parameter, or {@link #minSupportedVersion}, |
| 171 | + * whichever is greater. This means annotations can pass {@link Integer#MIN_VALUE} as a default value safely. |
| 172 | + * |
| 173 | + * <p>The maximum compiler version will be set to the {@code max} parameter, or {@link #maxSupportedVersion}, |
| 174 | + * whichever is smaller. This means annotations can pass {@link Integer#MAC_VALUE} as a default value safely. |
| 175 | + * |
| 176 | + * <p>If implementations do not support specifying custom compiler configurers, then an empty array must be |
| 177 | + * passed for the {@code configurerClasses} parameter. |
| 178 | + * |
| 179 | + * <p>If implementations do not support changing the version strategy, then it is suggested to pass |
| 180 | + * {@link VersionStrategy#RELEASE} as the value for the {@code versionStrategy} parameter. |
| 181 | + * |
154 | 182 | * @param min the inclusive minimum compiler version to use. |
155 | 183 | * @param max the inclusive maximum compiler version to use. |
156 | 184 | * @param configurerClasses the configurer classes to apply to each compiler. |
|
0 commit comments