|
| 1 | +package org.kohsuke.github; |
| 2 | + |
| 3 | +import com.tngtech.archunit.core.domain.JavaClasses; |
| 4 | +import com.tngtech.archunit.core.importer.ClassFileImporter; |
| 5 | +import com.tngtech.archunit.core.importer.ImportOption; |
| 6 | +import com.tngtech.archunit.lang.ArchRule; |
| 7 | +import org.junit.BeforeClass; |
| 8 | +import org.junit.Test; |
| 9 | + |
| 10 | +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; |
| 11 | +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.fields; |
| 12 | +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods; |
| 13 | +import static org.junit.Assert.assertTrue; |
| 14 | + |
| 15 | +public class ArchTests { |
| 16 | + |
| 17 | + private static final JavaClasses classFiles = new ClassFileImporter() |
| 18 | + .withImportOption(new ImportOption.DoNotIncludeTests()) |
| 19 | + .withImportOption(new ImportOption.DoNotIncludeJars()) |
| 20 | + .importPackages("org.kohsuke.github"); |
| 21 | + |
| 22 | + @BeforeClass |
| 23 | + public static void beforeClass() { |
| 24 | + assertTrue(classFiles.size() > 0); |
| 25 | + } |
| 26 | + |
| 27 | + @Test |
| 28 | + public void testPreviewsAreFlaggedAsDeprecated() { |
| 29 | + |
| 30 | + String reason = "all preview APIs must be annotated as @Deprecated until they are promoted to stable"; |
| 31 | + |
| 32 | + ArchRule classRule = classes().that() |
| 33 | + .areAnnotatedWith(Preview.class) |
| 34 | + .should() |
| 35 | + .beAnnotatedWith(Deprecated.class) |
| 36 | + .because(reason); |
| 37 | + |
| 38 | + ArchRule methodRule = methods().that() |
| 39 | + .areAnnotatedWith(Preview.class) |
| 40 | + .should() |
| 41 | + .beAnnotatedWith(Deprecated.class) |
| 42 | + .because(reason); |
| 43 | + |
| 44 | + ArchRule enumFieldsRule = fields().that() |
| 45 | + .areDeclaredInClassesThat() |
| 46 | + .areEnums() |
| 47 | + .and() |
| 48 | + .areAnnotatedWith(Preview.class) |
| 49 | + .should() |
| 50 | + .beAnnotatedWith(Deprecated.class) |
| 51 | + .because(reason); |
| 52 | + |
| 53 | + classRule.check(classFiles); |
| 54 | + enumFieldsRule.check(classFiles); |
| 55 | + methodRule.check(classFiles); |
| 56 | + |
| 57 | + } |
| 58 | +} |
0 commit comments