Skip to content

Instantly share code, notes, and snippets.

@andres-sacco
Last active January 16, 2021 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andres-sacco/4a163f1dde6e1fa966e51666ff1ff508 to your computer and use it in GitHub Desktop.
Save andres-sacco/4a163f1dde6e1fa966e51666ff1ff508 to your computer and use it in GitHub Desktop.
Annotations rules
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;
import com.tngtech.archunit.core.importer.ImportOption;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
@AnalyzeClasses(packages = "com.example.archunit", importOptions = ImportOption.DoNotIncludeTests.class)
class AnnotationsRulesTest {
@ArchTest
static final ArchRule controller_should_be_annotated = classes()
.that().resideInAPackage("com.example.archunit.controller")
.should().beAnnotatedWith(RestController.class)
.andShould().notBeAnnotatedWith(Controller.class)
.because("Controllers should be annotated with @RestController, and not with @Controller") ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment