Skip to content

Commit 1da8416

Browse files
authored
Merge pull request hub4j#983 from marcoferrer/add-preview-arch-rules
Add arch test for preview API usage
2 parents 9151102 + 5888efc commit 1da8416

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,12 @@
410410
<artifactId>commons-lang3</artifactId>
411411
<version>3.9</version>
412412
</dependency>
413+
<dependency>
414+
<groupId>com.tngtech.archunit</groupId>
415+
<artifactId>archunit</artifactId>
416+
<version>0.14.1</version>
417+
<scope>test</scope>
418+
</dependency>
413419
<dependency>
414420
<groupId>org.hamcrest</groupId>
415421
<artifactId>hamcrest</artifactId>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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

Comments
 (0)