From bf21a67ec0fbee15c731900de3772fdec99caeae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Spie=C3=9F?= Date: Tue, 8 Oct 2024 19:46:40 +0200 Subject: [PATCH] Add more compliance tests (#2748) --- ...eTest.java => ArchUnitComplianceTest.java} | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) rename src/test/java/net/dv8tion/jda/test/compliance/{RestActionComplianceTest.java => ArchUnitComplianceTest.java} (62%) diff --git a/src/test/java/net/dv8tion/jda/test/compliance/RestActionComplianceTest.java b/src/test/java/net/dv8tion/jda/test/compliance/ArchUnitComplianceTest.java similarity index 62% rename from src/test/java/net/dv8tion/jda/test/compliance/RestActionComplianceTest.java rename to src/test/java/net/dv8tion/jda/test/compliance/ArchUnitComplianceTest.java index 2d3b26a254..a43f28b2b1 100644 --- a/src/test/java/net/dv8tion/jda/test/compliance/RestActionComplianceTest.java +++ b/src/test/java/net/dv8tion/jda/test/compliance/ArchUnitComplianceTest.java @@ -16,9 +16,11 @@ package net.dv8tion.jda.test.compliance; +import com.tngtech.archunit.core.domain.JavaClass; import com.tngtech.archunit.core.domain.JavaClasses; import com.tngtech.archunit.core.importer.ClassFileImporter; import net.dv8tion.jda.annotations.UnknownNullability; +import net.dv8tion.jda.api.managers.Manager; import net.dv8tion.jda.api.requests.RestAction; import org.jetbrains.annotations.Contract; import org.junit.jupiter.api.Test; @@ -28,10 +30,12 @@ import javax.annotation.Nullable; import java.util.concurrent.CompletableFuture; +import static com.tngtech.archunit.base.DescribedPredicate.describe; import static com.tngtech.archunit.core.domain.JavaClass.Predicates.assignableTo; +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods; -public class RestActionComplianceTest +public class ArchUnitComplianceTest { final JavaClasses apiClasses = new ClassFileImporter().importPackages("net.dv8tion.jda.api"); @@ -87,4 +91,61 @@ void testMethodsThatReturnObjectShouldHaveNullabilityAnnotations() .beAnnotatedWith(UnknownNullability.class) .check(apiClasses); } + + @Test + void testMethodsThatReturnPrimitivesShouldNotHaveNullabilityAnnotations() + { + methods() + .that() + .haveRawReturnType(describe("primitive", JavaClass::isPrimitive)) + .and() + .arePublic() + .should() + .notBeAnnotatedWith(Nonnull.class) + .andShould() + .notBeAnnotatedWith(Nullable.class) + .check(apiClasses); + } + + @Test + void testRestActionClassesFollowNamePattern() + { + classes() + .that() + .areAssignableTo(RestAction.class) + .and() + .areNotAssignableTo(Manager.class) + .and() + .arePublic() + .should() + .haveSimpleNameEndingWith("Action") + .check(apiClasses); + } + + @Test + void testManagerClassesFollowNamePattern() + { + classes() + .that() + .areAssignableTo(Manager.class) + .and() + .arePublic() + .should() + .haveSimpleNameEndingWith("Manager") + .check(apiClasses); + } + + @Test + void testInternalClassesAreNotInApiPackage() + { + classes() + .that() + .arePublic() + .and() + .haveSimpleNameEndingWith("Impl") + .should() + .resideOutsideOfPackage("net.dv8tion.jda.api..") + .allowEmptyShould(true) + .check(apiClasses); + } }