mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-10 08:21:21 +00:00
Add arch test for preview API usage
This commit is contained in:
6
pom.xml
6
pom.xml
@@ -410,6 +410,12 @@
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.tngtech.archunit</groupId>
|
||||
<artifactId>archunit</artifactId>
|
||||
<version>0.14.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest</artifactId>
|
||||
|
||||
56
src/test/java/org/kohsuke/github/ArchTests.java
Normal file
56
src/test/java/org/kohsuke/github/ArchTests.java
Normal file
@@ -0,0 +1,56 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import com.tngtech.archunit.core.domain.JavaClass;
|
||||
import com.tngtech.archunit.core.domain.JavaClasses;
|
||||
import com.tngtech.archunit.core.domain.properties.HasAnnotations;
|
||||
import com.tngtech.archunit.core.domain.properties.HasName.AndFullName;
|
||||
import com.tngtech.archunit.core.importer.ClassFileImporter;
|
||||
import com.tngtech.archunit.core.importer.ImportOption;
|
||||
import com.tngtech.archunit.lang.ArchCondition;
|
||||
import com.tngtech.archunit.lang.ArchRule;
|
||||
import com.tngtech.archunit.lang.ConditionEvents;
|
||||
import com.tngtech.archunit.lang.SimpleConditionEvent;
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
|
||||
|
||||
public class ArchTests {
|
||||
|
||||
private final JavaClasses classFiles = new ClassFileImporter()
|
||||
.withImportOption(new ImportOption.DoNotIncludeTests())
|
||||
.withImportOption(new ImportOption.DoNotIncludeJars())
|
||||
.importPackages("org.kohsuke.github");
|
||||
|
||||
@Test
|
||||
public void testPreviewsAreFlaggedAsDeprecated() {
|
||||
|
||||
String description = "annotate all preview APIs as @Deprecated until they are promoted to stable";
|
||||
|
||||
ArchRule rule = classes().should(new ArchCondition<JavaClass>(description) {
|
||||
|
||||
@Override
|
||||
public void check(final JavaClass targetClazz, final ConditionEvents events) {
|
||||
checkForPreviewAnnotation(targetClazz, events);
|
||||
targetClazz.getAllMethods().forEach(method -> {
|
||||
checkForPreviewAnnotation(method, events);
|
||||
});
|
||||
}
|
||||
|
||||
<T extends HasAnnotations<T> & AndFullName> void checkForPreviewAnnotation(T codeTarget,
|
||||
ConditionEvents events) {
|
||||
|
||||
if (codeTarget.tryGetAnnotationOfType(Preview.class).isPresent()
|
||||
&& !codeTarget.tryGetAnnotationOfType(Deprecated.class).isPresent()) {
|
||||
|
||||
String message = codeTarget.getFullName()
|
||||
+ " uses a preview API and is missing the '@Deprecated' annotation.";
|
||||
|
||||
events.add(new SimpleConditionEvent(codeTarget, false, message));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
rule.check(classFiles);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user