Skip to content

Commit

Permalink
Add more compliance tests (#2748)
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment authored Oct 8, 2024
1 parent e24fc59 commit bf21a67
Showing 1 changed file with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");

Expand Down Expand Up @@ -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);
}
}

0 comments on commit bf21a67

Please sign in to comment.