Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1da8416

Browse filesBrowse 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
Copy full SHA for 1da8416

File tree

Expand file treeCollapse file tree

2 files changed

+64
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+64
-0
lines changed

‎pom.xml

Copy file name to clipboardExpand all lines: pom.xml
+6Lines 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>
+58Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.